Build System & Dependencies
Relevant source files
The following files were used as context for generating this wiki page:
HXLibs uses CMake as its primary build system and vcpkg for managing C++ dependencies. The project targets C++20 and integrates a benchmark-specific build process for performance evaluation against external libraries.
Build System Architecture
The build system relies on a hierarchical CMake structure. The root CMakeLists.txt defines the project and core settings, while subdirectories handle specific modules like tests, examples, and benchmarks.
Core Build Configuration
The system requires a minimum CMake version of 3.15. It defaults to a Release build type if none is specified, which sets the __HX_UN_DEBUG__ flag to "ON" for specific optimizations. Development features, such as SQLite3 support, are enabled when the project is built as the primary target.
Sources: CMakeLists.txt:1-35
Compilation Standards and Safety
The project enforces modern C++ practices through compiler-specific options. When using Clang or AppleClang, the build system adds -Wpedantic, -Wreserved-id-macro, and -Wreserved-identifier to detect the use of reserved identifiers.
Sources: documents/CodingStandards/CppStyle.md:37-47
Build Component Flow
The following diagram illustrates how CMake includes different modules during the configuration phase:
Sources: CMakeLists.txt:20-41
Dependency Management
HXLibs manages internal and external dependencies through vcpkg.json and dedicated shell scripts for benchmark environments.
Primary Dependencies
The project lists mandatory external libraries in the vcpkg.json manifest.
| Dependency | Purpose | Source Reference |
|---|---|---|
openssl | Security and SSL/TLS support | vcpkg.json:8 |
sqlite3 | Local database storage | vcpkg.json:9 |
Benchmark Dependencies
The benchmark subsystem fetches specific versions of external libraries using git to ensure reproducible performance comparisons.
Specific external versions used:
- Asio: Commit
231cb29b... - Yalantinglibs: Commit
225f4d48... - Nginx: Commit
481d28cb... - Wrk: Commit
a211dd5a...
Sources: benchmarks/http/scripts/build.sh:22-31
Benchmark Build Pipeline
The benchmark suite involves a complex pipeline that builds both the local HXLibs targets and third-party servers.
Build Scripts and Tooling
The build.sh script automates the retrieval of source code and the compilation process using clang, cmake, and ninja. It creates a .benchmark-build directory containing binaries and assets.
Sources: benchmarks/http/scripts/build.sh:7-14, 52-59
Target Configuration
The benchmark-specific CMake configuration links the benchmark executables to the core HXLibs library and necessary threading libraries.
add_executable(bench-hxlibs servers/hxlibs_server.cpp)
target_link_libraries(bench-hxlibs PRIVATE HXLibs)
add_executable(bench-asio servers/asio_server.cpp)
target_include_directories(bench-asio PRIVATE "${ASIO_SOURCE_DIR}/asio/include")
target_link_libraries(bench-asio PRIVATE Threads::Threads)
Sources: benchmarks/http/CMakeLists.txt:10-18
Build Matrix
The build system supports multiple optimization levels, specifically O2 and O3, for performance comparison. By default, it builds the O3 matrix.
Sources: benchmarks/http/scripts/build.sh:11-13, 62-67
Build Environment Variables
The build and run scripts utilize several environment variables to control output paths and execution parameters.
| Variable | Description | Default Value |
|---|---|---|
BENCH_BUILD_DIR | Directory for build artifacts | ${REPO_DIR}/.benchmark-build |
BENCH_OPTIMIZATIONS | Optimization levels to build/run | O3 |
ASIO_SOURCE_DIR | Path to Asio source code | Required for benchmark |
YLT_SOURCE_DIR | Path to YalantingLibs source code | Required for benchmark |
Sources: benchmarks/http/scripts/build.sh:10-14, benchmarks/http/CMakeLists.txt:13-22
Summary
The build system facilitates a modular C++20 development environment by combining CMake for project structure and vcpkg for dependency resolution. It includes a specialized benchmark pipeline that fetches and builds external libraries (Asio, Nginx, Yalantinglibs) to provide a standardized environment for performance analysis across different optimization levels.