CMakeLists.txt 5.8 KB

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