CMakeLists.txt 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. cmake_minimum_required(VERSION 3.6)
  2. set(QT_PROTOBUF_VERSION 0.5.0)
  3. set(QT_PROTOBUF_PROJECT QtProtobufProject)
  4. project(${QT_PROTOBUF_PROJECT} VERSION ${QT_PROTOBUF_VERSION} LANGUAGES CXX)
  5. # Conan support, optional
  6. if(EXISTS "${CMAKE_BINARY_DIR}/conanbuildinfo.cmake")
  7. include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
  8. conan_basic_setup()
  9. endif()
  10. include(GNUInstallDirs)
  11. set(QT_PROTOBUF_CMAKE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
  12. set(QT_PROTOBUF_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
  13. set(QT_PROTOBUF_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}")
  14. if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/grpc/CMakeLists.txt")
  15. message(STATUS "Found local gRPC sources directory. Perform all-in-one build")
  16. set(gRPC_BUILD_TESTS FALSE)
  17. set(protobuf_BUILD_TESTS FALSE)
  18. add_subdirectory("3rdparty/grpc" EXCLUDE_FROM_ALL)
  19. if(TARGET grpc AND TARGET grpc++ AND TARGET grpc_cpp_plugin)
  20. add_library(gRPC::grpc ALIAS grpc)
  21. add_library(gRPC::grpc++ ALIAS grpc++)
  22. add_executable(gRPC::grpc_cpp_plugin ALIAS grpc_cpp_plugin)
  23. set(gRPC_FOUND TRUE)
  24. endif()
  25. else()
  26. include("${QT_PROTOBUF_CMAKE_DIR}/ProtobufLookup.cmake")
  27. include("${QT_PROTOBUF_CMAKE_DIR}/gRPCLookup.cmake")
  28. endif()
  29. set(gtest_force_shared_crt OFF)
  30. set(GENERATOR_TARGET qtprotobufgen)
  31. set(PROTOBUF_QUICK_PLUGIN_NAME protobufquickplugin)
  32. set(GRPC_QUICK_PLUGIN_NAME grpcquickplugin)
  33. if(UNIX)
  34. if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
  35. # using Clang
  36. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -Wno-pessimizing-move -Wno-mismatched-tags -Wno-unused-private-field -Wno-self-assign-overloaded")
  37. elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
  38. # using GCC
  39. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -Wno-error=deprecated-declarations")
  40. endif()
  41. elseif(WIN32)
  42. if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
  43. #TODO: not all l4 warnings are fixed for MSVC. Enable options bellow
  44. # once fixed
  45. # set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /WX /W4 /MD")
  46. # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /WX /W4 /MD")
  47. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /bigobj /wd4005")
  48. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj /wd4005")
  49. else()
  50. message(WARNING "Only MSVC compilers family are supported for build")
  51. endif()
  52. endif()
  53. include(CMakePackageConfigHelpers)
  54. if(NOT CMAKE_CROSSCOMPILING)
  55. configure_package_config_file(
  56. "${CMAKE_CURRENT_SOURCE_DIR}/ProjectConfig.cmake.in" "${QT_PROTOBUF_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
  57. INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake")
  58. install(FILES "${QT_PROTOBUF_BINARY_DIR}/${PROJECT_NAME}Config.cmake" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
  59. COMPONENT dev)
  60. export(PACKAGE ${PROJECT_NAME})
  61. add_subdirectory("src/generator")
  62. endif()
  63. add_subdirectory("src/protobuf")
  64. add_subdirectory("src/grpc")
  65. if(NOT WIN32)#TODO: There are linking issues with windows build of well-known types...
  66. add_subdirectory("src/wellknowntypes")
  67. endif()
  68. add_subdirectory("src/qttypes")
  69. # add a target to generate API documentation with Doxygen
  70. find_package(Doxygen)
  71. if(NOT DOXYGEN_FOUND)
  72. find_program(DOXYGEN_EXECUTABLE doxygen)
  73. endif()
  74. if(DEFINED DOXYGEN_EXECUTABLE)
  75. message(STATUS "Using doxygen to generate documenation: ${DOXYGEN_EXECUTABLE}")
  76. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doxygen/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
  77. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doxygen/customdoxygen.css ${CMAKE_CURRENT_BINARY_DIR}/customdoxygen.css COPYONLY)
  78. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doxygen/header.html ${CMAKE_CURRENT_BINARY_DIR}/header.html COPYONLY)
  79. file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/doxygen/html)
  80. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doxygen/TitilliumWeb.woff2 ${CMAKE_CURRENT_BINARY_DIR}/doxygen/html/TitilliumWeb.woff2 COPYONLY)
  81. add_custom_target(doc
  82. ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
  83. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
  84. COMMENT "Generating API documentation with Doxygen" VERBATIM
  85. )
  86. endif()
  87. set(QT_PROTOBUF_MAKE_TESTS ON CACHE BOOL "Enable QtProtobuf tests build")
  88. set(QT_PROTOBUF_MAKE_EXAMPLES ON CACHE BOOL "Enable QtProtobuf examples build")
  89. set(QT_PROTOBUF_MAKE_COVERAGE OFF CACHE BOOL "Enable QtProtobuf build for profiler (gcov)")
  90. set(BUILD_SHARED_LIBS ON CACHE BOOL "Enable QtProtobuf static library build (disables shared library build)")
  91. if(CMAKE_CROSSCOMPILING)
  92. set(QT_PROTOBUF_MAKE_TESTS OFF)
  93. set(QT_PROTOBUF_MAKE_EXAMPLES OFF)
  94. else()
  95. if(NOT gRPC_FOUND)
  96. message(WARNING "gRPC not found: some tests and examples cannot be built.")
  97. message(STATUS "Force disable test")
  98. set(QT_PROTOBUF_MAKE_TESTS OFF)
  99. message(STATUS "Force disable examples")
  100. set(QT_PROTOBUF_MAKE_EXAMPLES OFF)
  101. endif()
  102. endif()
  103. include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/QtProtobufCommon.cmake")
  104. if(QT_PROTOBUF_MAKE_TESTS)
  105. if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/googletest/CMakeLists.txt")
  106. set(BUILD_GMOCK OFF CACHE BOOL "Disable gmock build functionality" FORCE)
  107. set(gtest_force_shared_crt ON CACHE BOOL "Enable shared crt" FORCE)
  108. add_subdirectory("3rdparty/googletest" EXCLUDE_FROM_ALL)
  109. set(GTest_FOUND TRUE)
  110. else()
  111. find_package(GTest)
  112. endif()
  113. if(GTest_FOUND)
  114. enable_testing()
  115. add_subdirectory("tests")
  116. else()
  117. message(STATUS "Force disable test")
  118. endif()
  119. endif()
  120. if(QT_PROTOBUF_MAKE_EXAMPLES)
  121. add_subdirectory("examples")
  122. endif()
  123. include("${QT_PROTOBUF_CMAKE_DIR}/packaging.cmake")