cmake中是否有办法找到定义了目标的CMakeLists.txt文件的源目录?
Somethign like:
if (TARGET Foo)
message("Library Foo was alread built in ${LOCATION_OF_FOOS_CMAKE}")
else()
add_library(Foo ...)
endif()
修改
不幸的是,我的cmake脚本必须在默认的ubuntu 14.04安装上工作。所以我只限于 cmake 2.8
答案 0 :(得分:3)
您可以使用目标媒体资源SOURCE_DIR
(添加CMake 3.7):
get_target_property(FOO_SOURCE_DIR Foo SOURCE_DIR)
对于旧版本的CMake,您可以覆盖例如add_library()
并定义您自己的SOURCE_DIR
目标媒体资源:
function(add_library _target)
_add_library(${_target} ${ARGN})
set_target_properties(${_target} PROPERTIES SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
endfunction(add_library)