views:

64

answers:

2

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:

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?

A: 

You need to add run_demo to the ALL target:

add_custom_target(run_demo ALL demo)
Kleist
This will execute demo each call to make, while this is not exactly what I want
dimba
+3  A: 

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)
rq
Thanks, I've fixed my question
dimba