Get property returns an empty variable when it tries to get information about target links

I have some debugging information in CMake to check if I added the right information when compiling the project. This piece of code works correctly:

# Include DIRECTORIES GET_PROPERTY(dirs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES) FOREACH(dir ${dirs}) MESSAGE(STATUS " * Include directory: '${dir}'") ENDFOREACH() 

But when I try to check all the libraries related in the current project, I get an empty variable:

 # Linking against GET_PROPERTY(libtargets DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY LINK_LIBRARIES) MESSAGE("Libs: ${libtargets}") FOREACH(libtarget ${libtargets}) MESSAGE(STATUS " * Target Link library: '${libtarget}'") ENDFOREACH() 

Checking the CMake 3.0 documentation seems to be fine, but I don't know what values ​​are readable. I am printing information AFTER manufacturing ADD_LIBRARY / ADD_EXECUTABLE

Is LINK_LIBRARIES wrong value for GET_PROPERTY ? How can I get this information?

+6
source share
1 answer

Directories do not have the LINK_LIBRARIES property according to this page:

http://www.cmake.org/cmake/help/v3.0/manual/cmake-properties.7.html?highlight=properties%20targets#properties-on-directories

I also think that target_link_libraries will only affect the target to which it was called, and not the directory. Try using get_target_property instead.

+6
source

Source: https://habr.com/ru/post/1204418/


All Articles