Fix CMakeLists.txt for Linux compatibility while preserving Windows vcpkg support

This commit is contained in:
2025-08-28 20:37:34 +02:00
parent b97d9f2d7f
commit 000fde485f

View File

@@ -17,8 +17,16 @@ elseif(UNIX)
endif() endif()
# Handle dependencies # Handle dependencies
if(WIN32)
# Windows: Use vcpkg packages
find_package(cryptopp CONFIG REQUIRED) find_package(cryptopp CONFIG REQUIRED)
find_package(nlohmann_json CONFIG REQUIRED) find_package(nlohmann_json CONFIG REQUIRED)
else()
# Linux: Use system packages
find_package(PkgConfig REQUIRED)
pkg_check_modules(CRYPTOPP REQUIRED libcryptopp)
pkg_check_modules(NLOHMANN_JSON REQUIRED nlohmann_json)
endif()
# Add library sources # Add library sources
set(SOURCES set(SOURCES
@@ -45,17 +53,34 @@ target_include_directories(privatebinapi PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/include
) )
# Explicitly include vcpkg directories # Platform-specific include directories
if(WIN32)
# Windows: Include vcpkg directories
target_include_directories(privatebinapi PRIVATE target_include_directories(privatebinapi PRIVATE
${CMAKE_CURRENT_BINARY_DIR}/vcpkg_installed/x64-windows/include ${CMAKE_CURRENT_BINARY_DIR}/vcpkg_installed/x64-windows/include
) )
endif()
# Link dependencies # Link dependencies
if(WIN32)
# Windows: Use vcpkg targets
target_link_libraries(privatebinapi PRIVATE target_link_libraries(privatebinapi PRIVATE
cryptopp::cryptopp cryptopp::cryptopp
nlohmann_json::nlohmann_json nlohmann_json::nlohmann_json
${PLATFORM_LIBS} ${PLATFORM_LIBS}
) )
else()
# Linux: Use system libraries
target_link_libraries(privatebinapi PRIVATE
${CRYPTOPP_LIBRARIES}
${NLOHMANN_JSON_LIBRARIES}
${PLATFORM_LIBS}
)
target_include_directories(privatebinapi PRIVATE
${CRYPTOPP_INCLUDE_DIRS}
${NLOHMANN_JSON_INCLUDE_DIRS}
)
endif()
# Install targets # Install targets
install(TARGETS privatebinapi install(TARGETS privatebinapi