CMakeLists.txt 6.1 KB

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