CMakeLists.txt 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. set(TARGET QtProtobuf)
  2. set(TARGET_EXPORT ${TARGET}Targets)
  3. set(TARGET_CONFIG ${TARGET}Config)
  4. set(TARGET_INCLUDE_DIR ${CMAKE_INSTALL_INCLUDEDIR}/${TARGET})
  5. set(TARGET_LIB_DIR ${CMAKE_INSTALL_LIBDIR})
  6. set(TARGET_CMAKE_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
  7. set(TARGET_BINDIR ${CMAKE_INSTALL_BINDIR})
  8. set(CMAKE_AUTOMOC ON)
  9. set(CMAKE_AUTORCC ON)
  10. find_package(Qt5 COMPONENTS Core Qml REQUIRED)
  11. if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/3rdparty/microjson/CMakeLists.txt")
  12. set(MICROJSON_MAKE_TESTS OFF)
  13. add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/microjson")
  14. message(STATUS "Using microjson from 3rdparty")
  15. message("Note: microjson will be added to install set")
  16. else()
  17. find_package(microjson CONFIG REQUIRED)
  18. endif()
  19. if(NOT TARGET microjson)
  20. message(FATAL_ERROR "microjson is not found.")
  21. endif()
  22. set(CMAKE_POSITION_INDEPENDENT_CODE ${Qt5_POSITION_INDEPENDENT_CODE})
  23. set(CMAKE_CXX_STANDARD 14)
  24. set(CMAKE_CXX_STANDARD_REQUIRED ON)
  25. include(${QT_PROTOBUF_CMAKE_DIR}/Coverage.cmake)
  26. include(${QT_PROTOBUF_CMAKE_DIR}/GenerateQtHeaders.cmake)
  27. include(${QT_PROTOBUF_CMAKE_DIR}/QtProtobufCommon.cmake)
  28. file(GLOB SOURCES
  29. qtprotobuf.cpp
  30. qtprotobuflogging.cpp
  31. qprotobufserializerregistry.cpp
  32. qabstractprotobufserializer.cpp
  33. qprotobufjsonserializer.cpp
  34. qprotobufserializer.cpp
  35. qprotobufmetaproperty.cpp
  36. qprotobufmetaobject.cpp)
  37. file(GLOB HEADERS
  38. qtprotobufglobal.h
  39. qtprotobuftypes.h
  40. qtprotobuflogging.h
  41. qprotobufobject.h
  42. qprotobufserializerregistry_p.h
  43. qqmllistpropertyconstructor.h
  44. qabstractprotobufserializer.h
  45. qabstractprotobufserializer_p.h
  46. qprotobufserializer.h
  47. qprotobufserializer_p.h
  48. qprotobufjsonserializer.h
  49. qprotobufselfcheckiterator.h
  50. qprotobufmetaproperty.h
  51. qprotobufmetaobject.h
  52. qprotobufserializationplugininterface.h)
  53. file(GLOB PUBLIC_HEADER
  54. qtprotobufglobal.h
  55. qtprotobuftypes.h
  56. qtprotobuflogging.h
  57. qprotobufobject.h
  58. qqmllistpropertyconstructor.h
  59. qabstractprotobufserializer.h
  60. qabstractprotobufserializer_p.h
  61. qprotobufserializer.h
  62. qprotobufjsonserializer.h
  63. qprotobufselfcheckiterator.h
  64. qprotobufmetaproperty.h
  65. qprotobufmetaobject.h
  66. qprotobufserializationplugininterface.h)
  67. protobuf_generate_qt_headers(PUBLIC_HEADER ${PUBLIC_HEADER} COMPONENT ${TARGET})
  68. add_library(${TARGET} ${SOURCES})
  69. set(QT_PROTOBUF_STATIC OFF)
  70. if(NOT BUILD_SHARED_LIBS)
  71. set(QT_PROTOBUF_STATIC ON)
  72. if(WIN32)
  73. message(WARNING "Static version of QtProtobuf is not fully tested on Win32 platforms")
  74. endif()
  75. target_compile_definitions(${TARGET} PRIVATE QT_PROTOBUF_STATIC)
  76. set(QT_PROTOBUF_EXTRA_COMPILE_DIFINITIONS QT_PROTOBUF_STATIC)
  77. set(QT_PROTOBUF_EXTRA_CONFIG "staticlib") #extra config for .pri file in case if static build enabled
  78. endif()
  79. if(NOT DEFINED QT_QMAKE_EXECUTABLE)
  80. find_program(QT_QMAKE_EXECUTABLE "qmake" NO_DEFAULT_PATH NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH)
  81. if(QT_QMAKE_EXECUTABLE STREQUAL QT_QMAKE_EXECUTABLE-NOTFOUND)
  82. find_program(QT_QMAKE_EXECUTABLE "qmake")
  83. if(QT_QMAKE_EXECUTABLE STREQUAL QT_QMAKE_EXECUTABLE-NOTFOUND)
  84. message(FATAL_ERROR "Could not find qmake executable")
  85. else()
  86. message(STATUS "Use qmake ${QT_QMAKE_EXECUTABLE}")
  87. endif()
  88. else()
  89. message(STATUS "Use qmake ${QT_QMAKE_EXECUTABLE}")
  90. endif()
  91. endif()
  92. extract_qt_variable(QT_INSTALL_PLUGINS)
  93. extract_qt_variable(QT_HOST_DATA)
  94. set_target_properties(${TARGET} PROPERTIES QT_PROTOBUF_PLUGIN_PATH "${QT_INSTALL_PLUGINS}/protobuf")
  95. target_compile_definitions(${TARGET} PUBLIC QT_PROTOBUF_PLUGIN_PATH="${QT_INSTALL_PLUGINS}/protobuf")
  96. target_compile_definitions(${TARGET} PRIVATE QT_BUILD_PROTOBUF_LIB PUBLIC QT_PROTOBUF_VERSION_MAJOR=${PROJECT_VERSION_MAJOR}
  97. QT_PROTOBUF_VERSION_MINOR=${PROJECT_VERSION_MINOR})
  98. set_target_properties(${TARGET} PROPERTIES VERSION ${PROJECT_VERSION} PUBLIC_HEADER "${PUBLIC_HEADER};${GENERATED_PUBLIC_HEADER}" OUTPUT_NAME ${TARGET})
  99. target_include_directories(${TARGET} PUBLIC
  100. $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
  101. $<BUILD_INTERFACE:${QT_PROTOBUF_BINARY_DIR}/include/${TARGET}>
  102. $<INSTALL_INTERFACE:${TARGET_INCLUDE_DIR}>
  103. )
  104. target_compile_features(${TARGET} PUBLIC cxx_std_14
  105. cxx_auto_type
  106. cxx_decltype
  107. cxx_final
  108. cxx_override
  109. cxx_nullptr
  110. cxx_lambdas
  111. cxx_func_identifier)
  112. target_link_libraries(${TARGET} PUBLIC Qt5::Core Qt5::Qml microjson)
  113. add_library(${QT_PROTOBUF_PROJECT}::${TARGET} ALIAS ${TARGET})
  114. include(CMakePackageConfigHelpers)
  115. configure_package_config_file(
  116. "${TARGET_CONFIG}.cmake.in" "${QT_PROTOBUF_BINARY_DIR}/${TARGET_CONFIG}.cmake"
  117. INSTALL_DESTINATION "${TARGET_CMAKE_DIR}")
  118. set(QT_PROTOBUF_EXECUTABLE_INSTALL ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/${GENERATOR_TARGET})
  119. configure_file("${CMAKE_CURRENT_SOURCE_DIR}/qt_lib_protobuf.pri.in" "${QT_PROTOBUF_BINARY_DIR}/qt_lib_protobuf.pri" @ONLY)
  120. if(QT_PROTOBUF_INSTALL)
  121. install(TARGETS ${TARGET}
  122. EXPORT ${TARGET_EXPORT} COMPONENT dev
  123. ARCHIVE DESTINATION ${TARGET_LIB_DIR} COMPONENT lib
  124. PUBLIC_HEADER DESTINATION ${TARGET_INCLUDE_DIR} COMPONENT dev
  125. LIBRARY DESTINATION ${TARGET_LIB_DIR} COMPONENT lib
  126. RUNTIME DESTINATION ${TARGET_BINDIR} COMPONENT lib)
  127. install(EXPORT ${TARGET_EXPORT} NAMESPACE ${QT_PROTOBUF_PROJECT}:: FILE ${TARGET_EXPORT}.cmake DESTINATION ${TARGET_CMAKE_DIR} COMPONENT dev)
  128. install(FILES "${QT_PROTOBUF_BINARY_DIR}/${TARGET_CONFIG}.cmake" DESTINATION "${TARGET_CMAKE_DIR}" COMPONENT dev)
  129. install(FILES "${QT_PROTOBUF_BINARY_DIR}/qt_lib_protobuf.pri" DESTINATION "${QT_HOST_DATA}/mkspecs/modules" COMPONENT dev)
  130. endif()
  131. export(TARGETS ${TARGET} NAMESPACE ${QT_PROTOBUF_PROJECT}:: FILE ${TARGET_EXPORT}.cmake)
  132. add_subdirectory("quick")
  133. add_coverage_target(TARGET ${TARGET})