Consider a project that defines multiple object libraries from the same source file:
add_library (A OBJECT
foo.cpp
bar.cpp
)
add_library (B OBJECT
foo.cpp
bar.cpp
)
My goal is to set a preprocessor definition (say FOO
) specifically for foo.cpp
to a value dependent on the target that generates the corresponding object file. In particular, I want to avoid a target-wide visibility of the definition, e.g., by using target_compile_definitions
.
Is there a way to limit the scope of set_source_files_properties
to specific targets? I feel that a generator expression would be the appropriate tool here, something along the lines
set_source_files_properties (foo.cpp PROPERTIES COMPILE_DEFINITIONS
$<$<TARGET_SOURCE:A>:FOO=A>
$<$<TARGET_SOURCE:B>:FOO=B>
)
However, I’m not able to identify an existing (target-dependent) generator expression that is suitable for this purpose.