Reputation: 3078
In this snippet:
cmake_minimum_required(VERSION 3.0)
project(hello LANGUAGES C VERSION 0.0.1)
add_library(a INTERFACE)
target_include_directories(a INTERFACE /usr/local/include)
add_executable(b main.c)
target_link_libraries(b PUBLIC a)
get_target_property(dirs b INCLUDE_DIRECTORIES)
message(STATUS "dirs: ${dirs}")
CMake will print:
-- dirs: dirs-NOTFOUND
I want all include directories of a target, but apparently those added via target_link_libraries
get ignored somehow. How can I obtain all include directories of a target?
Upvotes: 0
Views: 2748
Reputation: 42862
The problem is that the information you are seeking is only available after the generation step. You can get those only with e.g. add_custom_target()
calls, which run during compile time. Your get_target_property()
and message()
calls run during CMake configuration step.
Disclaimer: Taken with small modifications from the question linked below:
add_custom_command(
b_lists ALL
${CMAKE_COMMAND} -E echo "b INCLUDE_DIRECTORIES: $<TARGET_PROPERTY:B,INCLUDE_DIRECTORIES>"
)
References
Upvotes: 2
Reputation: 44
target_link_libraries does not add any directory, it adds the specific library that you've included. Use make VERBOSE=1 to see the complete command. You might be able to get the library output directory by reading the build directory or the library output name.
Upvotes: 0