build: CMake: made it easier to run tests in parallel
authorAlexey Sheplyakov <asheplyakov@altlinux.org>
Fri, 27 Dec 2019 13:34:05 +0000 (17:34 +0400)
committerAlexey Sheplyakov <asheplyakov@altlinux.org>
Fri, 28 Aug 2020 15:15:31 +0000 (19:15 +0400)
As of now `make -jN check` executes test suite sequentially
(although it builds test executables in parallel). This takes
a bit too long, so it would be nice to run tests in parallel.
`ctest -jN` or `make test ARGS=-jN` runs tests concurrently,
however it does not build test executables, instead it fails
if any test binary is missing.

Also `test` target is a bit special and it's impossible to add
dependencies to it, see
https://gitlab.kitware.com/cmake/cmake/issues/8438

To work around the problem define `test_suite` target which
builds the tests suite without running it, so one can both
compile and run tests in parallel

make -j8 test_suite
make test ARGS=-j8

CMakeLists.txt
check/CMakeLists.txt

index 9aec32790e6306593a13f4f3faa1f3047e6e9731..20ce8e1906cb7e39ac14ba003495928091224263 100644 (file)
@@ -20,6 +20,7 @@ set(ginaclib_version ${ginaclib_soversion}.${ginac_lt_age}.${ginac_lt_revision})
 # make check
 enable_testing()
 add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND})
+add_custom_target(test_suite)
 if (WIN32)
        if (NOT DEFINED CMAKE_RUNTIME_OUTPUT_DIRECTORY)
                set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin)
index 9c38932c4a06f73a1f94ede3f60571551c9dbda9..544c412e976f202f8abbb098a8231d447a95986f 100644 (file)
@@ -71,6 +71,7 @@ macro(add_ginac_test thename)
        endif()
        add_executable(${thename} EXCLUDE_FROM_ALL ${${thename}_sources})
        target_link_libraries(${thename} ginac ${LIBDL_LIBRARIES})
+       add_dependencies(test_suite ${thename})
        add_dependencies(check ${thename})
        add_test(NAME ${thename} COMMAND $<TARGET_FILE:${thename}>)
 endmacro()