From 385241ffdf2c15e383ac09145bee0cf8aef97bb1 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: Sat, 23 Nov 2024 20:49:38 +0100 Subject: [PATCH] Fixed dependencies in the CMakeLists.txt so they work with packages from sources other than vcpkg (#273) --- CMakeLists.txt | 46 +++++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 94f6d955..52d76549 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -109,13 +109,18 @@ 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}") - else () - target_link_libraries(reflectcpp PRIVATE "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib/libtinycbor${CMAKE_STATIC_LIBRARY_SUFFIX}") - endif () + if(REFLECTCPP_USE_VCPKG) + 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 () + else() + find_package(tinycbor) + target_link_libraries(reflectcpp PUBLIC tinycbor::tinycbor) + endif() endif () if (REFLECTCPP_FLEXBUFFERS) @@ -131,30 +136,33 @@ if (REFLECTCPP_MSGPACK) 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}") - else () - target_link_libraries(reflectcpp PRIVATE "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib/libmsgpack-c${CMAKE_STATIC_LIBRARY_SUFFIX}") - endif () + target_link_libraries(reflectcpp PUBLIC msgpack-c) endif () 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}") - else () - target_link_libraries(reflectcpp PRIVATE "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib/libtomlplusplus${CMAKE_STATIC_LIBRARY_SUFFIX}") - endif () + if(REFLECTCPP_USE_VCPKG) + 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 () + else() + find_package(tomlplusplus) + target_link_libraries(reflectcpp PUBLIC tomlplusplus::tomlplusplus) + endif() endif() if (REFLECTCPP_UBJSON) list(APPEND REFLECT_CPP_SOURCES src/reflectcpp_ubjson.cpp ) - target_include_directories(reflectcpp SYSTEM PRIVATE "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/include") + if(REFLECTCPP_USE_VCPKG) + target_include_directories(reflectcpp SYSTEM PRIVATE "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/include") + endif() find_package(jsoncons CONFIG REQUIRED) endif ()