This is scheduled to be fixed in the next release by allowing OBJECT libraries to be used in target_link_libraries.
On Tue, May 8, 2018 at 7:46 PM Miklos Espak <esp...@gmail.com> wrote: > 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 > > -- > > Powered by www.kitware.com > > Please keep messages on-topic and check the CMake FAQ at: > http://www.cmake.org/Wiki/CMake_FAQ > > Kitware offers various services to support the CMake community. For more > information on each offering, please visit: > > CMake Support: http://cmake.org/cmake/help/support.html > CMake Consulting: http://cmake.org/cmake/help/consulting.html > CMake Training Courses: http://cmake.org/cmake/help/training.html > > Visit other Kitware open-source projects at > http://www.kitware.com/opensource/opensource.html > > Follow this link to subscribe/unsubscribe: > https://cmake.org/mailman/listinfo/cmake >
-- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: https://cmake.org/mailman/listinfo/cmake