140 lines
4.4 KiB
CMake
140 lines
4.4 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 dependencies
|
|
if(WIN32)
|
|
# Windows: Use vcpkg packages
|
|
find_package(cryptopp 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
|
|
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})
|
|
|
|
# Define PRIVATEBINAPI_EXPORTS for the library build
|
|
target_compile_definitions(privatebinapi PRIVATE PRIVATEBINAPI_EXPORTS)
|
|
|
|
# Include directories
|
|
target_include_directories(privatebinapi PUBLIC
|
|
${CMAKE_CURRENT_SOURCE_DIR}/include
|
|
)
|
|
|
|
# Platform-specific include directories
|
|
if(WIN32)
|
|
# Windows: Include vcpkg directories
|
|
target_include_directories(privatebinapi PRIVATE
|
|
${CMAKE_CURRENT_BINARY_DIR}/vcpkg_installed/x64-windows/include
|
|
)
|
|
endif()
|
|
|
|
# Link dependencies
|
|
if(WIN32)
|
|
# Windows: Use vcpkg targets
|
|
target_link_libraries(privatebinapi PRIVATE
|
|
cryptopp::cryptopp
|
|
nlohmann_json::nlohmann_json
|
|
${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 privatebinapi
|
|
RUNTIME DESTINATION bin
|
|
LIBRARY DESTINATION lib
|
|
ARCHIVE DESTINATION lib
|
|
)
|
|
|
|
install(FILES ${HEADERS} DESTINATION include/privatebinapi)
|
|
|
|
# Tests
|
|
include(CTest)
|
|
enable_testing()
|
|
add_subdirectory(tests)
|
|
add_subdirectory(example)
|
|
|
|
# ===================== 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 auf konkrete Targets anwenden (bereits definierte Targets)
|
|
if(TARGET privatebinapi)
|
|
target_compile_options(privatebinapi PRIVATE -fprofile-instr-generate -fcoverage-mapping)
|
|
endif()
|
|
if(TARGET test_basic)
|
|
target_compile_options(test_basic PRIVATE -fprofile-instr-generate -fcoverage-mapping)
|
|
endif()
|
|
if(TARGET example)
|
|
target_compile_options(example PRIVATE -fprofile-instr-generate -fcoverage-mapping)
|
|
endif()
|
|
|
|
# Helper variables for report tools
|
|
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
|
|
add_custom_target(
|
|
coverage_llvm
|
|
COMMAND ${CMAKE_COMMAND} -E env
|
|
LLVM_PROFILE_FILE=${CMAKE_BINARY_DIR}/coverage/%p-%m.profraw
|
|
ctest -C $<IF:$<CONFIG:>,${CMAKE_BUILD_TYPE},$<CONFIG>> --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 $<TARGET_FILE:privatebinapi> --instr-profile=${CMAKE_BINARY_DIR}/coverage/merged.profdata --ignore-filename-regex="(vcpkg^|external^|CMakeFiles)"
|
|
COMMAND ${LLVM_COV} show $<TARGET_FILE:privatebinapi> --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()
|