Files
lib-privatebin/CMakeLists.txt

115 lines
3.2 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()
if(CRYPTOPP_FOUND)
# Use the found package
message(STATUS "Found Crypto++ package")
set(CRYPTOPP_INCLUDE_DIRS ${CRYPTOPP_INCLUDE_DIRS})
set(CRYPTOPP_LIBRARIES ${CRYPTOPP_LIBRARIES})
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()
# 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
)
# Include nlohmann/json
if(nlohmann_json_FOUND)
target_link_libraries(privatebinapi nlohmann_json::nlohmann_json)
else()
target_include_directories(privatebinapi PRIVATE ${NLOHMANN_JSON_INCLUDE_DIRS})
endif()
# Include Crypto++
if(CRYPTOPP_FOUND)
target_include_directories(privatebinapi PRIVATE ${CRYPTOPP_INCLUDE_DIRS})
target_link_libraries(privatebinapi ${CRYPTOPP_LIBRARIES})
endif()
# Link dependencies
target_link_libraries(privatebinapi ${PLATFORM_LIBS})
# Install targets
install(TARGETS privatebinapi
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)
install(FILES ${HEADERS} DESTINATION include/privatebinapi)