summaryrefslogtreecommitdiff
path: root/cmake/utils/TestUtils.cmake
diff options
context:
space:
mode:
authorDimitri Staessens <dimitri@ouroboros.rocks>2026-02-02 22:50:17 +0100
committerSander Vrijders <sander@ouroboros.rocks>2026-02-04 08:17:24 +0100
commit4c64d7daef8819d644ab78a911067b16943f023d (patch)
tree7545488b224d510017f08a99006d9949367a9d77 /cmake/utils/TestUtils.cmake
parentb1687570df3e080c961cdcc0d59b708cfbdf955e (diff)
downloadouroboros-4c64d7daef8819d644ab78a911067b16943f023d.tar.gz
ouroboros-4c64d7daef8819d644ab78a911067b16943f023d.zip
build: Refactor CMake back to in-tree CMakeListsbe
This moves the build definitions back to src/ subdirectories (CMakeLists.txt per component). Configuration and dependencies are kept out of tree. Configuration options are bundled into cmake/config/ modules. Dependencies are grouped by component (system/, crypt/, eth/, coverage/, etc.). It now consistently uses target-based commands (target_include_directories, target_link_libraries) instead of global include_directories(). Proper PRIVATE/PUBLIC visibility for executable link libraries. CONFIG_OUROBOROS_DEBUG now properly set based on being a valid debug config (not just checking the string name). It also adds OuroborosTargets export for find_package() support and CMake package config files (OuroborosConfig.cmake) for easier integration with CMake projects. The build logic now follows more idiomatic CMake practices with configuration separated from target definitions. Signed-off-by: Dimitri Staessens <dimitri@ouroboros.rocks> Signed-off-by: Sander Vrijders <sander@ouroboros.rocks>
Diffstat (limited to 'cmake/utils/TestUtils.cmake')
-rw-r--r--cmake/utils/TestUtils.cmake34
1 files changed, 33 insertions, 1 deletions
diff --git a/cmake/utils/TestUtils.cmake b/cmake/utils/TestUtils.cmake
index e40bdda1..e602690c 100644
--- a/cmake/utils/TestUtils.cmake
+++ b/cmake/utils/TestUtils.cmake
@@ -3,4 +3,36 @@ function(compute_test_prefix)
file(RELATIVE_PATH _prefix "${CMAKE_SOURCE_DIR}/src" "${CMAKE_CURRENT_SOURCE_DIR}")
string(REGEX REPLACE "/tests$" "" _prefix "${_prefix}")
set(TEST_PREFIX "${_prefix}" PARENT_SCOPE)
-endfunction(compute_test_prefix)
+endfunction()
+
+# Register tests from a test executable with the test framework
+# Usage: ouroboros_register_tests(TARGET <target> TESTS <test_list> [ENVIRONMENT <env>])
+# The TESTS argument should be the test list variable created by create_test_sourcelist
+function(ouroboros_register_tests)
+ cmake_parse_arguments(PARSE_ARGV 0 ARG "" "TARGET;ENVIRONMENT" "TESTS")
+
+ if(NOT ARG_TARGET)
+ message(FATAL_ERROR "ouroboros_register_tests: TARGET required")
+ endif()
+
+ if(NOT ARG_TESTS)
+ message(FATAL_ERROR "ouroboros_register_tests: TESTS required")
+ endif()
+
+ # First entry is the test driver, skip it
+ set(_tests ${ARG_TESTS})
+ list(POP_FRONT _tests)
+
+ foreach (test_src ${_tests})
+ get_filename_component(test_name ${test_src} NAME_WE)
+ add_test(${TEST_PREFIX}/${test_name}
+ ${CMAKE_CURRENT_BINARY_DIR}/${ARG_TARGET} ${test_name})
+ # All Ouroboros tests support skip return code
+ set_property(TEST ${TEST_PREFIX}/${test_name} PROPERTY SKIP_RETURN_CODE 1)
+ # Optional environment variables
+ if(ARG_ENVIRONMENT)
+ set_property(TEST ${TEST_PREFIX}/${test_name}
+ PROPERTY ENVIRONMENT "${ARG_ENVIRONMENT}")
+ endif()
+ endforeach ()
+endfunction()