From: Matthias Maier Date: Tue, 24 Jan 2023 01:56:46 +0000 (-0600) Subject: CMake: add_test(): refactor shared target boolean X-Git-Tag: v9.5.0-rc1~603^2~5 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b7f59e8e22829cce76610b7e5dc9a61244ec26bf;p=dealii.git CMake: add_test(): refactor shared target boolean --- diff --git a/cmake/macros/macro_deal_ii_add_test.cmake b/cmake/macros/macro_deal_ii_add_test.cmake index 6cafff1385..90cff2e218 100644 --- a/cmake/macros/macro_deal_ii_add_test.cmake +++ b/cmake/macros/macro_deal_ii_add_test.cmake @@ -412,6 +412,25 @@ function(deal_ii_add_test _category _test_name _comparison_file) file(MAKE_DIRECTORY ${_test_directory}) + # + # Determine whether the test shares a common executable target. This + # involves tests with .threads=N. and .mpirun=N. annotation, as well + # as tests with parameter files (that might share a common executable + # target). + # + # In this case we have to make sure that concurrently invoking the + # test does not accidentally trigger a concurrent build of the + # executable target. We ensure this by declaring an additional test + # that only builds the shared target / ensures the shared target is + # present. All run tests then requires this test target as a "setup + # fixture", see + # https://cmake.org/cmake/help/latest/prop_test/FIXTURES_REQUIRED.html#prop_test:FIXTURES_REQUIRED + # + set(_shared_target FALSE) + if(NOT "${_n_cpu}${_n_threads}" STREQUAL "00" OR "${_source_file}" MATCHES "(prm|json)$") + set(_shared_target TRUE) + endif() + # # Add an executable (for the first type of tests) and set up compile # definitions and the full link interface. Only add the target once. @@ -577,8 +596,7 @@ function(deal_ii_add_test _category _test_name _comparison_file) # as tests with parameter files (that might share a common executable # target). # - if( NOT "${_n_cpu}${_n_threads}" STREQUAL "00" OR - "${_source_file}" MATCHES "(prm|json)$" ) + if(_shared_target) # # Running multiple variants of tests with the same target # executable in parallel triggers a race condition where the same