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 dependencies find_package(cryptopp CONFIG REQUIRED) find_package(nlohmann_json CONFIG REQUIRED) # 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 ) # Explicitly include vcpkg directories target_include_directories(privatebinapi PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/vcpkg_installed/x64-windows/include ) # Link dependencies target_link_libraries(privatebinapi PRIVATE cryptopp::cryptopp nlohmann_json::nlohmann_json ${PLATFORM_LIBS} ) # Install targets install(TARGETS privatebinapi RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib ) install(FILES ${HEADERS} DESTINATION include/privatebinapi) # Tests include(CTest) enable_testing() add_subdirectory(tests) # ===================== LLVM/clang-cl Coverage (optional) ===================== option(ENABLE_LLVM_COVERAGE "Enable LLVM/clang-cl coverage instrumentation" OFF) if(ENABLE_LLVM_COVERAGE) if(NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang") message(FATAL_ERROR "ENABLE_LLVM_COVERAGE requires clang/clang-cl as compiler (CMAKE_CXX_COMPILER_ID=Clang)") endif() # Instrumentation flags add_compile_options(-fprofile-instr-generate -fcoverage-mapping) add_link_options(-fprofile-instr-generate) # Helper variables for report tools (can be overridden from environment) set(LLVM_PROFDATA "llvm-profdata" CACHE STRING "Path to llvm-profdata") set(LLVM_COV "llvm-cov" CACHE STRING "Path to llvm-cov") # Custom target to run tests and produce coverage report # Usage: cmake --build build --target coverage_llvm --config Release add_custom_target( coverage_llvm COMMAND ${CMAKE_COMMAND} -E env LLVM_PROFILE_FILE=${CMAKE_BINARY_DIR}/coverage/%p-%m.profraw ctest -C $,${CMAKE_BUILD_TYPE},$> --output-on-failure COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/coverage COMMAND ${LLVM_PROFDATA} merge -sparse ${CMAKE_BINARY_DIR}/coverage/*.profraw -o ${CMAKE_BINARY_DIR}/coverage/merged.profdata COMMAND ${LLVM_COV} report $ --instr-profile=${CMAKE_BINARY_DIR}/coverage/merged.profdata --ignore-filename-regex="(vcpkg|external|CMakeFiles)" COMMAND ${LLVM_COV} show $ --instr-profile=${CMAKE_BINARY_DIR}/coverage/merged.profdata --ignore-filename-regex="(vcpkg|external|CMakeFiles)" --format=html --output-dir=${CMAKE_BINARY_DIR}/coverage/html WORKING_DIRECTORY ${CMAKE_BINARY_DIR} DEPENDS privatebinapi ) endif()