Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions .github/workflows/modules.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Build & Test with modules

on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch:
release:
types: [published]

jobs:
build:
name: ${{ matrix.runs_on }}-${{ matrix.compiler }}-${{ matrix.configure_preset }}
runs-on: ${{ matrix.runs_on }}
strategy:
fail-fast: false
matrix:
include:
- runs_on: windows-2025-vs2026
compiler: msvc-14.50
configure_preset: "x64-vs"
build_preset: "x64-vs-build"
test_preset : "x64-vs-test"
# To be uncommented once GitHub Actions add GCC 15 or 16 with Ubuntu 26
# - runs_on: ubuntu-latest
# compiler: gcc-15
# configure_preset: "linux-debug"
# build_preset: "linux-debug-build"
# test_preset : "linux-debug-test"
# - runs_on: ubuntu-latest
# compiler: clang-18
# cc: clang
# cxx: clang++
# configure_preset: "linux-debug"
# build_preset: "linux-debug-build"
# test_preset : "linux-debug-test"
steps:

- uses: actions/checkout@v6

- uses: lukka/get-cmake@latest

- name: "Build & Test"
uses: lukka/run-cmake@v10
env:
CC: ${{ matrix.cc }}
CXX: ${{ matrix.cxx }}
with:
configurePreset: ${{ matrix.configure_preset }}
configurePresetAdditionalArgs: "['-DUT_ENABLE_MODULES=ON']"
buildPreset: ${{ matrix.build_preset }}
testPreset: ${{ matrix.test_preset }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
build*
out/
compile_commands.json

.vscode
.cache
.DS_Store
.vs
74 changes: 55 additions & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,40 +1,76 @@
cmake_minimum_required(VERSION 3.24)
cmake_minimum_required(VERSION 3.31) # Raise to 4.3 on availability global release and availability in CI/CD

set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD "d0edc3af-4c50-42ea-a356-e2862fe7a444") # Should be removed after 4.3 is released

include(cmake/prelude.cmake)

project(
ut
VERSION 1.1.0
LANGUAGES CXX
ut
VERSION 1.2.0
LANGUAGES CXX
)

include(cmake/project-is-top-level.cmake)
include(cmake/variables.cmake)

add_library(${PROJECT_NAME}_${PROJECT_NAME} INTERFACE)
option(UT_ENABLE_MODULES "Enable modules with import std" OFF)
option(UT_COMPILE_TIME "Enable compile time features" OFF)

if(UT_ENABLE_MODULES)
if(NOT CMAKE_GENERATOR MATCHES "Visual Studio") ## Support should be added with 4.4, todo: check when available
set(CMAKE_CXX_MODULE_STD 1)
endif()
endif()

if(UT_ENABLE_MODULES)
add_library(${PROJECT_NAME}_${PROJECT_NAME} STATIC)
set(UT_LIB_TYPE PUBLIC)
else()
add_library(${PROJECT_NAME}_${PROJECT_NAME} INTERFACE)
set(UT_LIB_TYPE INTERFACE)
endif()
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME}_${PROJECT_NAME})

if (MSVC)
string(REGEX MATCH "\/cl(.exe)?$" matched_cl ${CMAKE_CXX_COMPILER})
if (matched_cl)
# for a C++ standards compliant preprocessor, not needed for clang-cl
target_compile_options(${PROJECT_NAME}_${PROJECT_NAME} INTERFACE "/Zc:preprocessor" /GL /permissive- /Zc:lambda)
target_link_options(${PROJECT_NAME}_${PROJECT_NAME} INTERFACE /LTCG /INCREMENTAL:NO)
endif()
if(PROJECT_IS_TOP_LEVEL)
include(cmake/dev-mode.cmake)
endif()

target_compile_features(${PROJECT_NAME}_${PROJECT_NAME} ${UT_LIB_TYPE} cxx_std_23)

if(UT_ENABLE_MODULES)
target_sources(${PROJECT_NAME}_${PROJECT_NAME}
PUBLIC
FILE_SET modules TYPE CXX_MODULES
BASE_DIRS "${PROJECT_SOURCE_DIR}/modules"
FILES
"${PROJECT_SOURCE_DIR}/modules/ut.ixx"
)

target_compile_definitions(${PROJECT_NAME}_${PROJECT_NAME} PRIVATE UT_ENABLE_MODULES)
endif()

if(UT_COMPILE_TIME)
target_compile_definitions(${PROJECT_NAME}_${PROJECT_NAME} ${UT_LIB_TYPE} UT_COMPILE_TIME)
endif()

if(MSVC)
string(REGEX MATCH "\/cl(.exe)?$" matched_cl ${CMAKE_CXX_COMPILER})
if(matched_cl)
# for a C++ standards compliant preprocessor, not needed for clang-cl
target_compile_options(${PROJECT_NAME}_${PROJECT_NAME} INTERFACE "/Zc:preprocessor" /GL /permissive- /Zc:lambda)
target_link_options(${PROJECT_NAME}_${PROJECT_NAME} INTERFACE /LTCG /INCREMENTAL:NO)
endif()
endif()

set_property(TARGET ${PROJECT_NAME}_${PROJECT_NAME} PROPERTY EXPORT_NAME ${PROJECT_NAME})

target_compile_features(${PROJECT_NAME}_${PROJECT_NAME} INTERFACE cxx_std_23)
target_include_directories(
${PROJECT_NAME}_${PROJECT_NAME} ${warning_guard}
INTERFACE "$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>"
${PROJECT_NAME}_${PROJECT_NAME} ${warning_guard}
INTERFACE
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:include>"
)

if(NOT CMAKE_SKIP_INSTALL_RULES)
include(cmake/install-rules.cmake)
endif()

if (PROJECT_IS_TOP_LEVEL)
include(cmake/dev-mode.cmake)
endif()
132 changes: 132 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
{
"version": 9,
"cmakeMinimumRequired": {
"major": 3,
"minor": 31,
"patch": 0
},
"configurePresets": [
{
"name": "windows-base",
"hidden": true,
"generator": "Ninja",
"binaryDir": "${sourceDir}/out/build/${presetName}",
"installDir": "${sourceDir}/out/install/${presetName}",
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Windows"
}
},
{
"name": "x64",
"displayName": "x64",
"description": "Target Windows (64-bit) with the Visual Studio development environment.",
"inherits": "windows-base",
"architecture": {
"value": "x64",
"strategy": "external"
}
},
{
"name": "windows-base-preview",
"description": "Base preset for MSVC v14.51",
"hidden": true,
"generator": "Ninja",
"binaryDir": "${sourceDir}/out/build/${presetName}",
"installDir": "${sourceDir}/out/install/${presetName}",
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Windows"
},
"toolset": {
"value": "v145,host=x64,version=14.51"
}
},
{
"name": "x64-preview",
"displayName": "x64 Debug (MSVC v14.51 Preview)",
"inherits": "windows-base-preview",
"architecture": {
"value": "x64",
"strategy": "external"
}
},
{
"name": "windows-vs-base",
"hidden": true,
"generator": "Visual Studio 18 2026",
"binaryDir": "${sourceDir}/out/build/${presetName}",
"installDir": "${sourceDir}/out/install/${presetName}",
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Windows"
}
},
{
"name": "x64-vs",
"displayName": "x64 (VS generator)",
"inherits": "windows-vs-base",
"architecture": "x64"
},
{
"name": "linux-debug",
"displayName": "Linux Debug",
"generator": "Ninja",
"binaryDir": "${sourceDir}/out/build/${presetName}",
"installDir": "${sourceDir}/out/install/${presetName}",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
},
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Linux"
}
}
],
"buildPresets": [
{
"name": "x64-build",
"configurePreset": "x64"
},
{
"name": "x64-vs-build",
"configurePreset": "x64-vs",
"configuration": "Debug"
},
{
"name": "x64-preview-build",
"configurePreset": "x64-preview"
},
{
"name": "linux-debug-build",
"configurePreset": "linux-debug"
}
],
"testPresets": [
{
"name": "x64-test",
"configurePreset": "x64"
},

{
"name": "x64-vs-test",
"configurePreset": "x64-vs",
"configuration": "Debug",
"output": {
"outputOnFailure": true
}
},
{
"name": "x64-preview-test",
"configurePreset": "x64-preview"
},
{
"name": "linux-debug-test",
"configurePreset": "linux-debug"
}
]
}
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,28 @@ A simple and fast compiling unit test library.

### Features

- Single header
#### Single header

To enable compile time testing you must define the macro: `UT_COMPILE_TIME`
To enable compile time testing, set the option `UT_COMPILE_TIME` to ON. For example:
```cmake
set(UT_COMPILE_TIME ON)
```

Runtime testing is always enabled.

#### Modules support

The library supports C++ 20/23 modules. To enable, set the option `UT_ENABLE_MODULES` to ON. For example:
```cmake
set (UT_ENABLE_MODULES ON)
```
You can then import the library:
```cpp
import ut;
```

Please note that modules integration requires compiler and build tools that support `import std`.

### Running Specific Tests

Use the `UT_RUN` environment variable to run specific tests by name:
Expand All @@ -33,6 +49,7 @@ UT_RUN="[test1,test2,test3]" ./my_tests
### Requirements

- C++23
- CMake 3.31

## Example

Expand Down
6 changes: 6 additions & 0 deletions cmake/dev-mode.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,9 @@ set_tests_properties(ut_run_no_match PROPERTIES
ENVIRONMENT "UT_RUN=nonexistent"
PASS_REGULAR_EXPRESSION "tests: 0 \\(0 passed"
)

if (UT_ENABLE_MODULES)
add_executable(ut_module_consumer_tests "${PROJECT_SOURCE_DIR}/tests/ut_module_consumer_tests.cpp")
target_link_libraries(ut_module_consumer_tests PRIVATE ${PROJECT_NAME}::${PROJECT_NAME})
add_test(NAME ut_module_consumer_import COMMAND ut_module_consumer_tests)
endif()
2 changes: 1 addition & 1 deletion cmake/install-config.cmake
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include("${CMAKE_CURRENT_LIST_DIR}/${PROJECT_NAME}Targets.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/utTargets.cmake")
25 changes: 16 additions & 9 deletions cmake/install-rules.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
if(PROJECT_IS_TOP_LEVEL)
set(CMAKE_INSTALL_INCLUDEDIR include/${PROJECT_NAME} CACHE PATH "")
endif()

# Project is configured with no languages, so tell GNUInstallDirs the lib dir
set(CMAKE_INSTALL_LIBDIR lib CACHE PATH "")

Expand All @@ -17,11 +13,21 @@ install(
COMPONENT ${PROJECT_NAME}_Development
)

install(
TARGETS ${PROJECT_NAME}_${PROJECT_NAME}
EXPORT ${PROJECT_NAME}Targets
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)
if(UT_ENABLE_MODULES)
install(
TARGETS ${PROJECT_NAME}_${PROJECT_NAME}
EXPORT ${PROJECT_NAME}Targets
FILE_SET modules DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
CXX_MODULES_BMI DESTINATION "" # BMIs are not portable; suppress installation
COMPONENT ${PROJECT_NAME}_Development
)
else()
install(
TARGETS ${PROJECT_NAME}_${PROJECT_NAME}
EXPORT ${PROJECT_NAME}Targets
COMPONENT ${PROJECT_NAME}_Development
)
endif()

write_basic_package_version_file(
"${package}ConfigVersion.cmake"
Expand Down Expand Up @@ -53,6 +59,7 @@ install(
EXPORT ${PROJECT_NAME}Targets
NAMESPACE ${PROJECT_NAME}::
DESTINATION "${zb8_INSTALL_CMAKEDIR}"
CXX_MODULES_DIRECTORY modules
COMPONENT ${PROJECT_NAME}_Development
)

Expand Down
Loading