CMakeLists.txt 3.5 KB

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