Hi Chao,

You can see this more clearly if you do a "make VERBOSE=1" :

[chuck.atkins@hal9000 build]$ make VERBOSE=1
...
[ 50%] Building C object CMakeFiles/main.dir/main.c.o
/usr/bin/cc     -o CMakeFiles/main.dir/main.c.o   -c
/home/chuck.atkins/Code/tmp/source/main.c
[100%] Linking C executable main

*echo This\ is\ pre\ build\ This is pre build *
/usr/bin/cmake -E cmake_link_script CMakeFiles/main.dir/link.txt --verbose=1
*/usr/bin/cc     CMakeFiles/main.dir/main.c.o  -o main -rdynamic *

*echo This\ is\ post\ buildThis is post build*
make[2]: Leaving directory '/home/chuck.atkins/Code/tmp/build'
[100%] Built target main
make[1]: Leaving directory '/home/chuck.atkins/Code/tmp/build'
/usr/bin/cmake -E cmake_progress_start
/home/chuck.atkins/Code/tmp/build/CMakeFiles 0
[chuck.atkins@hal9000 build]$

Here you can see the order of command execution is PRE_BUILD -> Link ->
POST_BUILD

- Chuck

On Fri, Apr 22, 2016 at 5:53 AM, Chaos Zhang <zcsd2...@gmail.com> wrote:

> Sorry for i just know reply by email and thinks for your help again. :-)
>
>
> Petr Kmoch wrote
> > No, it is indeed compiled and linked just fine. What I meant is:
> >
> > Without any custom commands, the build process conceptually looks like
> > this:
> >
> > buildMain() {
> >   compile_object_files();
> >   link_main_binary();
> >
> >   message("Built target main");
> > }
> >
> > With a post-build custom command:
> >
> > buildMain() {
> >   compile_object_files();
> >   link_main_binary();
> >   post_build_command();
> >
> >   message("Built target main");
> > }
> >
> > 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.
> >
> > BTW, please keep the mailing list in copy when replying.
> >
> > Petr
> >
> > On 22 April 2016 at 10:02, Chaos Zhang &lt;
>
> > zcsd2012@
>
> > &gt; wrote:
> >
> >> So what you mean is the target have not been complied and linked after i
> >> introduce
> >> custom commands into this target right? Do i understand right?
> >>
> >> Thanks a lot for your generous help. :-)
> >>
> >> 2016-04-22 16:38 GMT+08:00 Petr Kmoch &lt;
>
> > petr.kmoch@
>
> > &gt;:
> >>
> >>> Hi,
> >>>
> >>> 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.
> >>>
> >>> Petr
> >>>
> >>> On 22 April 2016 at 06:25, Chaos Zhang &lt;
>
> > zcsd2012@
>
> > &gt; wrote:
> >>>
> >>>> Hi all,
> >>>>
> >>>> I have some trouble when i use PRE_BUILD | PRE_LINK | POST_BUILD in
> >>>> command
> >>>> "add_custom_command(...)". When i use POST_BUILD, i found the command
> >>>> will
> >>>> execute before target had been built, like this:
> >>>>
> >>>> 1 [root@VM_33_35_centos build]# make
> >>>> 2 Scanning dependencies of target main
> >>>> 3 [100%] Building C object CMakeFiles/main.dir/main.c.o
> >>>> 4 Linking C executable main
> >>>> 5 This is pre build
> >>>> 6 This is post build
> >>>> 7 [100%] Built target main
> >>>>
> >>>> In my CMakeLists.txt, the content is:
> >>>>  1 cmake_minimum_required(VERSION 2.8)
> >>>>  2 add_executable(main main.c)
> >>>>  3 add_custom_command(TARGET main
> >>>>  4                     PRE_BUILD
> >>>>  5                     COMMAND echo "This is pre build "
> >>>>  6         )
> >>>>  7 add_custom_command(TARGET main
> >>>>  8                     POST_BUILD
> >>>>  9                     COMMAND echo "This is post build"
> >>>>  10         )
> >>>>
> >>>> Why the command echo "This is post build" in 8 line(CMakeLists.txt)
> did
> >>>> not
> >>>> execute after [100%] Built target main in 7 line(Linux command)?
> >>>>
> >>>>
> >>>>
> >>>>
> >>>> --
> >>>> View this message in context:
> >>>>
> http://cmake.3232098.n2.nabble.com/CMake-question-of-the-time-when-the-command-will-happen-in-add-custom-command-tp7593314.html
> >>>> Sent from the CMake mailing list archive at Nabble.com.
> >>>> --
> >>>>
> >>>> Powered by www.kitware.com
> >>>>
> >>>> Please keep messages on-topic and check the CMake FAQ at:
> >>>> http://www.cmake.org/Wiki/CMake_FAQ
> >>>>
> >>>> Kitware offers various services to support the CMake community. For
> >>>> more
> >>>> information on each offering, please visit:
> >>>>
> >>>> CMake Support: http://cmake.org/cmake/help/support.html
> >>>> CMake Consulting: http://cmake.org/cmake/help/consulting.html
> >>>> CMake Training Courses: http://cmake.org/cmake/help/training.html
> >>>>
> >>>> Visit other Kitware open-source projects at
> >>>> http://www.kitware.com/opensource/opensource.html
> >>>>
> >>>> Follow this link to subscribe/unsubscribe:
> >>>> http://public.kitware.com/mailman/listinfo/cmake
> >>>>
> >>>
> >>>
> >>
> >
> > --
> >
> > Powered by www.kitware.com
> >
> > Please keep messages on-topic and check the CMake FAQ at:
> > http://www.cmake.org/Wiki/CMake_FAQ
> >
> > Kitware offers various services to support the CMake community. For more
> > information on each offering, please visit:
> >
> > CMake Support: http://cmake.org/cmake/help/support.html
> > CMake Consulting: http://cmake.org/cmake/help/consulting.html
> > CMake Training Courses: http://cmake.org/cmake/help/training.html
> >
> > Visit other Kitware open-source projects at
> > http://www.kitware.com/opensource/opensource.html
> >
> > Follow this link to subscribe/unsubscribe:
> > http://public.kitware.com/mailman/listinfo/cmake
>
>
>
>
>
> --
> View this message in context:
> http://cmake.3232098.n2.nabble.com/CMake-question-of-the-time-when-the-command-will-happen-in-add-custom-command-tp7593314p7593320.html
> Sent from the CMake mailing list archive at Nabble.com.
> --
>
> Powered by www.kitware.com
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Kitware offers various services to support the CMake community. For more
> information on each offering, please visit:
>
> CMake Support: http://cmake.org/cmake/help/support.html
> CMake Consulting: http://cmake.org/cmake/help/consulting.html
> CMake Training Courses: http://cmake.org/cmake/help/training.html
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/cmake
>
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake

Reply via email to