propagation of include paths through targets

I created a project (see here) and am using it in another project through FetchContent.

In my new project, I create a base library that depends on one of my fetched targets, we’ll call it fetchTarget. Here I have

add_library( myBase SHARED )

target_link_libraries( myBase PUBLIC fetchTarget )

This builds myBase just fine. However, when I try to use myBase

add_executable( myProg )
target_link_libraries( myProg PRIVATE myBase )

I get compile errors from sources on myProg not finding include files from fetchTarget ( myProg includes myBase which includes fetchTarget).

In trying to debug, I added this:

get_target_property(fetch_inc fetchTarget INCLUDE_DIRECTORIES)
message(" **** fetchTarget includes = ${fetch_inc}")

target_link_libraries( myBase PUBLIC fetchTarget)
get_target_property(myBase_inc myBase INCLUDE_DIRECTORIES)
message(" **** myBase includes = ${myBase_inc}")

Surprisingly, this prints

 *** fetchTarget includes = $<BUILD_INTERFACE:/usr/src/project/build-DEBUG/_deps/fetchTarget-src/src>;/usr/src/project/build-DEBUG/_deps/fetchTarget-src/src
 *** myBase includes = /usr/src/project/src/PUBLIC;/usr/src/project/src;$<BUILD_INTERFACE:/usr/src/project/src>

Why isn’t the fetchTarget include path being propagated to the myBase target? How can I fix that?

You could check the INTERFACE_INCLUDE_DIRECTORIES properties and see if they are set as expected.

The INTERFACE_INCLUDE_DIRECTORIES property was as you would expect.

It turns out that the issue was (surprise!) programmer error. myProg has most of its sources built in an OBJECT library to facilitate unit testing. When the sources were moved into the object library, myBase was left as a link library on the executable, rather than being moved to the object library. Consequently, the sources in the object library didn’t get the benefit of the fetchTarget includes when they compiled.

Thanks for looking; sorry for wasting everyone’s time.