FindWrapProtobuf.cmake 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. cmake_minimum_required(VERSION 3.10)
  2. find_package(Protobuf QUIET)
  3. unset(WrapProtobuf_FOUND)
  4. if(CMAKE_SIZEOF_VOID_P EQUAL 8)
  5. set(FIND_LIBRARY_USE_LIB64_PATHS TRUE)
  6. set(FIND_LIBRARY_USE_LIBX32_PATHS FALSE)
  7. set(FIND_LIBRARY_USE_LIB32_PATHS FALSE)
  8. else()
  9. set(FIND_LIBRARY_USE_LIBX32_PATHS TRUE)
  10. set(FIND_LIBRARY_USE_LIB32_PATHS TRUE)
  11. set(FIND_LIBRARY_USE_LIB64_PATHS FALSE)
  12. endif()
  13. if("Protobuf" IN_LIST WrapProtobuf_FIND_COMPONENTS OR NOT WrapProtobuf_FIND_COMPONENTS)
  14. set(WrapProtobuf_Protobuf_FOUND TRUE)
  15. if(NOT TARGET protobuf::libprotobuf)
  16. find_library(Protobuf_LIBRARY protobuf)
  17. if(Protobuf_LIBRARY)
  18. add_library(protobuf::libprotobuf UNKNOWN IMPORTED)
  19. set_target_properties(protobuf::libprotobuf PROPERTIES
  20. IMPORTED_LOCATION "${Protobuf_LIBRARY}"
  21. )
  22. find_path(Protobuf_INCLUDE_DIRS "message.h"
  23. PATH_SUFFIXES "google/protobuf"
  24. )
  25. if(Protobuf_INCLUDE_DIRS)
  26. set_target_properties(protobuf::libprotobuf PROPERTIES
  27. INTERFACE_INCLUDE_DIRECTORIES "${Protobuf_INCLUDE_DIRS}"
  28. )
  29. else()
  30. set(WrapProtobuf_Protobuf_FOUND FALSE)
  31. endif()
  32. else()
  33. set(WrapProtobuf_Protobuf_FOUND FALSE)
  34. endif()
  35. else()
  36. if(NOT Protobuf_INCLUDE_DIRS)
  37. get_target_property(Protobuf_INCLUDE_DIRS protobuf::libprotobuf INTERFACE_INCLUDE_DIRECTORIES)
  38. endif()
  39. endif()
  40. endif()
  41. if("Protoc" IN_LIST WrapProtobuf_FIND_COMPONENTS OR NOT WrapProtobuf_FIND_COMPONENTS)
  42. set(WrapProtobuf_Protoc_FOUND TRUE)
  43. if(NOT TARGET protobuf::libprotoc)
  44. find_package(Threads REQUIRED)
  45. find_library(Protoc_LIBRARY protoc)
  46. if(Protoc_LIBRARY)
  47. add_library(protobuf::libprotoc UNKNOWN IMPORTED)
  48. set_target_properties(protobuf::libprotoc PROPERTIES
  49. IMPORTED_LOCATION "${Protoc_LIBRARY}"
  50. INTERFACE_LINK_LIBRARIES Threads::Threads
  51. )
  52. message(WARNING "aedelev: Protoc_INCLUDE_DIRS")
  53. find_path(Protoc_INCLUDE_DIRS "descriptor.h"
  54. PATH_SUFFIXES "google/protobuf"
  55. )
  56. if(Protoc_INCLUDE_DIRS)
  57. set_target_properties(protobuf::libprotoc PROPERTIES
  58. INTERFACE_INCLUDE_DIRECTORIES "${Protoc_INCLUDE_DIRS}"
  59. )
  60. else()
  61. set(WrapProtobuf_Protoc_FOUND FALSE)
  62. endif()
  63. else()
  64. set(WrapProtobuf_Protoc_FOUND FALSE)
  65. endif()
  66. else()
  67. if(NOT Protoc_INCLUDE_DIRS)
  68. get_target_property(Protoc_INCLUDE_DIRS protobuf::libprotoc INTERFACE_INCLUDE_DIRECTORIES)
  69. endif()
  70. endif()
  71. endif()
  72. if("Generator" IN_LIST WrapProtobuf_FIND_COMPONENTS OR NOT WrapProtobuf_FIND_COMPONENTS)
  73. set(WrapProtobuf_Generator_FOUND TRUE)
  74. if(NOT TARGET protobuf::protoc)
  75. find_program(Protobuf_Protoc_EXECUTABLE protoc)
  76. if(Protobuf_Protoc_EXECUTABLE)
  77. add_executable(protobuf::protoc IMPORTED)
  78. set_target_properties(protobuf::protoc PROPERTIES
  79. IMPORTED_LOCATION "${Protobuf_Protoc_EXECUTABLE}"
  80. )
  81. else()
  82. set(WrapProtobuf_Generator_FOUND FALSE)
  83. endif()
  84. endif()
  85. endif()
  86. if(WrapProtobuf_FIND_COMPONENTS)
  87. include(FindPackageHandleStandardArgs)
  88. find_package_handle_standard_args(WrapProtobuf HANDLE_COMPONENTS
  89. REQUIRED_VARS Protoc_INCLUDE_DIRS Protobuf_INCLUDE_DIRS
  90. )
  91. elseif(TARGET protobuf::protoc AND TARGET protobuf::libprotoc AND TARGET protobuf::libprotobuf)
  92. include(FindPackageHandleStandardArgs)
  93. find_package_handle_standard_args(WrapProtobuf REQUIRED_VARS
  94. Protoc_INCLUDE_DIRS Protobuf_INCLUDE_DIRS)
  95. endif()