FindWrapProtobuf.cmake 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. set(WrapProtobuf_REQUIRED_VARS)
  14. if("Protobuf" IN_LIST WrapProtobuf_FIND_COMPONENTS OR NOT WrapProtobuf_FIND_COMPONENTS)
  15. list(APPEND WrapProtobuf_REQUIRED_VARS Protobuf_INCLUDE_DIRS)
  16. set(WrapProtobuf_Protobuf_FOUND TRUE)
  17. if(NOT TARGET protobuf::libprotobuf)
  18. find_library(Protobuf_LIBRARY protobuf)
  19. if(Protobuf_LIBRARY)
  20. add_library(protobuf::libprotobuf UNKNOWN IMPORTED)
  21. set_target_properties(protobuf::libprotobuf PROPERTIES
  22. IMPORTED_LOCATION "${Protobuf_LIBRARY}"
  23. )
  24. find_path(Protobuf_INCLUDE_DIRS "message.h"
  25. PATH_SUFFIXES "google/protobuf"
  26. )
  27. if(Protobuf_INCLUDE_DIRS)
  28. set_target_properties(protobuf::libprotobuf PROPERTIES
  29. INTERFACE_INCLUDE_DIRECTORIES "${Protobuf_INCLUDE_DIRS}"
  30. )
  31. else()
  32. set(WrapProtobuf_Protobuf_FOUND FALSE)
  33. endif()
  34. else()
  35. set(WrapProtobuf_Protobuf_FOUND FALSE)
  36. endif()
  37. else()
  38. if(NOT Protobuf_INCLUDE_DIRS)
  39. get_target_property(Protobuf_INCLUDE_DIRS protobuf::libprotobuf INTERFACE_INCLUDE_DIRECTORIES)
  40. endif()
  41. endif()
  42. endif()
  43. if("Protoc" IN_LIST WrapProtobuf_FIND_COMPONENTS OR NOT WrapProtobuf_FIND_COMPONENTS)
  44. list(APPEND WrapProtobuf_REQUIRED_VARS Protoc_INCLUDE_DIRS)
  45. set(WrapProtobuf_Protoc_FOUND TRUE)
  46. if(NOT TARGET protobuf::libprotoc)
  47. find_package(Threads REQUIRED)
  48. find_library(Protoc_LIBRARY protoc)
  49. if(Protoc_LIBRARY)
  50. add_library(protobuf::libprotoc UNKNOWN IMPORTED)
  51. set_target_properties(protobuf::libprotoc PROPERTIES
  52. IMPORTED_LOCATION "${Protoc_LIBRARY}"
  53. INTERFACE_LINK_LIBRARIES Threads::Threads
  54. )
  55. message(WARNING "aedelev: Protoc_INCLUDE_DIRS")
  56. find_path(Protoc_INCLUDE_DIRS "descriptor.h"
  57. PATH_SUFFIXES "google/protobuf"
  58. )
  59. if(Protoc_INCLUDE_DIRS)
  60. set_target_properties(protobuf::libprotoc PROPERTIES
  61. INTERFACE_INCLUDE_DIRECTORIES "${Protoc_INCLUDE_DIRS}"
  62. )
  63. else()
  64. set(WrapProtobuf_Protoc_FOUND FALSE)
  65. endif()
  66. else()
  67. set(WrapProtobuf_Protoc_FOUND FALSE)
  68. endif()
  69. else()
  70. if(NOT Protoc_INCLUDE_DIRS)
  71. get_target_property(Protoc_INCLUDE_DIRS protobuf::libprotoc INTERFACE_INCLUDE_DIRECTORIES)
  72. endif()
  73. endif()
  74. endif()
  75. if("Generator" IN_LIST WrapProtobuf_FIND_COMPONENTS OR NOT WrapProtobuf_FIND_COMPONENTS)
  76. list(APPEND WrapProtobuf_REQUIRED_VARS Protobuf_Protoc_EXECUTABLE)
  77. set(WrapProtobuf_Generator_FOUND TRUE)
  78. if(NOT TARGET protobuf::protoc)
  79. find_program(Protobuf_Protoc_EXECUTABLE protoc)
  80. if(Protobuf_Protoc_EXECUTABLE)
  81. add_executable(protobuf::protoc IMPORTED)
  82. set_target_properties(protobuf::protoc PROPERTIES
  83. IMPORTED_LOCATION "${Protobuf_Protoc_EXECUTABLE}"
  84. )
  85. else()
  86. set(WrapProtobuf_Generator_FOUND FALSE)
  87. endif()
  88. else()
  89. set(Protobuf_Protoc_EXECUTABLE "protobuf::protoc")
  90. endif()
  91. endif()
  92. if(WrapProtobuf_FIND_COMPONENTS)
  93. include(FindPackageHandleStandardArgs)
  94. find_package_handle_standard_args(WrapProtobuf HANDLE_COMPONENTS
  95. REQUIRED_VARS ${WrapProtobuf_REQUIRED_VARS}
  96. )
  97. elseif(TARGET protobuf::protoc AND TARGET protobuf::libprotoc AND TARGET protobuf::libprotobuf)
  98. include(FindPackageHandleStandardArgs)
  99. find_package_handle_standard_args(WrapProtobuf
  100. REQUIRED_VARS ${WrapProtobuf_REQUIRED_VARS}
  101. )
  102. endif()