Files
cmake/Tests/RunCMake/test_include_dirs/TIDGenex.cmake
T
Daksh Mamodiya 63316be823 TEST_INCLUDE_FILES: Evaluate generator expressions in include paths
The TEST_INCLUDE_FILE(S) directory properties were written verbatim into
CTestTestfile.cmake, so a $<CONFIG>-parameterized include path could not
select a per-configuration script and failed at ctest time.

Evaluate generator expressions per include entry in
cmLocalGenerator::GenerateTestFiles():

* Entries without a generator expression are emitted unchanged.
* On single-config generators a genex entry is evaluated once and
  emitted as one unconditional include.
* On multi-config generators it is evaluated for every configuration;
  a config-independent result collapses to one unconditional include,
  otherwise each non-empty per-config result is guarded by a
  CTEST_CONFIGURATION_TYPE branch, mirroring add_test().  An entry that
  evaluates to empty adds no include.

Promote cmScriptGenerator::CreateConfigTest to a public static helper so
the include guards reuse the exact add_test() config-test encoding; the
instance overloads now delegate to it.  Evaluated results are quoted via
cmScriptGenerator::Quote, while plain entries keep their raw
serialization.

Fixes: #27941
2026-07-23 18:58:04 +02:00

31 lines
1.3 KiB
CMake

enable_testing()
set(gen_dir "${CMAKE_CURRENT_BINARY_DIR}")
# Plain include script (no generator expression in the path); used via the
# deprecated singular TEST_INCLUDE_FILE to also cover singular-first ordering.
file(GENERATE OUTPUT "${gen_dir}/plain.cmake"
CONTENT "add_test(plain_test \"${CMAKE_COMMAND}\" -E true)\n")
# Per-configuration script selected by $<CONFIG> in the include path.
file(GENERATE OUTPUT "${gen_dir}/props_$<CONFIG>.cmake"
CONTENT "add_test(config_$<CONFIG> \"${CMAKE_COMMAND}\" -E true)\n")
# Config-independent generator expression in the path: collapses to a single
# unconditional include (still runs without -C).
file(GENERATE OUTPUT "${gen_dir}/indep.cmake"
CONTENT "add_test(indep_test \"${CMAKE_COMMAND}\" -E true)\n")
# Debug-only include via a conditional-empty generator expression.
file(GENERATE OUTPUT "${gen_dir}/dbgonly.cmake"
CONTENT "add_test(dbgonly_test \"${CMAKE_COMMAND}\" -E true)\n")
set_property(DIRECTORY PROPERTY TEST_INCLUDE_FILE
"${gen_dir}/plain.cmake")
set_property(DIRECTORY APPEND PROPERTY TEST_INCLUDE_FILES
"${gen_dir}/props_$<CONFIG>.cmake")
set_property(DIRECTORY APPEND PROPERTY TEST_INCLUDE_FILES
"$<1:${gen_dir}/indep.cmake>")
set_property(DIRECTORY APPEND PROPERTY TEST_INCLUDE_FILES
"$<$<CONFIG:Debug>:${gen_dir}/dbgonly.cmake>")