CMakeLists.txt 5.8 KB

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