CMake & Submodules¶
restcl provides first-class modern CMake targets for seamless inclusion in your build configuration.
Using add_subdirectory¶
-
Add
restclas a Git submodule in your project repository: -
Add the following to your
CMakeLists.txt:
Using CPM / FetchContent¶
You can also pull restcl directly via CMake FetchContent:
include(FetchContent)
FetchContent_Declare(
restcl
GIT_REPOSITORY https://github.com/SiddiqSoft/restcl.git
GIT_TAG main
)
FetchContent_MakeAvailable(restcl)
target_link_libraries(MyRestApp PRIVATE siddiqsoft::restcl)
or use the cpm-cmake:
# download CPM.cmake..
file(DOWNLOAD https://github.com/cpm-cmake/CPM.cmake/releases/download/v0.42.3/CPM.cmake ${CMAKE_CURRENT_SOURCE_DIR}/pack/CPM.cmake)
# import the helper into our process..
include(pack/CPM.cmake)
..
..
CPMAddPackage("gh:SiddiqSoft/restcl#2.3.8")
target_link_libraries(${PROJECT_NAME} INTERFACE restcl::restcl)
Compiler Flags¶
Ensure C++23 standard support is enabled:
Build Options & Debug Tracing¶
restcl provides a build option restcl_DEBUG_TRACE to enable payload trace logging for HTTP requests and responses.
Options Matrix¶
| Option | Default | Description |
|---|---|---|
restcl_BUILD_TESTS |
OFF |
Build test suite (BUILD_TESTS). |
restcl_DEBUG_TRACE |
OFF |
Enable HTTP verb, header, and payload trace logging to std::cerr. |
CPM Dependency Cache¶
restcl configures CPM_SOURCE_CACHE by default to avoid re-downloading dependencies during clean builds:
- Windows:
%LOCALAPPDATA%\CPM\.cpmcacheor%USERPROFILE%\AppData\Local\CPM\.cpmcache - Linux / macOS:
$HOME/.cache/.cpmcache - Fallback:
${CMAKE_BINARY_DIR}/.cpmcache
You can override CPM_SOURCE_CACHE by defining it before building or in CMake command arguments:
Building & Running Tests¶
To build and run the test suite:
# Configure with test suite enabled
cmake --preset Darwin -Drestcl_BUILD_TESTS=ON
# Build the tests
cmake --build --preset Darwin
# Run tests via ctest
ctest --preset Darwin
Test Categories¶
- Unit Tests (
test_validation.cpp): Request and response validation, header serialization, error states. - Core Functionality (
test_restcl.cpp): Synchronous and asynchronous operations, HTTP verbs, client configuration. - Serialization (
test_serializers.cpp): JSON body encoding and decoding. - Integration Tests (
test_postbin.cpp): Network IO and live service response handling. - Platform Helpers (
test_libcurl_helpers.cpp):libcurlsingleton and callback wrappers. - Coverage & Mocks (
test_mock_and_coverage.cpp): AddressSanitizer and code coverage validation.