CMakeLists.txt 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. qprotobufmetaproperty.h
  37. qprotobufmetaobject.h)
  38. file(GLOB PUBLIC_HEADERS
  39. qtprotobufglobal.h
  40. qtprotobuftypes.h
  41. qtprotobuflogging.h
  42. qprotobufobject.h
  43. qqmllistpropertyconstructor.h
  44. qabstractprotobufserializer.h
  45. qabstractprotobufserializer_p.h
  46. qprotobufserializer.h
  47. qprotobufjsonserializer.h
  48. qprotobufselfcheckiterator.h
  49. qprotobufmetaproperty.h
  50. qprotobufmetaobject.h)
  51. protobuf_generate_qt_headers(PUBLIC_HEADERS ${PUBLIC_HEADERS} COMPONENT ${TARGET})
  52. add_library(${TARGET} SHARED ${SOURCES})
  53. target_compile_definitions(${TARGET} PRIVATE QT_BUILD_PROTOBUF_LIB PUBLIC QTPROTOBUF_VERSION_MAJOR=${PROJECT_VERSION_MAJOR}
  54. QTPROTOBUF_VERSION_MINOR=${PROJECT_VERSION_MINOR})
  55. add_library(${QTPROTOBUF_COMMON_NAMESPACE}::${TARGET} ALIAS ${TARGET})
  56. set_target_properties(${TARGET} PROPERTIES VERSION ${PROJECT_VERSION} PUBLIC_HEADER "${PUBLIC_HEADERS};${GENERATED_PUBLIC_HEADERS}" OUTPUT_NAME ${TARGET})
  57. target_include_directories(${TARGET} PUBLIC
  58. $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
  59. $<BUILD_INTERFACE:${QTPROTOBUF_BINARY_DIR}/include/${TARGET}>
  60. $<INSTALL_INTERFACE:${TARGET_INCLUDE_DIR}>
  61. )
  62. target_link_libraries(${TARGET} PUBLIC Qt5::Core Qt5::Qml)
  63. target_compile_features(${TARGET} PUBLIC cxx_std_14
  64. cxx_auto_type
  65. cxx_decltype
  66. cxx_final
  67. cxx_override
  68. cxx_nullptr
  69. cxx_lambdas
  70. cxx_func_identifier)
  71. install(TARGETS ${TARGET}
  72. EXPORT ${TARGET_EXPORT}
  73. ARCHIVE DESTINATION ${TARGET_LIB_DIR}
  74. PUBLIC_HEADER DESTINATION ${TARGET_INCLUDE_DIR}
  75. LIBRARY DESTINATION ${TARGET_LIB_DIR}
  76. RUNTIME DESTINATION ${TARGET_BIN_DIR})
  77. install(EXPORT ${TARGET_EXPORT} NAMESPACE ${QTPROTOBUF_COMMON_NAMESPACE}:: FILE ${TARGET_EXPORT}.cmake DESTINATION ${TARGET_CMAKE_DIR})
  78. include(CMakePackageConfigHelpers)
  79. configure_package_config_file(
  80. "${TARGET_CONFIG}.cmake.in" "${QTPROTOBUF_BINARY_DIR}/${TARGET_CONFIG}.cmake"
  81. INSTALL_DESTINATION "${TARGET_CMAKE_DIR}")
  82. install(FILES "${QTPROTOBUF_BINARY_DIR}/${TARGET_CONFIG}.cmake" DESTINATION "${TARGET_CMAKE_DIR}")
  83. export(TARGETS ${TARGET} NAMESPACE ${QTPROTOBUF_COMMON_NAMESPACE}:: FILE ${TARGET_EXPORT}.cmake)
  84. configure_file("${CMAKE_CURRENT_SOURCE_DIR}/QtProtobufGen.cmake.in" "${QTPROTOBUF_BINARY_DIR}/QtProtobufGen.cmake" @ONLY)
  85. install(FILES "${QTPROTOBUF_BINARY_DIR}/QtProtobufGen.cmake" DESTINATION "${TARGET_CMAKE_DIR}")
  86. configure_file("${CMAKE_CURRENT_SOURCE_DIR}/parsemessages.go" "${QTPROTOBUF_BINARY_DIR}/parsemessages.go" COPYONLY)
  87. install(FILES "${QTPROTOBUF_BINARY_DIR}/parsemessages.go" DESTINATION "${TARGET_CMAKE_DIR}")
  88. configure_file("${QTPROTOBUF_CMAKE_DIR}/ProtobufLookup.cmake" "${QTPROTOBUF_BINARY_DIR}/ProtobufLookup.cmake" COPYONLY)
  89. install(FILES "${QTPROTOBUF_BINARY_DIR}/ProtobufLookup.cmake" DESTINATION "${TARGET_CMAKE_DIR}")
  90. add_subdirectory("quick")
  91. add_coverage_target(TARGET ${TARGET})