在CMake中,有没有办法指定我的所有可执行文件都链接到某个库?基本上我希望我的所有可执行文件都链接到tcmalloc和profiler.简单地指定-ltcmalloc和-lprofiler不是一个好的解决方案,因为我想让CMake以可移植的方式找到库的路径.
sak*_*kra 11
您可以add_executable使用自己的内置函数覆盖内置函数,它总是添加所需的链接依赖项:
macro (add_executable _name)
# invoke built-in add_executable
_add_executable(${ARGV})
if (TARGET ${_name})
target_link_libraries(${_name} tcmalloc profiler)
endif()
endmacro()
Run Code Online (Sandbox Code Playgroud)