CMakeLists.txt 5.4 KB

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