Whenever I actually compilebar, foo_library_includes is correctly added to the include path.
However, I’d like to use a function like the following
function(add_special_target library)
get_target_property(dirs ${library} INCLUDE_DIRECTORIES)
transmogrify(dirs) # macro prepends some prefix to each element in dirs
add_custom_target(${library}.special
COMMAND "special_processor ${dirs} further_arguments"
)
endfunction()
In fact, the custom command does a bit more, but I hope you get the intention.
Unfortunately, when using add_special_target(bar) after all the above definitions, the get_target_property() will not deliver the foo_library_includes although they are made applicable when building the bar target.
What is the correct way to solve the problem? (CMake 3.21.3 here)
I acknowledge that similar questions have been posted before (like this or this one). However I do not yet see how generator expressions would help me here: set (dirs $<TARGET_PROPERTY:${library},INCLUDE_DIRECTORIES>) instead of get_target_property() won’t work, right?
If I understand the CMake documentation for INTERFACE_INCLUDE_DIRECTORIES correctly [see here]:
When target dependencies are specified using `target_link_libraries(), CMake will read this property from all target dependencies to determine the build properties of the consumer.
, CMake does so somewhere at some point anyway. Is there a way to query those “build properties”? I.e. I want:
Not at configure time. Only generator expressions can access that information (because it is only then when everything is known to answer such questions).