Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions cmake/modules/RootCTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,21 @@ foreach(d ${test_list})
endif()
endforeach()

# Building a test executable must bring lib/modules.idx and all module
# artifacts (PCMs) up to date. Otherwise, a targeted build that changes a
# dictionary (e.g. `cmake --build . --target testFoo`) leaves the test running
# against a stale global module index and stale dependent PCMs, which
# manifests as modules that fail to load or as spurious segfaults. The
# modules_idx target depends on every ROOT module, so making the test
# executables depend on it ensures any dictionary change is first propagated
# through the dependent PCMs and the index is regenerated.
if(runtime_cxxmodules AND TARGET modules_idx)
get_property(modules_idx_gtests GLOBAL PROPERTY ROOT_MODULES_IDX_GTESTS)
foreach(modules_idx_gtest ${modules_idx_gtests})
add_dependencies(${modules_idx_gtest} modules_idx)
endforeach()
endif()

# When ninja or the Microsoft generator are in use, tests that compile an executable might try
# to rebuild the entire build tree. If multiple of these are invoked in parallel, ninja will
# suffer from race conditions.
Expand Down
5 changes: 5 additions & 0 deletions cmake/modules/RootMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1965,6 +1965,11 @@ function(ROOT_ADD_GTEST test_suite)
# against. For example, tests in Core should link only against libCore. This could be tricky
# to implement because some ROOT components create more than one library.
ROOT_EXECUTABLE(${test_suite} ${source_files} LIBRARIES ${ARG_LIBRARIES})
if(runtime_cxxmodules)
# Register the test so that the modules_idx dependency can be attached at
# the end of the top-level CMakeLists, where the modules_idx target exists.
set_property(GLOBAL APPEND PROPERTY ROOT_MODULES_IDX_GTESTS ${test_suite})
endif()
target_link_libraries(${test_suite} PRIVATE GTest::gtest GTest::gmock GTest::gtest_main GTest::gmock_main)
if(TARGET ROOT::TestSupport)
target_link_libraries(${test_suite} PRIVATE ROOT::TestSupport)
Expand Down
Loading