2016-04-22 654 views
1

我使用时有些问题PRE_BUILD | PRE_LINK | POST_BUILD命令add_custom_command(...)。当我使用POST_BUILD,我发现该命令的目标之前将执行已建成,就像这样:CMake:为什么add_custom_command(...)中的POST_BUILD不起作用?

[[email protected]_33_35_centos build]# make 
Scanning dependencies of target main 
[100%] Building C object CMakeFiles/main.dir/main.c.o 
Linking C executable main 
This is pre build 
This is post build 
[100%] Built target main 

的内容我CMakeLists.txt是:

cmake_minimum_required(VERSION 2.8) 
add_executable(main main.c) 
add_custom_command(TARGET main 
        PRE_BUILD 
        COMMAND echo "This is pre build " 
     ) 
add_custom_command(TARGET main 
        POST_BUILD 
        COMMAND echo "This is post build" 
     ) 

为什么第8行指挥echo "This is post build"CMakeLists.txt不能在第7行(Linux命令)上的[100%] Built target main消息之后执行?

回答

0

命令加入add_custom_command(TARGET)签名成为目标的一部分,即可以假定目标待建(Built target main)仅给定的命令之后被执行。目标后

说明POST_BUILD关键字

运行已建成

意味着命令后目标文件执行(你的情况可执行main)创建。该文件是作为链接过程的一部分创建的,从Linking C executable main行开始。