126 lines
3.8 KiB
CMake
126 lines
3.8 KiB
CMake
cmake_minimum_required(VERSION 3.10)
|
|
project(PrivateBinAPI)
|
|
|
|
set(CMAKE_CXX_STANDARD 17)
|
|
|
|
# Platform-specific configurations
|
|
if(WIN32)
|
|
# Windows-specific settings
|
|
add_definitions(-DWINDOWS)
|
|
set(PLATFORM_LIBS winhttp)
|
|
elseif(UNIX)
|
|
# Linux-specific settings
|
|
add_definitions(-DLINUX)
|
|
find_package(PkgConfig REQUIRED)
|
|
find_package(CURL REQUIRED)
|
|
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
|
|
# First try to find it as a package
|
|
find_package(PkgConfig QUIET)
|
|
if(PKG_CONFIG_FOUND)
|
|
pkg_check_modules(CRYPTOPP QUIET libcrypto++ cryptopp)
|
|
endif()
|
|
|
|
# Try to find Crypto++ using find_package
|
|
find_package(cryptopp CONFIG QUIET)
|
|
|
|
if(cryptopp_FOUND)
|
|
# Use the found package
|
|
message(STATUS "Found Crypto++ package via find_package")
|
|
set(CRYPTOPP_INCLUDE_DIRS "")
|
|
set(CRYPTOPP_LIBRARIES cryptopp::cryptopp)
|
|
else()
|
|
# Try to find it via vcpkg
|
|
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/../vcpkg/installed/x64-windows/include/cryptopp/config.h")
|
|
message(STATUS "Found Crypto++ via vcpkg")
|
|
set(CRYPTOPP_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../vcpkg/installed/x64-windows/include")
|
|
set(CRYPTOPP_LIBRARIES "${CMAKE_CURRENT_SOURCE_DIR}/../vcpkg/installed/x64-windows/lib/cryptopp.lib")
|
|
else()
|
|
# For now, we'll provide a warning and use stub implementations
|
|
# In a real implementation, you would install Crypto++ separately
|
|
message(WARNING "Crypto++ not found. Using stub implementations for cryptographic functions.")
|
|
add_definitions(-DNO_CRYPTO)
|
|
endif()
|
|
endif()
|
|
|
|
# Add library sources
|
|
set(SOURCES
|
|
src/privatebinapi.cpp
|
|
src/http_client.cpp
|
|
src/crypto.cpp
|
|
src/json_parser.cpp
|
|
src/base58.cpp
|
|
)
|
|
|
|
set(HEADERS
|
|
include/privatebinapi.h
|
|
include/http_client.h
|
|
include/crypto.h
|
|
include/json_parser.h
|
|
include/base58.h
|
|
)
|
|
|
|
# Create the shared library
|
|
add_library(privatebinapi SHARED ${SOURCES} ${HEADERS})
|
|
|
|
# Include directories
|
|
target_include_directories(privatebinapi PUBLIC
|
|
${CMAKE_CURRENT_SOURCE_DIR}/include
|
|
)
|
|
|
|
# Link dependencies
|
|
if(cryptopp_FOUND)
|
|
target_link_libraries(privatebinapi PRIVATE cryptopp::cryptopp)
|
|
elseif(CRYPTOPP_LIBRARIES)
|
|
target_include_directories(privatebinapi PRIVATE ${CRYPTOPP_INCLUDE_DIRS})
|
|
target_link_libraries(privatebinapi PRIVATE ${CRYPTOPP_LIBRARIES})
|
|
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})
|
|
|
|
# Install targets
|
|
install(TARGETS privatebinapi
|
|
RUNTIME DESTINATION bin
|
|
LIBRARY DESTINATION lib
|
|
ARCHIVE DESTINATION lib
|
|
)
|
|
|
|
install(FILES ${HEADERS} DESTINATION include/privatebinapi) |