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