From 1dfa80a44500f0617eadad5ec6e35ab628e9b626 Mon Sep 17 00:00:00 2001 From: elpatron Date: Thu, 28 Aug 2025 10:03:16 +0200 Subject: [PATCH] Update to use vcpkg manifest approach for dependencies --- CMakeLists.txt | 59 ++++++++------------------------------------------ vcpkg.json | 1 + 2 files changed, 10 insertions(+), 50 deletions(-) create mode 100644 vcpkg.json diff --git a/CMakeLists.txt b/CMakeLists.txt index 6b7528b..763a069 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,43 +16,9 @@ elseif(UNIX) set(PLATFORM_LIBS ${CURL_LIBRARIES}) endif() -# Handle nlohmann/json dependency -# First try to find it as a package -find_package(nlohmann_json QUIET) - -if(nlohmann_json_FOUND) - # Use the found package - message(STATUS "Found nlohmann_json package") -else() - # Download it as a submodule or include it directly - message(STATUS "nlohmann_json not found as package, will use submodule") - - # Check if we have it in external/json - if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/external/json/include/nlohmann/json.hpp") - set(NLOHMANN_JSON_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/external/json/include") - else() - # Try to download it with compatibility settings - include(FetchContent) - FetchContent_Declare( - nlohmann_json - GIT_REPOSITORY https://github.com/nlohmann/json.git - GIT_TAG v3.11.2 - ) - # Set compatibility flag for older CMake versions - set(CMAKE_POLICY_VERSION_MINIMUM 3.5) - FetchContent_MakeAvailable(nlohmann_json) - set(NLOHMANN_JSON_INCLUDE_DIRS ${nlohmann_json_SOURCE_DIR}/include) - endif() -endif() - -# Handle Crypto++ dependency -find_package(cryptopp CONFIG QUIET) - -if(cryptopp_FOUND) - message(STATUS "Found Crypto++ package via vcpkg") -else() - message(WARNING "Crypto++ not found via vcpkg. Make sure to use the vcpkg toolchain file.") -endif() +# Handle dependencies +find_package(cryptopp CONFIG REQUIRED) +find_package(nlohmann_json CONFIG REQUIRED) # Add library sources set(SOURCES @@ -79,19 +45,12 @@ target_include_directories(privatebinapi PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include ) -# Link Crypto++ -if(cryptopp_FOUND) - target_link_libraries(privatebinapi PRIVATE cryptopp::cryptopp) -endif() - -# Include nlohmann/json -if(nlohmann_json_FOUND) - target_link_libraries(privatebinapi PRIVATE nlohmann_json::nlohmann_json) -else() - target_include_directories(privatebinapi PRIVATE ${NLOHMANN_JSON_INCLUDE_DIRS}) -endif() - -target_link_libraries(privatebinapi PRIVATE ${PLATFORM_LIBS}) +# Link dependencies +target_link_libraries(privatebinapi PRIVATE + cryptopp::cryptopp + nlohmann_json::nlohmann_json + ${PLATFORM_LIBS} +) # Install targets install(TARGETS privatebinapi diff --git a/vcpkg.json b/vcpkg.json new file mode 100644 index 0000000..2607a79 --- /dev/null +++ b/vcpkg.json @@ -0,0 +1 @@ +{"name": "privatebin-api", "version-string": "1.0.0", "dependencies": ["cryptopp", "nlohmann-json"]}