`target_link_libraries` not propagating include paths to dependent targets


I’m new to CMake. I’ve been listening to and watching lots of CMake talks, learning about “modern” cmake, etc. I understand that I should be thinking in terms of targets. Got it.

Maybe I’m misunderstanding something, but I’m having an issue with dependents not inheriting public include properties from their dependencies.

For instance, I have a project that builds a shared library (MyLib) and three test applications (AppA, *B, and *C). So I have something like this:

add_library(MyLib SHARED my_lib.c)
target_include_directories(MyLib PUBLIC "/something/something/path")

add_exectuable(AppA app_a.c)
target_link_libraries(AppA PUBLIC MyLib)

Should the include directories from MyLib marked PUBLIC be automatically included when building AppA because of the target_link_libraries(AppA PUBLIC MyLib) ? If so, I’m not seeing that behavior. When I examine both INCLUDE_DIRECTORIES and INTERFACE_INCLUDE_DIRECTORIES for AppA target, both properties are empty, even though there is a dependency established via the call to target_link_libraries

The properties don’t get “updated” until generate time, so looking up the properties at configure time doesn’t really tell you much. You’ll need something like $<TARGET_PROPERTY:MyApp,INTERFACE_INCLUDE_DIRECTORIES> to get this information.

1 Like

Awesome, thanks. That fills in a piece of the puzzle conceptually. Much appreciated.

That was enough to get me looking deeper and I found the issue ( and turning on verbose makefiles :slight_smile: )