MantisBT - CMake
View Issue Details
0015755CMakeCMakepublic2015-09-21 12:272016-02-01 09:10
Dimitri Merejkowsky 
 
normalmajoralways
closedno change required 
CMake 3.3.2 
 
0015755: add_dependencies() undoes include_directories()
Calling add_dependencies() between two targets causes some calls to include_directories() to no longer be taken into account
See attached project.

$ mkdir b1
$ cmake ..
$ make
...
[ 25%] Linking C executable eggs
CMakeFiles/eggs.dir/eggs.c.o: In function `main':
eggs.c:(.text+0xa): undefined reference to `spam

$ mkdir b2
$ cmake -DADD_DEPENDENCIES=ON ..
$ make
[ 25%] Building C object spam/CMakeFiles/spam.dir/src/spam.c.o
spam/src/spam.c:1:23: fatal error: spam/spam.h: No such file or directory
No tags attached.
zip spam.zip (1,763) 2015-09-21 12:27
https://public.kitware.com/Bug/file/5532/spam.zip
Issue History
2015-09-21 12:27Dimitri MerejkowskyNew Issue
2015-09-21 12:27Dimitri MerejkowskyFile Added: spam.zip
2015-09-21 12:35Dimitri MerejkowskyNote Added: 0039462
2015-09-22 13:24Brad KingNote Added: 0039471
2015-09-22 13:24Brad KingStatusnew => resolved
2015-09-22 13:24Brad KingResolutionopen => no change required
2016-02-01 09:10Robert MaynardNote Added: 0040416
2016-02-01 09:10Robert MaynardStatusresolved => closed

Notes
(0039462)
Dimitri Merejkowsky   
2015-09-21 12:35   
Note that if I add a line looking like

include_directories(".")

in spam/CMakeLists.txt, the header is found
(0039471)
Brad King   
2015-09-22 13:24   
The include_directories after the add_subdirectory has no influence on the subdirectory. The reason your "b1" case does not get the compiler error is that without add_dependencies there is no ordering between the targets so you happen to see the linker error before the "spam" library tries to build. Even in that case running "make spam" will see the missing header.
(0040416)
Robert Maynard   
2016-02-01 09:10   
Closing resolved issues that have not been updated in more than 4 months.