cmake - Transitive target_include_directories on OBJECT libraries -


here snippet make cmakelists.txt:

add_library(foo-object object src/foo.cpp) target_include_directories(foo-object public include) add_library(foo shared $<target_objects:${project_name}-object>) add_library(foo_static static $<target_objects:${project_name}-object>) 

now, works fine, both libraries generated. have problem when try use it:

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

target bar doesn't compile, because include directories foo-object not propagated. if add target_include_directories directly on foo well, compile fine.

how can make both foo , foo_static automatically use (and forward stuff depending on them) include directories foo-object?

hm, @ moment came following:

add_library(foo-object object src/foo.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:${project_name}-object>) target_include_directories(foo public ${object_include_dirs}) target_link_libraries(foo public ${object_link_libs})  add_library(foo_static static $<target_objects:${project_name}-object>) target_include_directories(foo_static public ${object_include_dirs}) target_link_libraries(foo_static public ${object_link_libs}) 

but come on, there must better way :/


Comments