Hi all,

I'm trying to setup OBJECT library for the first time and I've run into
problem that include directories are not transient. Let me illustrate:

        add_library(foo-object OBJECT src/cache.cpp)
        target_include_directories(foo-object PUBLIC include)

        add_library(foo SHARED $<TARGET_OBJECTS:foo-object>)
        add_library(foo_static STATIC $<TARGET_OBJECTS:foo-object>)

This compiles just fine. However, when I try to use it:

        add_executable(bar src/main.cpp)
        target_link_libraries(bar foo)

with `main.cpp` looking like this:

        #include "cache.h"
        int main(int, char**) { return 0; }

This doesn't compile, because the include directory from `foo-object`
isn't carried over.

This seem like slight oversight when designed the OBJECT functionality,
would it be possible to fix this in some future version? Or is there
some good reason it is like it is?

Have a nice day,
W.

PS: I've come up with following workaround, it should work right?

        add_library(foo-object OBJECT src/cache.cpp)
        target_include_directories(foo-object PUBLIC include)

        get_property(object_include_dirs TARGET foo-object PROPERTY 
INCLUDE_DIRECTORIES)
        get_property(object_link_libs TARGET foo-object PROPERTY LINK_LIBRARIES)

        add_library(foo SHARED $<TARGET_OBJECTS:foo-object>)
        target_include_directories(foo PUBLIC ${object_include_dirs})
        target_link_libraries(foo PUBLIC ${object_link_libs})

        add_library(foo_static STATIC $<TARGET_OBJECTS:foo-object>)
        target_include_directories(foo_static PUBLIC ${object_include_dirs})
        target_link_libraries(foo_static PUBLIC ${object_link_libs})

-- 
There are only two hard things in Computer Science:
cache invalidation, naming things and off-by-one errors.

Attachment: signature.asc
Description: PGP signature

-- 

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:
http://public.kitware.com/mailman/listinfo/cmake

Reply via email to