CMakeLists.txt 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. find_package(Qt5 COMPONENTS Core Network Qml REQUIRED)
  15. if(EXISTS "${QT_PROTOBUF_SOURCE_DIR}/3rdparty/microjson/CMakeLists.txt")
  16. set(MICROJSON_MAKE_TESTS OFF)
  17. add_subdirectory("${QT_PROTOBUF_SOURCE_DIR}/3rdparty/microjson" EXCLUDE_FROM_ALL)
  18. message(STATUS "Using microjson from 3rdparty")
  19. endif()
  20. if(Qt5Core_VERSION VERSION_LESS "5.12.4")
  21. # grpc target requires QT version not less than 5.12.4
  22. # earlier versions Http2DirectAttribute is broken: https://doc.qt.io/qt-5/whatsnew511.html
  23. # https://bugreports.qt.io/browse/QTBUG-74765
  24. message(FATAL_ERROR "Required Qt version is 5.12.4+")
  25. endif()
  26. if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/grpc/CMakeLists.txt")
  27. message(STATUS "Found local gRPC sources directory. Perform all-in-one build")
  28. set(gRPC_BUILD_TESTS FALSE)
  29. set(protobuf_BUILD_TESTS FALSE)
  30. add_subdirectory("3rdparty/grpc" EXCLUDE_FROM_ALL)
  31. if(TARGET grpc AND TARGET grpc++ AND TARGET grpc_cpp_plugin)
  32. add_library(gRPC::grpc ALIAS grpc)
  33. add_library(gRPC::grpc++ ALIAS grpc++)
  34. add_executable(gRPC::grpc_cpp_plugin ALIAS grpc_cpp_plugin)
  35. set(gRPC_FOUND TRUE)
  36. endif()
  37. else()
  38. include("${QT_PROTOBUF_CMAKE_DIR}/ProtobufLookup.cmake")
  39. include("${QT_PROTOBUF_CMAKE_DIR}/gRPCLookup.cmake")
  40. endif()
  41. set(gtest_force_shared_crt OFF)
  42. set(GENERATOR_TARGET qtprotobufgen)
  43. set(PROTOBUF_QUICK_PLUGIN_NAME protobufquickplugin)
  44. set(GRPC_QUICK_PLUGIN_NAME grpcquickplugin)
  45. if(UNIX)
  46. if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
  47. # using Clang
  48. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -Wno-pessimizing-move -Wno-mismatched-tags -Wno-unused-private-field -Wno-self-assign-overloaded")
  49. elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
  50. # using GCC
  51. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -Wno-error=deprecated-declarations")
  52. endif()
  53. elseif(WIN32)
  54. if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
  55. #TODO: not all l4 warnings are fixed for MSVC. Enable options bellow
  56. # once fixed
  57. # set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /WX /W4 /MD")
  58. # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /WX /W4 /MD")
  59. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /bigobj /wd4005")
  60. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj /wd4005")
  61. else()
  62. message(WARNING "Only MSVC compilers family are supported for build")
  63. endif()
  64. endif()
  65. if(Qt5_POSITION_INDEPENDENT_CODE)
  66. set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
  67. endif()
  68. set(CMAKE_CXX_STANDARD 14)
  69. set(CMAKE_CXX_STANDARD_REQUIRED ON)
  70. include(CMakePackageConfigHelpers)
  71. configure_package_config_file(
  72. "${CMAKE_CURRENT_SOURCE_DIR}/ProjectConfig.cmake.in" "${QT_PROTOBUF_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
  73. INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake")
  74. install(FILES "${QT_PROTOBUF_BINARY_DIR}/${PROJECT_NAME}Config.cmake" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
  75. COMPONENT dev)
  76. export(PACKAGE ${PROJECT_NAME})
  77. add_subdirectory("src/protobuf")
  78. add_subdirectory("src/grpc")
  79. add_subdirectory("src/generator")
  80. if(NOT WIN32)#TODO: There are linking issues with windows build of well-known types...
  81. add_subdirectory("src/wellknowntypes")
  82. endif()
  83. add_subdirectory("src/qttypes")
  84. # add a target to generate API documentation with Doxygen
  85. find_package(Doxygen)
  86. if(NOT DOXYGEN_FOUND)
  87. find_program(DOXYGEN_EXECUTABLE doxygen)
  88. endif()
  89. if(DEFINED DOXYGEN_EXECUTABLE)
  90. message(STATUS "Using doxygen to generate documenation: ${DOXYGEN_EXECUTABLE}")
  91. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doxygen/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
  92. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doxygen/customdoxygen.css ${CMAKE_CURRENT_BINARY_DIR}/customdoxygen.css COPYONLY)
  93. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doxygen/header.html ${CMAKE_CURRENT_BINARY_DIR}/header.html COPYONLY)
  94. file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/doxygen/html)
  95. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doxygen/TitilliumWeb.woff2 ${CMAKE_CURRENT_BINARY_DIR}/doxygen/html/TitilliumWeb.woff2 COPYONLY)
  96. add_custom_target(doc
  97. ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
  98. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
  99. COMMENT "Generating API documentation with Doxygen" VERBATIM
  100. )
  101. endif()
  102. set(QT_PROTOBUF_MAKE_TESTS ON CACHE BOOL "Enable QtProtobuf tests build")
  103. set(QT_PROTOBUF_MAKE_EXAMPLES ON CACHE BOOL "Enable QtProtobuf examples build")
  104. set(QT_PROTOBUF_MAKE_COVERAGE OFF CACHE BOOL "Enable QtProtobuf build for profiler (gcov)")
  105. set(BUILD_SHARED_LIBS ON CACHE BOOL "Enable QtProtobuf static library build (disables shared library build)")
  106. if(NOT gRPC_FOUND)
  107. message(WARNING "gRPC not found: some tests and examples cannot be built.")
  108. message(STATUS "Force disable test")
  109. set(QT_PROTOBUF_MAKE_TESTS OFF)
  110. message(STATUS "Force disable examples")
  111. set(QT_PROTOBUF_MAKE_EXAMPLES OFF)
  112. endif()
  113. include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/QtProtobufCommon.cmake")
  114. if(QT_PROTOBUF_MAKE_TESTS)
  115. if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/googletest/CMakeLists.txt")
  116. set(BUILD_GMOCK OFF CACHE BOOL "Disable gmock build functionality" FORCE)
  117. set(gtest_force_shared_crt ON CACHE BOOL "Enable shared crt" FORCE)
  118. add_subdirectory("3rdparty/googletest" EXCLUDE_FROM_ALL)
  119. set(GTest_FOUND TRUE)
  120. else()
  121. find_package(GTest)
  122. endif()
  123. if(GTest_FOUND)
  124. enable_testing()
  125. add_subdirectory("tests")
  126. else()
  127. message(STATUS "Force disable test")
  128. endif()
  129. endif()
  130. if(QT_PROTOBUF_MAKE_EXAMPLES)
  131. add_subdirectory("examples")
  132. endif()
  133. include("${QT_PROTOBUF_CMAKE_DIR}/packaging.cmake")