CMakeLists.txt 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. include(CMakePackageConfigHelpers)
  12. set(QT_PROTOBUF_CMAKE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
  13. set(QT_PROTOBUF_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
  14. set(QT_PROTOBUF_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}")
  15. include("${QT_PROTOBUF_CMAKE_DIR}/dependencies.cmake")
  16. include("${QT_PROTOBUF_CMAKE_DIR}/Coverage.cmake" EXCLUDE_FROM_ALL)
  17. set(GENERATOR_TARGET qtprotobufgen)
  18. set(PROTOBUF_QUICK_PLUGIN_NAME protobufquickplugin)
  19. set(GRPC_QUICK_PLUGIN_NAME grpcquickplugin)
  20. set(QT_PROTOBUF_MAKE_TESTS ON CACHE BOOL "Enable QtProtobuf tests build")
  21. set(QT_PROTOBUF_MAKE_EXAMPLES ON CACHE BOOL "Enable QtProtobuf examples build")
  22. set(QT_PROTOBUF_MAKE_COVERAGE OFF CACHE BOOL "Enable QtProtobuf build for profiler (gcov)")
  23. set(QT_PROTOBUF_FIELD_ENUM OFF CACHE BOOL "Enable generation of enumeration with fields numbers for well-known and Qt types libraries")
  24. set(BUILD_SHARED_LIBS ON CACHE BOOL "Enable QtProtobuf shared library build (disables static library build)")
  25. if(CMAKE_CROSSCOMPILING)
  26. set(QT_PROTOBUF_MAKE_TESTS OFF)
  27. set(QT_PROTOBUF_MAKE_EXAMPLES OFF)
  28. endif()
  29. if(UNIX)
  30. if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
  31. # using Clang
  32. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -Wno-pessimizing-move -Wno-mismatched-tags -Wno-unused-private-field -Wno-self-assign-overloaded")
  33. elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
  34. # using GCC
  35. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -Wno-error=deprecated-declarations")
  36. endif()
  37. elseif(WIN32)
  38. if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
  39. #TODO: not all l4 warnings are fixed for MSVC. Enable options bellow
  40. # once fixed
  41. # set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /WX /W4 /MD")
  42. # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /WX /W4 /MD")
  43. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /bigobj /wd4005")
  44. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj /wd4005")
  45. else()
  46. message(WARNING "Only MSVC compilers family are supported for build")
  47. endif()
  48. endif()
  49. configure_package_config_file(
  50. "${CMAKE_CURRENT_SOURCE_DIR}/ProjectConfig.cmake.in" "${QT_PROTOBUF_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
  51. INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake")
  52. install(FILES "${QT_PROTOBUF_BINARY_DIR}/${PROJECT_NAME}Config.cmake" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
  53. COMPONENT dev)
  54. export(PACKAGE ${PROJECT_NAME})
  55. add_subdirectory("src/generator")
  56. add_subdirectory("src/protobuf")
  57. add_subdirectory("src/grpc")
  58. set(EXTRA_TYPE_LIBRARIES_OPTIONS "") #Prevent to set from outside
  59. if(QT_PROTOBUF_FIELD_ENUM)
  60. set(EXTRA_TYPE_LIBRARIES_OPTIONS "FIELDENUM ${EXTRA_TYPE_LIBRARIES_OPTIONS}")
  61. endif()
  62. if(NOT WIN32)#TODO: There are linking issues with windows build of well-known types...
  63. add_subdirectory("src/wellknowntypes")
  64. endif()
  65. add_subdirectory("src/qttypes")
  66. if(QT_PROTOBUF_MAKE_TESTS)
  67. if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/googletest/CMakeLists.txt")
  68. set(BUILD_GMOCK OFF CACHE BOOL "" FORCE)
  69. set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
  70. add_subdirectory("3rdparty/googletest" EXCLUDE_FROM_ALL)
  71. set(GTest_FOUND TRUE)
  72. else()
  73. find_package(GTest)
  74. endif()
  75. if(GTest_FOUND)
  76. enable_testing()
  77. add_subdirectory("tests")
  78. else()
  79. message(STATUS "googletest not found. Force disable tests.")
  80. endif()
  81. endif()
  82. if(QT_PROTOBUF_MAKE_EXAMPLES)
  83. add_subdirectory("examples")
  84. endif()
  85. if(QT_PROTOBUF_INSTALL)
  86. include("${QT_PROTOBUF_CMAKE_DIR}/packaging.cmake")
  87. endif()
  88. include("${QT_PROTOBUF_CMAKE_DIR}/doxygen.cmake")