Update to use vcpkg manifest approach for dependencies

This commit is contained in:
2025-08-28 10:03:16 +02:00
parent cad675e0be
commit 1dfa80a445
2 changed files with 10 additions and 50 deletions

View File

@ -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

1
vcpkg.json Normal file
View File

@ -0,0 +1 @@
{"name": "privatebin-api", "version-string": "1.0.0", "dependencies": ["cryptopp", "nlohmann-json"]}