Reputation: 927
I have 2 projects L and A in CMake, say L is a library and A an application depending on L.
The folders hierarchy looks like:
Now, in terms of include directories I understand I need to specify subL in L/CMakeLists.txt/include_directories(), so the other files within L can reference the include files simply with a #include "mySubLHeaderFile.h" or #include < mySubLHeaderFile.h>.
Now if I want to reference a header file from subL within a file from the A project and be able to reference this subL file simply with a #include "mySubLHeaderFile.h" or #include < mySubLHeaderFile.h>, I have noticed I need to re-specify subL in A/CMakeLists.txt/include_directories(). Is this a normal behavior? Aren't the include_directories() inherited from the depended project?
------ EDIT 1 -------
Note that I have a top level CMakeLists.txt above A and L.
Upvotes: 0
Views: 2111
Reputation: 7339
Yes, that is the standard behavior for CMake's include_directories
command. If you want properties to propagate to dependents, use the target_include_directories
command that became standard with version 3. Specifically, locations with headers that are needed by client code should be in the PUBLIC
or INTERFACE
section. If SubL also needs to include headers there, use PUBLIC
. Look at the whole family of target_*
commands for property propagation to dependents.
Upvotes: 3