I am creating an executable using the add_executable(foo sources.cpp)
then I would like to have a target that runs foo, so right now I'm doing this:
add_custom_target(run_foo
COMMAND ${CMAKE_BINARY_DIR}/test/foo
DEPENDS foo
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
it works now, but I feel like I'm doing it wrong by hardcoding the path to the binary in "COMMAND". Isn't there a way to get the path to the binary from foo
?
See:
http://www.cmake.org/cmake/help/v3.0/manual/cmake-generator-expressions.7.html
In fact, you don't even need a generator expression :) At least /w modern CMake: