Skip to content

Commit b809931

Browse files
committed
Use EVAL CODE for enable_testing in cpp-library.cmake
Replaces cmake_language(DEFER DIRECTORY ...) with cmake_language(EVAL CODE ...) to execute enable_testing() immediately at the parent directory scope. This ensures enable_testing() is called before any add_test() calls, improving compatibility with CTest and test setup.
1 parent a1cb536 commit b809931

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

cpp-library.cmake

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,12 @@ function(cpp_library_setup)
167167

168168
# Enable testing at directory scope (must not be inside function scope for CTest to work)
169169
# This must happen after project(), which has already been called before cpp_library_setup()
170-
# We use cmake_language(DEFER DIRECTORY) to execute enable_testing() at directory scope
171-
# after this function returns. Since project() was called before cpp_library_setup(),
172-
# the deferred enable_testing() will have access to all project information.
170+
# We use cmake_language(EVAL CODE) to execute enable_testing() in the parent directory scope
171+
# immediately, before any add_test() calls in _cpp_library_setup_executables().
173172
if(PROJECT_IS_TOP_LEVEL AND BUILD_TESTING)
174-
# Defer enable_testing() to execute at directory scope after function returns
175-
# This is required because add_test() needs enable_testing() to be at directory scope
176-
cmake_language(DEFER DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} CALL enable_testing)
173+
# Execute enable_testing() immediately at directory scope (parent of this function)
174+
# This must happen before add_test() is called in _cpp_library_setup_executables()
175+
cmake_language(EVAL CODE "enable_testing()")
177176
endif()
178177

179178
# Include installation module that requires project() to be called first

0 commit comments

Comments
 (0)