123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- cmake_minimum_required(VERSION 3.6)
- set(QT_PROTOBUF_VERSION 0.3.1)
- set(QT_PROTOBUF_PROJECT QtProtobufProject)
- project(${QT_PROTOBUF_PROJECT} VERSION ${QT_PROTOBUF_VERSION} LANGUAGES CXX)
- include(GNUInstallDirs)
- set(QT_PROTOBUF_CMAKE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
- set(QT_PROTOBUF_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
- set(QT_PROTOBUF_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}")
- set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
- find_package(Qt5 COMPONENTS Core Network Qml REQUIRED)
- set(MICROJSON_MAKE_TESTS OFF)
- if(NOT EXISTS "${QT_PROTOBUF_SOURCE_DIR}/3rdparty/microjson/CMakeLists.txt")
- message(FATAL_ERROR "microjson is not found. Please initialize microjson module: git submodule update --init 3rdparty/microjson")
- else()
- add_subdirectory("${QT_PROTOBUF_SOURCE_DIR}/3rdparty/microjson" EXCLUDE_FROM_ALL)
- endif()
- if(Qt5Core_VERSION VERSION_LESS "5.12.4")
- # grpc target requires QT version not less than 5.12.4
- # earlier versions Http2DirectAttribute is broken: https://doc.qt.io/qt-5/whatsnew511.html
- # https://bugreports.qt.io/browse/QTBUG-74765
- message(FATAL_ERROR "Required Qt version is 5.12.4+")
- endif()
- if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/grpc/CMakeLists.txt")
- message(STATUS "Found local gRPC sources directory. Perform all-in-one build")
- set(gRPC_BUILD_TESTS FALSE)
- set(protobuf_BUILD_TESTS FALSE)
- add_subdirectory("3rdparty/grpc" EXCLUDE_FROM_ALL)
- if(TARGET grpc AND TARGET grpc++ AND TARGET grpc_cpp_plugin)
- add_library(gRPC::grpc ALIAS grpc)
- add_library(gRPC::grpc++ ALIAS grpc++)
- add_executable(gRPC::grpc_cpp_plugin ALIAS grpc_cpp_plugin)
- set(gRPC_FOUND TRUE)
- endif()
- else()
- include("${QT_PROTOBUF_CMAKE_DIR}/ProtobufLookup.cmake")
- include("${QT_PROTOBUF_CMAKE_DIR}/gRPCLookup.cmake")
- endif()
- set(gtest_force_shared_crt OFF)
- set(GENERATOR_TARGET qtprotobufgen)
- set(QT_PROTOBUF_EXECUTABLE_INSTALL ${CMAKE_INSTALL_FULL_BINDIR}/${GENERATOR_TARGET})
- set(QT_PROTOBUF_EXECUTABLE $<TARGET_FILE:${GENERATOR_TARGET}> CACHE STRING "QT_PROTOBUF_EXECUTABLE is set ${QT_PROTOBUF_EXECUTABLE}" FORCE)
- if(UNIX)
- if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
- # using Clang
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -Wno-pessimizing-move -Wno-mismatched-tags -Wno-unused-private-field -Wno-self-assign-overloaded")
- elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
- # using GCC
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -Wno-error=deprecated-declarations")
- endif()
- elseif(WIN32)
- if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
- #TODO: not all l4 warnings are fixed for MSVC. Enable options bellow
- # once fixed
- # set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /WX /W4 /MD")
- # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /WX /W4 /MD")
- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /bigobj /wd4005")
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj /wd4005")
- else()
- message(WARNING "Only MSVC compilers family are supported for build")
- endif()
- endif()
- if(Qt5_POSITION_INDEPENDENT_CODE)
- set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
- endif()
- set(CMAKE_CXX_STANDARD 14)
- set(CMAKE_CXX_STANDARD_REQUIRED ON)
- add_subdirectory("src/protobuf")
- add_subdirectory("src/grpc")
- add_subdirectory("src/generator")
- if(NOT WIN32)#TODO: There are linking issues with windows build of well-known types...
- add_subdirectory("src/wellknowntypes")
- endif()
- configure_package_config_file(
- "${CMAKE_CURRENT_SOURCE_DIR}/ProjectConfig.cmake.in" "${QT_PROTOBUF_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
- INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake")
- install(FILES "${QT_PROTOBUF_BINARY_DIR}/${PROJECT_NAME}Config.cmake" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
- COMPONENT dev)
- export(PACKAGE ${PROJECT_NAME})
- # add a target to generate API documentation with Doxygen
- find_package(Doxygen)
- if(NOT DOXYGEN_FOUND)
- find_program(DOXYGEN_EXECUTABLE doxygen)
- endif()
- if(DEFINED DOXYGEN_EXECUTABLE)
- message(STATUS "Using doxygen to generate documenation: ${DOXYGEN_EXECUTABLE}")
- configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doxygen/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
- configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doxygen/customdoxygen.css ${CMAKE_CURRENT_BINARY_DIR}/customdoxygen.css COPYONLY)
- configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doxygen/header.html ${CMAKE_CURRENT_BINARY_DIR}/header.html COPYONLY)
- file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/doxygen/html)
- configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doxygen/TitilliumWeb.woff2 ${CMAKE_CURRENT_BINARY_DIR}/doxygen/html/TitilliumWeb.woff2 COPYONLY)
- add_custom_target(doc
- ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
- WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
- COMMENT "Generating API documentation with Doxygen" VERBATIM
- )
- endif()
- if(DEFINED $ENV{QT_PROTOBUF_MAKE_TESTS})
- set(QT_PROTOBUF_MAKE_TESTS $ENV{QT_PROTOBUF_MAKE_TESTS})
- elseif(NOT DEFINED QT_PROTOBUF_MAKE_TESTS)
- set(QT_PROTOBUF_MAKE_TESTS ON)
- endif()
- if(DEFINED $ENV{QT_PROTOBUF_MAKE_EXAMPLES})
- set(QT_PROTOBUF_MAKE_EXAMPLES $ENV{QT_PROTOBUF_MAKE_EXAMPLES})
- elseif(NOT DEFINED QT_PROTOBUF_MAKE_EXAMPLES)
- set(QT_PROTOBUF_MAKE_EXAMPLES ON)
- endif()
- if(NOT gRPC_FOUND)
- message(WARNING "gRPC not found: some tests and examples cannot be built.")
- message(STATUS "Force disable test")
- set(QT_PROTOBUF_MAKE_TESTS OFF)
- message(STATUS "Force disable examples")
- set(QT_PROTOBUF_MAKE_EXAMPLES OFF)
- endif()
- include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/QtProtobufCommon.cmake")
- if(QT_PROTOBUF_MAKE_TESTS)
- if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/googletest/CMakeLists.txt")
- set(BUILD_GMOCK OFF CACHE BOOL "Disable gmock build functionality" FORCE)
- set(gtest_force_shared_crt ON CACHE BOOL "Enable shared crt" FORCE)
- add_subdirectory("3rdparty/googletest" EXCLUDE_FROM_ALL)
- set(GTest_FOUND TRUE)
- else()
- find_package(GTest)
- endif()
- if(GTest_FOUND)
- enable_testing()
- add_subdirectory("tests")
- else()
- message(STATUS "Force disable test")
- endif()
- endif()
- if(QT_PROTOBUF_MAKE_EXAMPLES)
- add_subdirectory("examples")
- endif()
- include("${QT_PROTOBUF_CMAKE_DIR}/packaging.cmake")
|