CMakeLists.txt 3.6 KB

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