I have multiple libraries which utilize the target_include_directories(myLib PUBLIC myLib/inc)
command to populate their INTERFACE_INCLUDE_DIRECTORIES
property. Now if I build a target which is linked against such a library the INTERFACE_INCLUDE_DIRECTORIES
are propagated (as wanted) to the target.
My problem occurs when I try to use the get_property
command to snatch the list of INCLUDE_DIRECTORIES
of such a created target as - according to this already answered question - the linking of libraries is only evaluated at generate time and thus also the propagation of the INCLUDE_DIRECTORIES
is only done at generate time.
What happens is that the list created via get_property
is empty / incomplete. Is there a way to force CMake to evaluate the list again at generate time when all linking is also done? I want to use some string-operations on the list and use the result for a custom_command later on...
I'm using:
- Cmake version 3.5.0
- Scientific Linux release 7.2
Minimal Example of the problem
Main
CMakeLists.txt
cmake_minimum_required (VERSION 2.8) project(MINIMAL LANGUAGES CXX) add_subdirectory(${PROJECT_SOURCE_DIR}/libA) add_subdirectory(${PROJECT_SOURCE_DIR}/libB)
libA
CMakeLists.txt
cmake_minimum_required (VERSION 2.8) project (libA) add_library(libA ${Some_Sources} ${Some_Header}) # Set include_directories, this populates INTERFACE_INCLUDE_DIRECTORIES target_include_directories(libA PUBLIC "../libA/src")
libB
CMakeLists.txt
cmake_minimum_required (VERSION 2.8) project (libB) add_library(libB ${Some_Sources} ${Some_Header}) target_link_libraries(libB PUBLIC libA) target_include_directories(libB PUBLIC "../libB/src") # this contains only the value set here directly as # get_property is evaluated at configure_time get_property(INC_DIR_LIST TARGET libB PROPERTY INTERFACE_INCLUDE_DIRECTORIES) message(${INC_DIR_LIST}) # >>> Output: ../libB/src # this expression is evaluated at generate time, # thus it contains all needed information as the linking is done already file(GENERATE OUTPUT "includes.txt" CONTENT "$<TARGET_PROPERTY:libB,INTERFACE_INCLUDE_DIRECTORIES>\n # >>> Output in text-file: ../libB/src;../libA/src
Possible (but bad??) solution
As I know that (in the example) libB
is linked against libA
I could manually add:
get_property(INC_DIRS_LIBA TARGET libA PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
target_include_directories(libB PUBLIC INC_DIRS_LIBA)
This would work as the property is now set correctly at configure time BUT it is now set twice at generate time (as CMake sets it again automatically when evaluating the linking) and it seems just wrong to me...