In CMake, is there a way to indicate that all of my executables are associated with a library? Basically, I want all of my executables to reference tcmalloc and the profiler. Just specifying -ltcmalloc and -lprofiler is not the best solution, because I want CMake to find the library paths in a portable way.
You can override the built-in function add_executablewith your own, which always adds the necessary link dependencies:
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()
You can write a function / macro in CMake that does your work.
function(setup name sources add_executable(name sources) target_link_library(name tcmalloc profiler) endfunction(setup) setup(foo foo.c) setup(bar bar.c)
For more information, contact