Skip to content

Commit

Permalink
CMake: set ALWAYS_EMIT_SHARED_TEST_TARGETS when using ninja
Browse files Browse the repository at this point in the history
  • Loading branch information
tamiko committed Jan 26, 2024
1 parent 62a7aa7 commit 13e547e
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions cmake/macros/macro_deal_ii_pickup_tests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@
# * "medium": workstation, >=8 physical cores, >=32GB RAM
# * "heavy": compute node, >=32 physical cores, >=128GB RAM
#
# ALWAYS_EMIT_SHARED_TEST_TARGETS
# - If set to true then we: (a) always split out compiling and linking
# of an executable into a separate "test_dependency/" test, and (b)
# break up implicit target dependencies between the two.
#
# numdiff is used for the comparison of test results. Its location can be
# specified with NUMDIFF_DIR.
#
Expand Down Expand Up @@ -256,6 +261,28 @@ macro(deal_ii_pickup_tests)
set_if_empty(TESTING_ENVIRONMENT "$ENV{TESTING_ENVIRONMENT}")
set_if_empty(TESTING_ENVIRONMENT "light")

if(CMAKE_GENERATOR MATCHES "Ninja")
#
# When running tests for in parallel ctest issues multiple concurrent
# calls to the underlying build system. For performance reasons the
# ninja build system only ensures that ".ninja_log" is not corrupted
# in such a scenario, but doesn't ensure that it is in fact complete.
#
# We thus need to set ALWAYS_EMIT_SHARED_TEST_TARGETS to true, which
# splits all test targets and drops implicit target dependencies
# between (a) compilation and linkage, and (b) execution and output
# comparison.
#
# That way a parallel $ ctest invocation does what one expects, i.e.,
# trying to compile a test executable precisely once. Without this
# workaround multiple ninja instances might try to compile the same
# test executable multiple times leading to race conditions.
#
set_if_empty(ALWAYS_EMIT_SHARED_TEST_TARGETS TRUE)
else()
set_if_empty(ALWAYS_EMIT_SHARED_TEST_TARGETS FALSE)
endif()

#
# ... and finally pick up tests:
#
Expand Down

0 comments on commit 13e547e

Please sign in to comment.