Feature: Dependency on add_custom_command base on generated files
Abstract
- Add an option (or a mode) not to propagate dependency on
add_custom_command
to its users by default when its 1st user isadd_library
.- I don't suppose it applicable to
add_custom_target
.
- I don't suppose it applicable to
- Use
target_sources(PUBLIC gen.h)
to propagate dependencies to users.- Control propagation with the scope of
target_link_libraries
.
- Control propagation with the scope of
- Assume Ninja generator. May be suboptimal to other generators.
Problem
Consider the case.
add_custom_command(OUTPUT gen.c ...)
add_library(A gen.c)
A's users' compilations depend on add_custom_command
.
Suggested notations
Introduce a new behavior to add_library
with add_custom_command
. Maybe the policy or the target property flag.
For a generated source file
add_custom_command(OUTPUT gen.c ...)
add_library(A gen.c foo.c bar.c)
-
add_custom_command
should affect onlygen.c
.foo.c
andbar.c
should be independent fromgen.c
. -
target_link_libraries(others A)
doesn't propagate the dependency onadd_custom_command
For local headers
add_custom_command(OUTPUT gen.h ...)
add_library(A foo.c bar.c gen.h)
-
foo.c
andbar.c
may depend ongen.h
as order-only dependency.- Dependency on
gen.h
should be order-only. I don't expectfoo.c
andbar.c
might be rebuilt always alonggen.h
.
- Dependency on
-
target_link_libraries(others A)
shouldn't depend onadd_custom_command
, sincegen.h
has the private scope.
For public headers
add_custom_command(OUTPUT gen.h ...)
add_library(A INTEFACE)
target_sources(A PUBLIC gen.h)
add_library(B b.c)
target_link_libraries(B PUBLIC A)
add_library(C c.c)
target_link_libraries(C PRIVATE B)
add_library(D d.c)
target_link_libraries(D PUBLIC C)
-
b.c
(inB
) depends ongen.h
.-
B
propagatesgen.h
-
-
c.c
(inC
) depends ongen.h
, sinceB
exposesgen.h
.-
C
doesn't exposegen.h
sinceB
is linked asPRIVATE
.
-
-
d.c
(inD
) shouldn't depend ongen.h
in compilation.-
D
will depend ongen.h
in linking, sinceA
(as a library) depends ongen.h
.
-
- Anyways,
add_dependencies(others A)
will make dependencies ongen.h
This is an simplified version of https://discourse.cmake.org/t/proposal-dependency-pre-scanner-for-generated-includes/3558