Files
cmake/Tests/RunCMake/add_test/TestDependency-ON-interface.cmake
Daksh Mamodiya 503bdb9777 Makefile: Generate test_prep targets for CMAKE_TEST_BUILD_DEPENDS
Extend the test_prep/<test> and test_prep/all build targets, generated
from add_test(BUILD_DEPENDS) when CMAKE_TEST_BUILD_DEPENDS is enabled, to
the Makefile generators.  Previously only the Ninja and FASTBuild
generators provided them.

Resolve each test's dependencies in a shared layer so all command-line
generators consume one result.  cmTestGenerator now filters target
dependencies to build-system targets and records, for each file
dependency, the single target that produces it as a primary
custom-command output (cmGlobalGenerator::FindOutputOwningTarget).  The
Makefile generators emit phony rules in CMakeFiles/Makefile2 depending on
<target>.dir/all, with top-level forwarding rules.  Sharing the
resolution also stops Ninja and FASTBuild from emitting a dead test_prep
edge for a non-buildable (e.g. INTERFACE) BUILD_DEPENDS target.

On the Makefile generators a file dependency that no single target
produces, and a test whose name contains ':', cannot be expressed as a
recursive-make rule and are reported with a warning and skipped.

Fixes: #27879
2026-06-24 17:24:54 +02:00

20 lines
525 B
CMake

cmake_minimum_required(VERSION 4.3)
set(CMAKE_TEST_BUILD_DEPENDS ON)
project(TestDependencyInterface C)
enable_testing()
add_executable(TestDependencyInterfaceExe main.c)
# Header-only INTERFACE library is not part of the build system and must be
# filtered out of the test_prep dependencies so that no dead
# "TestDependencyIface.dir/all" prerequisite is generated.
add_library(TestDependencyIface INTERFACE)
add_test(NAME InterfaceTest
COMMAND
TestDependencyInterfaceExe
BUILD_DEPENDS
TestDependencyIface)