From b65b95dda4e2aa7983a342957ff287059225bc22 Mon Sep 17 00:00:00 2001 From: John Thacker Date: Thu, 25 Aug 2022 07:49:09 -0400 Subject: CMake: Build test_programs automatically when running test Since we require CMake version at least 3.7, we can use fixtures to ensure that the unittests have been built before running suite_unittests. This only applies to running the tests via ctest (including '[ninja|make] test'), not when running pytest directly. Fix #17191 --- CMakeLists.txt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 950f669cd6..4384cbb564 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3937,6 +3937,14 @@ set(_test_group_list set(TEST_EXTRA_ARGS "" CACHE STRING "Extra arguments to pass to test/test.py") separate_arguments(TEST_EXTRA_ARGS) +add_test(build_unittests + "${CMAKE_COMMAND}" + --build "${CMAKE_BINARY_DIR}" + --config "${CONFIG}" + --target test-programs +) +set_tests_properties(build_unittests PROPERTIES FIXTURES_SETUP unittests) + foreach(_group_name ${_test_group_list}) add_test( NAME ${_group_name} @@ -3950,6 +3958,8 @@ foreach(_group_name ${_test_group_list}) set_tests_properties(${_group_name} PROPERTIES TIMEOUT 600) endforeach() +set_tests_properties(suite_unittests PROPERTIES FIXTURES_REQUIRED unittests) + # Make it possible to run pytest without passing the full path as argument. if(NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR) file(READ "${CMAKE_CURRENT_SOURCE_DIR}/pytest.ini" pytest_ini) -- cgit v1.2.3