[CMake] include directories not found for object library
Miklos Espak
espakm at gmail.com
Tue May 8 19:45:59 EDT 2018
Hi,
I have an abstract class that I want to compile into many applications.
Something like this:
baseapp.h
baseapp.cpp
app1.h
app1.cpp
app2.h
app2.cpp
...
I thought of making an object library from baseapp because I want to
compile it only once and it is used only internally.
However, baseapp depends on other libraries, e.g. dcmjpeg, mylib1 and
mylib2, and the include directories of these of these libraries are not
found. For regular libraries and executables, the include directories are
picked up from the target property of the linked libraries, but for object
libraries you cannot specify target link libraries.
I came up with this:
add_library(baseapp OBJECT baseapp.h baseapp.cpp)
target_include_directories(baseapp PUBLIC
$<TARGET_PROPERTY:dcmjpeg,INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:mylib1,INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:mylib2,INCLUDE_DIRECTORIES>)
This works, but it does not look too pretty to me.
I am wondering if there is a more elegant way.
E.g. would it be a good idea to propagate the include dirs with the
add_dependencies command? E.g. instead of the above, one could write:
add_dependencies(baseapp dcmjpeg mylib1 mylib2)
Cheers,
Miklos
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20180508/a6b9133c/attachment.html>
More information about the CMake
mailing list