Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get property returns empty variable when try to get Target Link Libraries information

Tags:

c++

cmake

I have some debug info in CMake to check if I have added no needed info compiling a project. This piece of code works propertly:

 # 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 libraries linked in 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 CMake documentation 3.0 it seems ok, but I don't know what values are available to read. I print the info AFTER make ADD_LIBRARY/ADD_EXECUTABLE

Is the LINK_LIBRARIES an incorrect value to GET_PROPERTY? How could I get that information?

like image 771
vgonisanz Avatar asked Oct 10 '14 12:10

vgonisanz


1 Answers

Directories don't 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

Also I think target_link_libraries would have effect only on the target on which it was called, not on the directory. Try using get_target_property instead.

like image 131
szx Avatar answered Sep 19 '22 14:09

szx