<div dir="ltr"><div><div>Hi Chao,<br><br></div>You can see this more clearly if you do a "make VERBOSE=1" :<br><br><span style="font-family:monospace,monospace">[chuck.atkins@hal9000 build]$ make VERBOSE=1<br>...<br>[ 50%] Building C object CMakeFiles/main.dir/main.c.o<br>/usr/bin/cc     -o CMakeFiles/main.dir/main.c.o   -c /home/chuck.atkins/Code/tmp/source/main.c<br>[100%] Linking C executable main<br><b>echo This\ is\ pre\ build\ <br>This is pre build </b><br>/usr/bin/cmake -E cmake_link_script CMakeFiles/main.dir/link.txt --verbose=1<br><b>/usr/bin/cc     CMakeFiles/main.dir/main.c.o  -o main -rdynamic </b><br><b>echo This\ is\ post\ build<br>This is post build</b><br>make[2]: Leaving directory '/home/chuck.atkins/Code/tmp/build'<br>[100%] Built target main<br>make[1]: Leaving directory '/home/chuck.atkins/Code/tmp/build'<br>/usr/bin/cmake -E cmake_progress_start /home/chuck.atkins/Code/tmp/build/CMakeFiles 0<br>[chuck.atkins@hal9000 build]$ </span><br><br></div>Here you can see the order of command execution is PRE_BUILD -> Link -> POST_BUILD<br></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature"><div dir="ltr">- Chuck<br></div></div></div>
<br><div class="gmail_quote">On Fri, Apr 22, 2016 at 5:53 AM, 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">Sorry for i just know reply by email and thinks for your help again. :-)<br>
<br>
<br>
Petr Kmoch wrote<br>
<span class="">> No, it is indeed compiled and linked just fine. What I meant is:<br>
><br>
> Without any custom commands, the build process conceptually looks like<br>
> this:<br>
><br>
> buildMain() {<br>
>   compile_object_files();<br>
>   link_main_binary();<br>
><br>
>   message("Built target main");<br>
> }<br>
><br>
> With a post-build custom command:<br>
><br>
> buildMain() {<br>
>   compile_object_files();<br>
>   link_main_binary();<br>
>   post_build_command();<br>
><br>
>   message("Built target main");<br>
> }<br>
><br>
> The custom command becomes a part of the entire process of "Building<br>
> target," that's why the "Built target" message appears after the command<br>
> runs.<br>
><br>
> BTW, please keep the mailing list in copy when replying.<br>
><br>
> Petr<br>
><br>
</span>> On 22 April 2016 at 10:02, Chaos Zhang &lt;<br>
<br>
> zcsd2012@<br>
<span class=""><br>
> &gt; wrote:<br>
><br>
>> So what you mean is the target have not been complied and linked after i<br>
>> introduce<br>
>> custom commands into this target right? Do i understand right?<br>
>><br>
>> Thanks a lot for your generous help. :-)<br>
>><br>
</span>>> 2016-04-22 16:38 GMT+08:00 Petr Kmoch &lt;<br>
<br>
> petr.kmoch@<br>
<br>
> &gt;:<br>
<span class="">>><br>
>>> Hi,<br>
>>><br>
>>> the reason is that the post-build command is actually a part of building<br>
>>> "main the target." Once you introduce custom commands into a target,<br>
>>> building it includes them all, and not just compiling the object files<br>
>>> and<br>
>>> linking the binary. You will notice that the "Linking C exectuable main"<br>
>>> line came before the post-build message, so it did happen in the correct<br>
>>> order.<br>
>>><br>
>>> Petr<br>
>>><br>
</span>>>> On 22 April 2016 at 06:25, Chaos Zhang &lt;<br>
<br>
> zcsd2012@<br>
<div><div class="h5"><br>
> &gt; wrote:<br>
>>><br>
>>>> Hi all,<br>
>>>><br>
>>>> I have some trouble when i use PRE_BUILD | PRE_LINK | POST_BUILD in<br>
>>>> command<br>
>>>> "add_custom_command(...)". When i use POST_BUILD, i found the command<br>
>>>> 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<br>
>>>> not<br>
>>>> execute after [100%] Built target main in 7 line(Linux command)?<br>
>>>><br>
>>>><br>
>>>><br>
>>>><br>
>>>> --<br>
>>>> View this message in context:<br>
>>>> <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:<br>
>>>> <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<br>
>>>> more<br>
>>>> 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<br>
>>>> <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>
>>>><br>
>>><br>
>>><br>
>><br>
><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:<br>
> <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<br>
> 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<br>
> <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>
<br>
<br>
<br>
<br>
<br>
--<br>
</div></div>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-tp7593314p7593320.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-tp7593314p7593320.html</a><br>
<div class="HOEnZb"><div class="h5">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>
</div></div></blockquote></div><br></div>