From 8fe614c0aeed51da741e837fd6e4339dcf2c8108 Mon Sep 17 00:00:00 2001 From: GregTheMadMonk Date: Mon, 28 Oct 2024 23:44:37 +0300 Subject: [PATCH 1/9] Skip `find_package` for already present targets Draft, not implemented for msgpack-c and PkgConfig --- CMakeLists.txt | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 94f6d955..36b2bb9c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -74,7 +74,9 @@ if (REFLECTCPP_USE_BUNDLED_DEPENDENCIES) reflectcpp PUBLIC $) else () - find_package(ctre CONFIG REQUIRED) + if (NOT TARGET ctre::ctre) + find_package(ctre CONFIG REQUIRED) + endif () target_link_libraries(reflectcpp PUBLIC ctre::ctre) endif () @@ -92,7 +94,9 @@ if (REFLECTCPP_JSON) reflectcpp PUBLIC $) else () - find_package(yyjson CONFIG REQUIRED) + if (NOT PACKAGE yyjson::yyjson) + find_package(yyjson CONFIG REQUIRED) + endif () target_link_libraries(reflectcpp PUBLIC yyjson::yyjson) endif () endif () @@ -101,7 +105,9 @@ if (REFLECTCPP_BSON) list(APPEND REFLECT_CPP_SOURCES src/reflectcpp_bson.cpp ) - find_package(bson-1.0 CONFIG REQUIRED) + if (NOT TARGET mongo::bson_static AND NOT TARGET mongo::bson_shared) + find_package(bson-1.0 CONFIG REQUIRED) + endif () target_link_libraries(reflectcpp PRIVATE $,mongo::bson_static,mongo::bson_shared>) endif () @@ -122,7 +128,9 @@ if (REFLECTCPP_FLEXBUFFERS) list(APPEND REFLECT_CPP_SOURCES src/reflectcpp_flexbuf.cpp ) - find_package(flatbuffers CONFIG REQUIRED) + if (NOT TARGET flatbuffers::flatbuffers) + find_package(flatbuffers CONFIG REQUIRED) + endif () target_link_libraries(reflectcpp PUBLIC flatbuffers::flatbuffers) endif () @@ -162,7 +170,9 @@ if (REFLECTCPP_XML) list(APPEND REFLECT_CPP_SOURCES src/reflectcpp_xml.cpp ) - find_package(pugixml CONFIG REQUIRED) + if (NOT TARGET pugixml::pugixml) + find_package(pugixml CONFIG REQUIRED) + endif () target_link_libraries(reflectcpp PUBLIC pugixml::pugixml) endif () @@ -170,7 +180,9 @@ if (REFLECTCPP_YAML) list(APPEND REFLECT_CPP_SOURCES src/reflectcpp_yaml.cpp ) - find_package(yaml-cpp CONFIG REQUIRED) + if (NOT TARGET yaml-cpp::yaml-cpp) + find_package(yaml-cpp CONFIG REQUIRED) + endif () target_link_libraries(reflectcpp PUBLIC yaml-cpp::yaml-cpp) endif () @@ -186,8 +198,12 @@ if (REFLECTCPP_BUILD_TESTS) endif () if (REFLECTCPP_BUILD_BENCHMARKS) - find_package(benchmark CONFIG REQUIRED) - find_package(simdjson CONFIG REQUIRED) + if (NOT TARGET benchmark::benchmark) + find_package(benchmark CONFIG REQUIRED) + endif () + if (NOT TARGET simdjson::simdjson) + find_package(simdjson CONFIG REQUIRED) + endif () target_link_libraries(reflectcpp PUBLIC benchmark::benchmark simdjson::simdjson) add_subdirectory(benchmarks) endif () From 511e33dac95a9f5ddab1dd4546d938abd73ed172 Mon Sep 17 00:00:00 2001 From: GregTheMadMonk Date: Thu, 21 Nov 2024 15:06:33 +0300 Subject: [PATCH 2/9] Fix yyjson package check --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 36b2bb9c..9ff568d5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -94,7 +94,7 @@ if (REFLECTCPP_JSON) reflectcpp PUBLIC $) else () - if (NOT PACKAGE yyjson::yyjson) + if (NOT TARGET yyjson::yyjson) find_package(yyjson CONFIG REQUIRED) endif () target_link_libraries(reflectcpp PUBLIC yyjson::yyjson) From cc48fb482f0d1c2f225cbd1d77ac97f9d8b129e5 Mon Sep 17 00:00:00 2001 From: GregTheMadMonk Date: Thu, 21 Nov 2024 15:07:22 +0300 Subject: [PATCH 3/9] Edit msgpack and tomlplusplus imports --- CMakeLists.txt | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9ff568d5..5afbd526 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -138,11 +138,15 @@ if (REFLECTCPP_MSGPACK) list(APPEND REFLECT_CPP_SOURCES src/reflectcpp_msgpack.cpp ) - find_package(msgpack-c CONFIG REQUIRED) - if (MSVC) - target_link_libraries(reflectcpp PRIVATE "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib/msgpack-c${CMAKE_STATIC_LIBRARY_SUFFIX}") + if (TARGET msgpack-cxx) + target_link_libraries(reflectcpp INTERFACE msgpack-cxx) else () - target_link_libraries(reflectcpp PRIVATE "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib/libmsgpack-c${CMAKE_STATIC_LIBRARY_SUFFIX}") + find_package(msgpack-c CONFIG REQUIRED) + if (MSVC) + target_link_libraries(reflectcpp PRIVATE "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib/msgpack-c${CMAKE_STATIC_LIBRARY_SUFFIX}") + else () + target_link_libraries(reflectcpp PRIVATE "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib/libmsgpack-c${CMAKE_STATIC_LIBRARY_SUFFIX}") + endif () endif () endif () @@ -150,11 +154,15 @@ if (REFLECTCPP_TOML) list(APPEND REFLECT_CPP_SOURCES src/reflectcpp_toml.cpp ) - target_include_directories(reflectcpp SYSTEM PRIVATE "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/include") - if (MSVC) - target_link_libraries(reflectcpp PRIVATE "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib/tomlplusplus${CMAKE_STATIC_LIBRARY_SUFFIX}") + if (TARGET tomlplusplus::tomlplusplus) + target_link_libraries(reflectcpp INTERFACE tomlplusplus::tomlplusplus) else () - target_link_libraries(reflectcpp PRIVATE "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib/libtomlplusplus${CMAKE_STATIC_LIBRARY_SUFFIX}") + target_include_directories(reflectcpp SYSTEM PRIVATE "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/include") + if (MSVC) + target_link_libraries(reflectcpp PRIVATE "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib/tomlplusplus${CMAKE_STATIC_LIBRARY_SUFFIX}") + else () + target_link_libraries(reflectcpp PRIVATE "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib/libtomlplusplus${CMAKE_STATIC_LIBRARY_SUFFIX}") + endif () endif () endif() From e12a9779f2acd460c50b31ad7a9cd9b44d3c7645 Mon Sep 17 00:00:00 2001 From: GregTheMadMonk Date: Thu, 21 Nov 2024 15:07:46 +0300 Subject: [PATCH 4/9] Only call `install` if toplevel project --- CMakeLists.txt | 58 ++++++++++++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5afbd526..015d6cc5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -216,36 +216,38 @@ if (REFLECTCPP_BUILD_BENCHMARKS) add_subdirectory(benchmarks) endif () -include(GNUInstallDirs) -include(CMakePackageConfigHelpers) - -configure_package_config_file(reflectcpp-config.cmake.in - ${CMAKE_CURRENT_BINARY_DIR}/reflectcpp-config.cmake - INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/reflectcpp - ) +if (PROJECT_IS_TOP_LEVEL) + include(GNUInstallDirs) + include(CMakePackageConfigHelpers) + + configure_package_config_file(reflectcpp-config.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/reflectcpp-config.cmake + INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/reflectcpp + ) + + install( + FILES "${CMAKE_CURRENT_BINARY_DIR}/reflectcpp-config.cmake" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/reflectcpp" + ) -install( - FILES "${CMAKE_CURRENT_BINARY_DIR}/reflectcpp-config.cmake" - DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/reflectcpp" -) + file(GLOB_RECURSE RFL_HEADERS RELATIVE ${CMAKE_CURRENT_LIST_DIR} "${CMAKE_CURRENT_LIST_DIR}/include/*" ) -file(GLOB_RECURSE RFL_HEADERS RELATIVE ${CMAKE_CURRENT_LIST_DIR} "${CMAKE_CURRENT_LIST_DIR}/include/*" ) + target_sources(reflectcpp + PUBLIC + FILE_SET reflectcpp_headers + TYPE HEADERS + BASE_DIRS $ $ + FILES ${RFL_HEADERS}) -target_sources(reflectcpp - PUBLIC - FILE_SET reflectcpp_headers - TYPE HEADERS - BASE_DIRS $ $ - FILES ${RFL_HEADERS}) + install( + TARGETS reflectcpp + EXPORT reflectcpp-exports + FILE_SET reflectcpp_headers DESTINATION ${INCLUDE_INSTALL_DIR} + ) -install( - TARGETS reflectcpp - EXPORT reflectcpp-exports - FILE_SET reflectcpp_headers DESTINATION ${INCLUDE_INSTALL_DIR} + install( + EXPORT reflectcpp-exports + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/reflectcpp + NAMESPACE reflectcpp:: ) - -install( - EXPORT reflectcpp-exports - DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/reflectcpp - NAMESPACE reflectcpp:: -) +endif () From 0982be8ec0517935c9613ff2df0a5d5a2d3365c5 Mon Sep 17 00:00:00 2001 From: GregTheMadMonk Date: Thu, 21 Nov 2024 15:19:32 +0300 Subject: [PATCH 5/9] Change dependencies to PUBLIC --- CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 015d6cc5..856b58e0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -108,7 +108,7 @@ if (REFLECTCPP_BSON) if (NOT TARGET mongo::bson_static AND NOT TARGET mongo::bson_shared) find_package(bson-1.0 CONFIG REQUIRED) endif () - target_link_libraries(reflectcpp PRIVATE $,mongo::bson_static,mongo::bson_shared>) + target_link_libraries(reflectcpp PUBLIC $,mongo::bson_static,mongo::bson_shared>) endif () if (REFLECTCPP_CBOR) @@ -139,7 +139,7 @@ if (REFLECTCPP_MSGPACK) src/reflectcpp_msgpack.cpp ) if (TARGET msgpack-cxx) - target_link_libraries(reflectcpp INTERFACE msgpack-cxx) + target_link_libraries(reflectcpp PUBLIC msgpack-cxx) else () find_package(msgpack-c CONFIG REQUIRED) if (MSVC) @@ -155,7 +155,7 @@ if (REFLECTCPP_TOML) src/reflectcpp_toml.cpp ) if (TARGET tomlplusplus::tomlplusplus) - target_link_libraries(reflectcpp INTERFACE tomlplusplus::tomlplusplus) + target_link_libraries(reflectcpp PUBLIC tomlplusplus::tomlplusplus) else () target_include_directories(reflectcpp SYSTEM PRIVATE "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/include") if (MSVC) From 00abc7bd49332ddd71bebe0e99459890ee4fd806 Mon Sep 17 00:00:00 2001 From: GregTheMadMonk Date: Thu, 21 Nov 2024 15:23:06 +0300 Subject: [PATCH 6/9] Support possible custom tinycbor target --- CMakeLists.txt | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 856b58e0..efad8cfb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -115,12 +115,16 @@ if (REFLECTCPP_CBOR) list(APPEND REFLECT_CPP_SOURCES src/reflectcpp_cbor.cpp ) - target_include_directories(reflectcpp SYSTEM PRIVATE "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/include") - target_include_directories(reflectcpp SYSTEM PRIVATE "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/include/tinycbor") - if (MSVC) - target_link_libraries(reflectcpp PRIVATE "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib/tinycbor${CMAKE_STATIC_LIBRARY_SUFFIX}") + if (TARGET tinycbor) + target_link_libraries(reflectcpp PUBLIC tinycbor) else () - target_link_libraries(reflectcpp PRIVATE "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib/libtinycbor${CMAKE_STATIC_LIBRARY_SUFFIX}") + target_include_directories(reflectcpp SYSTEM PRIVATE "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/include") + target_include_directories(reflectcpp SYSTEM PRIVATE "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/include/tinycbor") + if (MSVC) + target_link_libraries(reflectcpp PRIVATE "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib/tinycbor${CMAKE_STATIC_LIBRARY_SUFFIX}") + else () + target_link_libraries(reflectcpp PRIVATE "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib/libtinycbor${CMAKE_STATIC_LIBRARY_SUFFIX}") + endif () endif () endif () From d7d531fddb3afa4076e7c94e77b95c98f953cb26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dr=2E=20Patrick=20Urbanke=20=28=E5=8A=89=E8=87=AA=E6=88=90?= =?UTF-8?q?=29?= Date: Fri, 6 Dec 2024 18:19:58 +0100 Subject: [PATCH 7/9] Use tomlplusplus --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 77760192..0cbe7683 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -165,8 +165,8 @@ if (REFLECTCPP_TOML) pkg_check_modules(tomlplusplus REQUIRED IMPORTED_TARGET tomlplusplus) target_link_libraries(reflectcpp PUBLIC PkgConfig::tomlplusplus) else() - if (NOT TARGET tomlplusplus::tomlplusplus) - find_package(tomlplusplus::tomlplusplus) + if (NOT TARGET tomlplusplus) + find_package(tomlplusplus) endif() target_link_libraries(reflectcpp PUBLIC tomlplusplus::tomlplusplus) endif() From 00c88072bdf7fda3a24dfcccde944c782ad89a28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dr=2E=20Patrick=20Urbanke=20=28=E5=8A=89=E8=87=AA=E6=88=90?= =?UTF-8?q?=29?= Date: Fri, 6 Dec 2024 18:25:02 +0100 Subject: [PATCH 8/9] Fix the msgpack dependency --- CMakeLists.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0cbe7683..d2a26523 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -147,13 +147,12 @@ if (REFLECTCPP_MSGPACK) if (NOT TARGET msgpack-c) find_package(msgpack-c CONFIG REQUIRED) endif() - target_link_libraries(reflectcpp PUBLIC msgpack-c) else() if (NOT TARGET msgpack) find_package(msgpack CONFIG REQUIRED) endif() - target_link_libraries(reflectcpp PUBLIC msgpack) endif() + target_link_libraries(reflectcpp PUBLIC msgpack-c) endif () if (REFLECTCPP_TOML) From bc2cbd552613f881323ca3f799d014ac5f92ae4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dr=2E=20Patrick=20Urbanke=20=28=E5=8A=89=E8=87=AA=E6=88=90?= =?UTF-8?q?=29?= Date: Fri, 6 Dec 2024 18:29:07 +0100 Subject: [PATCH 9/9] Trigger pipeline --- CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index d2a26523..ffcbbbb1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,6 +18,7 @@ option(REFLECTCPP_BUILD_TESTS "Build tests" OFF) option(REFLECTCPP_USE_BUNDLED_DEPENDENCIES "Use the bundled dependencies" ON) set(REFLECTCPP_USE_VCPKG_DEFAULT OFF) + if(REFLECTCPP_BUILD_BENCHMARKS) set(REFLECTCPP_JSON ON CACHE BOOL "" FORCE) set(REFLECTCPP_BSON ON CACHE BOOL "" FORCE) @@ -29,6 +30,7 @@ if(REFLECTCPP_BUILD_BENCHMARKS) set(REFLECTCPP_UBJSON ON CACHE BOOL "" FORCE) set(REFLECTCPP_YAML ON CACHE BOOL "" FORCE) endif() + if (REFLECTCPP_BUILD_TESTS OR REFLECTCPP_BUILD_BENCHMARKS OR (REFLECTCPP_JSON AND NOT REFLECTCPP_USE_BUNDLED_DEPENDENCIES) OR REFLECTCPP_BSON OR REFLECTCPP_CBOR OR REFLECTCPP_FLEXBUFFERS OR REFLECTCPP_MSGPACK OR REFLECTCPP_XML OR REFLECTCPP_TOML OR REFLECTCPP_UBJSON OR REFLECTCPP_YAML)