当尝试获取Target Link Libraries信息时,获取属性返回空变量

时间:2014-10-10 12:33:47

标签: c++ cmake

我在CMake中有一些调试信息,以检查我是否添加了编译项目所需的信息。这段代码很有效:

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

但是当我尝试检查当前项目中链接的所有库时,我得到一个空变量:

# 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()

检查CMake documentation 3.0似乎没问题,但我不知道有哪些值可供阅读。我打印信息AFTER make ADD_LIBRARY / ADD_EXECUTABLE

LINK_LIBRARIES是否为GET_PROPERTY的值不正确?我怎么能得到这些信息?

1 个答案:

答案 0 :(得分:5)

目录根据此页面没有LINK_LIBRARIES属性:

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

另外我认为target_link_libraries只会影响调用它的目标,而不会影响目录。请尝试使用get_target_property