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 <zcsd2...@gmail.com> 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