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() # Download it as a submodule or include it directly message(STATUS "Crypto++ not found as package, will use submodule") # Check if we have it in external/cryptopp if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/external/cryptopp/cryptlib.h") set(CRYPTOPP_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/external/cryptopp") # For local build, we assume the library is built separately set(CRYPTOPP_LIBRARIES cryptopp) else() # Try to download it include(FetchContent) FetchContent_Declare( cryptopp GIT_REPOSITORY https://github.com/weidai11/cryptopp.git GIT_TAG CRYPTOPP_8_8_0 ) FetchContent_MakeAvailable(cryptopp) set(CRYPTOPP_INCLUDE_DIRS ${cryptopp_SOURCE_DIR}) set(CRYPTOPP_LIBRARIES cryptopp) 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 ) # 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++ target_include_directories(privatebinapi PRIVATE ${CRYPTOPP_INCLUDE_DIRS}) target_link_libraries(privatebinapi ${CRYPTOPP_LIBRARIES}) # 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)