STX provides flexible CMake integration supporting both traditional header-only usage and modern C++23 modules.
Requirements
C++23 standard is required. For C++ Modules support, you need:
- CMake 3.28 or later
- Clang 16+, GCC 14+, or MSVC 19.34+
Method 1: add_subdirectory
If you’ve added STX as a Git submodule or copied it into your project:
Add STX to your project
Place STX in a subdirectory (e.g., extern/stx or third_party/stx)
Configure CMakeLists.txt
add_subdirectory(extern/stx)
target_link_libraries(<your-target> PRIVATE lbyte::stx)
Build your project
cmake -B build
cmake --build build
Method 2: FetchContent
For automatic dependency management without manual downloads:
Configure FetchContent
include(FetchContent)
FetchContent_Declare(
stx
GIT_REPOSITORY https://github.com/zethcxx/stx.git
GIT_TAG v2.0.0
)
FetchContent_MakeAvailable(stx)
target_link_libraries(${PROJECT_NAME} PRIVATE lbyte::stx)
Build your project
CMake will automatically fetch STX during configuration:cmake -B build
cmake --build build
Usage in Code
#include <lbyte/stx.hpp>
// or for core only:
// #include <lbyte/stx/core.hpp>
using namespace stx;
auto main() -> int {
// Use STX utilities
return 0;
}
CMake Options
| Option | Type | Default | Description |
|---|
LBYTE_STX_USE_MODULES | BOOL | OFF | Enable C++23 modules instead of header-only |
When modules are enabled, STX becomes a STATIC library. Otherwise, it remains INTERFACE (header-only).
Target Properties
The lbyte::stx target provides:
- Include directories: Automatically added to consuming targets
- C++23 standard: Enforced via
cxx_std_23
- Module files (when enabled):
modules/stx/core.cppm
modules/stx/mem.cppm
modules/stx/time.cppm
modules/stx/stx.cppm
Next Steps
Xmake Integration
Learn how to use STX with Xmake
C++ Modules Setup
Detailed modules configuration and troubleshooting