I'm trying to create a cmake equivalent to the following make:
demo: main.cpp
gcc -o demo main.cpp
./demo
demo is executed whenever demo is created.
This what I came to, but demo is not executed as I want:开发者_Python百科
add_executable(demo main.cpp)
add_custom_target(run_demo demo)
This is actually equivalent to:
all: demo
demo: main.cpp
gcc -o demo main.cpp
run_demo:demo
What do I miss?
I'm not entirely sure what you want, as the Makefile snippets you posted do not do what you say they do. But judging by the comment on Kleist's answer, you want the demo to run each time it is compiled anew. You can achieve that as follows:
add_executable(demo main.cpp)
add_custom_command(TARGET demo
POST_BUILD COMMAND ${CMAKE_CURRENT_BINARY_DIR}/demo)
You need to add run_demo to the ALL target:
add_custom_target(run_demo ALL demo)
精彩评论