<div dir="ltr"><div><div><div><div><div>No, it is indeed compiled and linked just fine. What I meant is:<br><br></div>Without any custom commands, the build process conceptually looks like this:<br><br></div>buildMain() {<br></div>  compile_object_files();<br></div>  link_main_binary();<br></div><br>  message("Built target main");<br><div><div><div>}<br><br></div><div>With a post-build custom command:<br><br></div><div>buildMain() {<br></div><div>  compile_object_files();<br></div><div>  link_main_binary();<br></div><div>  post_build_command();<br><br></div><div>  message("Built target main");<br></div><div>}<br><br></div><div>The custom command becomes a part of the entire process of "Building target," that's why the "Built target" message appears after the command runs.<br><br></div><div>BTW, please keep the mailing list in copy when replying.<br><br></div><div>Petr<br></div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 22 April 2016 at 10:02, Chaos Zhang <span dir="ltr"><<a href="mailto:zcsd2012@gmail.com" target="_blank">zcsd2012@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">So what you mean is the target have not been complied and linked after i <span style="font-size:14px">introduce custom commands into this target right? Do i understand right?</span><div><span style="font-size:14px"><br></span></div><div><span style="font-size:14px">Thanks a lot for your generous help. :-)</span></div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">2016-04-22 16:38 GMT+08:00 Petr Kmoch <span dir="ltr"><<a href="mailto:petr.kmoch@gmail.com" target="_blank">petr.kmoch@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div>Hi,<br><br></div>the reason is that the post-build command is actually a part of building "main the target." Once you introduce custom commands into a target, building it includes them all, and not just compiling the object files and linking the binary. You will notice that the "Linking C exectuable main" line came before the post-build message, so it did happen in the correct order.<br><br></div>Petr<br></div><div class="gmail_extra"><br><div class="gmail_quote">On 22 April 2016 at 06:25, Chaos Zhang <span dir="ltr"><<a href="mailto:zcsd2012@gmail.com" target="_blank">zcsd2012@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi all,<br>
<br>
I have some trouble when i use PRE_BUILD | PRE_LINK | POST_BUILD in command<br>
"add_custom_command(...)". When i use POST_BUILD, i found the command will<br>
execute before target had been built, like this:<br>
<br>
1 [root@VM_33_35_centos build]# make<br>
2 Scanning dependencies of target main<br>
3 [100%] Building C object CMakeFiles/main.dir/main.c.o<br>
4 Linking C executable main<br>
5 This is pre build<br>
6 This is post build<br>
7 [100%] Built target main<br>
<br>
In my CMakeLists.txt, the content is:<br>
 1 cmake_minimum_required(VERSION 2.8)<br>
 2 add_executable(main main.c)<br>
 3 add_custom_command(TARGET main<br>
 4                     PRE_BUILD<br>
 5                     COMMAND echo "This is pre build "<br>
 6         )<br>
 7 add_custom_command(TARGET main<br>
 8                     POST_BUILD<br>
 9                     COMMAND echo "This is post build"<br>
 10         )<br>
<br>
Why the command echo "This is post build" in 8 line(CMakeLists.txt) did not<br>
execute after [100%] Built target main in 7 line(Linux command)?<br>
<br>
<br>
<br>
<br>
--<br>
View this message in context: <a href="http://cmake.3232098.n2.nabble.com/CMake-question-of-the-time-when-the-command-will-happen-in-add-custom-command-tp7593314.html" rel="noreferrer" target="_blank">http://cmake.3232098.n2.nabble.com/CMake-question-of-the-time-when-the-command-will-happen-in-add-custom-command-tp7593314.html</a><br>
Sent from the CMake mailing list archive at Nabble.com.<br>
--<br>
<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Please keep messages on-topic and check the CMake FAQ at: <a href="http://www.cmake.org/Wiki/CMake_FAQ" rel="noreferrer" target="_blank">http://www.cmake.org/Wiki/CMake_FAQ</a><br>
<br>
Kitware offers various services to support the CMake community. For more information on each offering, please visit:<br>
<br>
CMake Support: <a href="http://cmake.org/cmake/help/support.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/support.html</a><br>
CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/consulting.html</a><br>
CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/training.html</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://public.kitware.com/mailman/listinfo/cmake" rel="noreferrer" target="_blank">http://public.kitware.com/mailman/listinfo/cmake</a><br>
</blockquote></div><br></div>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div>