CMakeLists.txt 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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_BIN_DIR ${CMAKE_INSTALL_BINDIR})
  9. set(CMAKE_AUTOMOC ON)
  10. set(CMAKE_AUTORCC ON)
  11. find_package(Qt5 COMPONENTS Core Qml REQUIRED)
  12. include(${QTPROTOBUF_CMAKE_DIR}/Coverage.cmake)
  13. include(${QTPROTOBUF_CMAKE_DIR}/GenerateQtHeaders.cmake)
  14. file(GLOB SOURCES
  15. qtprotobuf.cpp
  16. qtprotobuflogging.cpp
  17. qprotobufserializerregistry.cpp
  18. qabstractprotobufserializer.cpp
  19. qprotobufjsonserializer.cpp
  20. qprotobufserializer.cpp
  21. qprotobufmetaproperty.cpp
  22. qprotobufmetaobject.cpp)
  23. file(GLOB HEADERS
  24. qtprotobufglobal.h
  25. qtprotobuftypes.h
  26. qtprotobuflogging.h
  27. qprotobufobject.h
  28. qprotobufserializerregistry_p.h
  29. qqmllistpropertyconstructor.h
  30. qabstractprotobufserializer.h
  31. qabstractprotobufserializer_p.h
  32. qprotobufserializer.h
  33. qprotobufserializer_p.h
  34. qprotobufjsonserializer.h
  35. qprotobufselfcheckiterator.h
  36. qprotobufregistrationhelper.h
  37. qprotobufmetaproperty.h
  38. qprotobufmetaobject.h)
  39. file(GLOB PUBLIC_HEADERS
  40. qtprotobufglobal.h
  41. qtprotobuftypes.h
  42. qtprotobuflogging.h
  43. qprotobufobject.h
  44. qqmllistpropertyconstructor.h
  45. qabstractprotobufserializer.h
  46. qabstractprotobufserializer_p.h
  47. qprotobufserializer.h
  48. qprotobufjsonserializer.h
  49. qprotobufselfcheckiterator.h
  50. qprotobufregistrationhelper.h
  51. qprotobufmetaproperty.h
  52. qprotobufmetaobject.h)
  53. protobuf_generate_qt_headers(PUBLIC_HEADERS ${PUBLIC_HEADERS} COMPONENT ${TARGET})
  54. add_library(${TARGET} SHARED ${SOURCES})
  55. target_compile_definitions(${TARGET} PRIVATE QT_BUILD_PROTOBUF_LIB PUBLIC QTPROTOBUF_VERSION_MAJOR=${PROJECT_VERSION_MAJOR}
  56. QTPROTOBUF_VERSION_MINOR=${PROJECT_VERSION_MINOR})
  57. add_library(${QTPROTOBUF_COMMON_NAMESPACE}::${TARGET} ALIAS ${TARGET})
  58. set_target_properties(${TARGET} PROPERTIES VERSION ${PROJECT_VERSION} PUBLIC_HEADER "${PUBLIC_HEADERS};${GENERATED_PUBLIC_HEADERS}" OUTPUT_NAME ${TARGET})
  59. target_include_directories(${TARGET} PUBLIC
  60. $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
  61. $<BUILD_INTERFACE:${QTPROTOBUF_BINARY_DIR}/include/${TARGET}>
  62. $<INSTALL_INTERFACE:${TARGET_INCLUDE_DIR}>
  63. )
  64. target_link_libraries(${TARGET} PUBLIC Qt5::Core Qt5::Qml)
  65. target_compile_features(${TARGET} PUBLIC cxx_std_14
  66. cxx_auto_type
  67. cxx_decltype
  68. cxx_final
  69. cxx_override
  70. cxx_nullptr
  71. cxx_lambdas
  72. cxx_func_identifier)
  73. install(TARGETS ${TARGET}
  74. EXPORT ${TARGET_EXPORT}
  75. ARCHIVE DESTINATION ${TARGET_LIB_DIR}
  76. PUBLIC_HEADER DESTINATION ${TARGET_INCLUDE_DIR}
  77. LIBRARY DESTINATION ${TARGET_LIB_DIR}
  78. RUNTIME DESTINATION ${TARGET_BIN_DIR})
  79. install(EXPORT ${TARGET_EXPORT} NAMESPACE ${QTPROTOBUF_COMMON_NAMESPACE}:: FILE ${TARGET_EXPORT}.cmake DESTINATION ${TARGET_CMAKE_DIR})
  80. include(CMakePackageConfigHelpers)
  81. configure_package_config_file(
  82. "${TARGET_CONFIG}.cmake.in" "${QTPROTOBUF_BINARY_DIR}/${TARGET_CONFIG}.cmake"
  83. INSTALL_DESTINATION "${TARGET_CMAKE_DIR}")
  84. install(FILES "${QTPROTOBUF_BINARY_DIR}/${TARGET_CONFIG}.cmake" DESTINATION "${TARGET_CMAKE_DIR}")
  85. export(TARGETS ${TARGET} NAMESPACE ${QTPROTOBUF_COMMON_NAMESPACE}:: FILE ${TARGET_EXPORT}.cmake)
  86. configure_file("${CMAKE_CURRENT_SOURCE_DIR}/QtProtobufGen.cmake.in" "${QTPROTOBUF_BINARY_DIR}/QtProtobufGen.cmake" @ONLY)
  87. install(FILES "${QTPROTOBUF_BINARY_DIR}/QtProtobufGen.cmake" DESTINATION "${TARGET_CMAKE_DIR}")
  88. configure_file("${CMAKE_CURRENT_SOURCE_DIR}/parsemessages.go" "${QTPROTOBUF_BINARY_DIR}/parsemessages.go" COPYONLY)
  89. install(FILES "${QTPROTOBUF_BINARY_DIR}/parsemessages.go" DESTINATION "${TARGET_CMAKE_DIR}")
  90. configure_file("${QTPROTOBUF_CMAKE_DIR}/ProtobufLookup.cmake" "${QTPROTOBUF_BINARY_DIR}/ProtobufLookup.cmake" COPYONLY)
  91. install(FILES "${QTPROTOBUF_BINARY_DIR}/ProtobufLookup.cmake" DESTINATION "${TARGET_CMAKE_DIR}")
  92. add_subdirectory("quick")
  93. add_coverage_target(TARGET ${TARGET})