开发者

cmake dependency

开发者 https://www.devze.com 2023-01-01 08:23 出处:网络
I\'m trying to create a cmake equivalent to the following make: demo: main.cpp gcc -o demo main.cpp ./demo

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)
0

精彩评论

暂无评论...
验证码 换一张
取 消