<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Apr 19, 2016 at 4:55 PM, 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:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">I have read the description of PRE_BUILD before in CMake doc, but when i use it, i found something confuesed.<div>(1) In CMakeLists.txt, the content as below:<br><div><img src="http://cmake.3232098.n2.nabble.com/attachment/7593283/0/1.png" height="211" width="358"><br>​(2)After i make the makefile generated by this CMakeLists.txt, i get result as below:<br></div></div><div><img src="http://cmake.3232098.n2.nabble.com/attachment/7593283/1/2.png" height="125" width="414"></div><div>"3_pre_build" is behind "1_pre_link", if POST_BUILD gets treated as PRE_LINK, why "3_pre_build" was printed before "1_pre_link"?</div></div></blockquote><div><br></div><div>It's not the order of the "add_custom_command" commands in CMakeLists.txt which determines in which order they will be invoked. According to the doc:<br><br> 


<span style="font-size:10pt;color:rgb(0,0,0);font-style:normal;font-variant:normal">PRE_BUILD − run before all other dependencies<br></span>  <span style="font-size:10pt;color:rgb(0,0,0);font-style:normal;font-variant:normal">PRE_LINK − run after other dependencies<br><span style="font-size:10pt;color:rgb(0,0,0);font-style:normal;font-variant:normal">  POST_BUILD − run after the target has been built<br><br></span></span></div><div><span style="font-size:10pt;color:rgb(0,0,0);font-style:normal;font-variant:normal"><span style="font-size:10pt;color:rgb(0,0,0);font-style:normal;font-variant:normal">So PRE_BUILD comes first and then PRE_LINK and at last POST_BUILD.<br></span></span></div><div><span style="font-size:10pt;color:rgb(0,0,0);font-style:normal;font-variant:normal"><span style="font-size:10pt;color:rgb(0,0,0);font-style:normal;font-variant:normal"><br></span></span></div><div>-clark<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><br></div><div>Thanks for you reply,</div><div>Chaos Zhang</div><div>​<br></div></div><div class="gmail_extra"><br><div class="gmail_quote"><span>2016-04-19 15:50 GMT+08:00 Craig Scott-3 [via CMake] <span dir="ltr"><<a href="http:///user/SendEmail.jtp?type=node&node=7593283&i=0" rel="nofollow" link="external" target="_blank">[hidden email]</a>></span>:<br></span><blockquote style="border-left:2px solid rgb(204,204,204);padding:0px 1em" class="gmail_quote"><span><span>

        <div dir="ltr">In case it matters, in Clark's suggested code, note that PRE_BUILD is only fully honoured with Visual Studio generators. For everything else, it gets treated as PRE_LINK, which occurs later (i.e. after compiling all the sources rather than before). So it depends on what your "if" test is trying to do whether or not this matters in your case.</div></span></span><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Apr 19, 2016 at 5:24 PM, Clark Wang <span dir="ltr"><<a href="http:///user/SendEmail.jtp?type=node&node=7593281&i=0" rel="nofollow" link="external" target="_blank">[hidden email]</a>></span> wrote:<div><div><div><div><br><blockquote style="border-left:2px solid rgb(204,204,204);padding:0px 1em" class="gmail_quote"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Apr 19, 2016 at 1:15 PM, Chaos Zhang <span dir="ltr"><<a href="http:///user/SendEmail.jtp?type=node&node=7593281&i=1" rel="nofollow" link="external" target="_blank">[hidden email]</a>></span> wrote:<br><blockquote style="border-left:2px solid rgb(204,204,204);padding:0px 1em" class="gmail_quote">Hi,<br>
<br>
Is there a way to use Linux command 'if' like this :<br>
<<a href="http://cmake.3232098.n2.nabble.com/file/n7593278/2016-04-19_113005.png" rel="nofollow" link="external" target="_blank">http://cmake.3232098.n2.nabble.com/file/n7593278/2016-04-19_113005.png</a>><br>
For i need to execute 'if condition' in make phase rather than cmake phase.<br></blockquote><div><br></div><div>Try like this:<br><br>% cat CMakeLists.txt<br>add_custom_target(foo ALL)<br>add_custom_command(TARGET foo<br>    PRE_BUILD<br>    COMMAND if [ -f bar ]\; then echo yes\; else echo no\; fi)<br>% cmake .<br>% make<br>no<br>Built target foo<br>% touch bar<br>% make<br>yes<br>Built target foo<br>% <br><br></div><blockquote style="border-left:2px solid rgb(204,204,204);padding:0px 1em" class="gmail_quote">
<br>
Thanks a lot<br>
Chaos Zhang<br>
<br>
<br>
<br>
--<br>
View this message in context: <a href="http://cmake.3232098.n2.nabble.com/CMake-how-to-use-if-condition-in-command-add-custom-command-tp7593278.html" rel="nofollow" link="external" target="_blank">http://cmake.3232098.n2.nabble.com/CMake-how-to-use-if-condition-in-command-add-custom-command-tp7593278.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="nofollow" link="external" 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="nofollow" link="external" 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="nofollow" link="external" target="_blank">http://cmake.org/cmake/help/support.html</a><br>
CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" rel="nofollow" link="external" target="_blank">http://cmake.org/cmake/help/consulting.html</a><br>
CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html" rel="nofollow" link="external" 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="nofollow" link="external" 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="nofollow" link="external" target="_blank">http://public.kitware.com/mailman/listinfo/cmake</a><br>
</blockquote></div><br></div></div>
<br>--<br>
<br>
Powered by <a href="http://www.kitware.com" rel="nofollow" link="external" 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="nofollow" link="external" 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="nofollow" link="external" target="_blank">http://cmake.org/cmake/help/support.html</a><br>
CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" rel="nofollow" link="external" target="_blank">http://cmake.org/cmake/help/consulting.html</a><br>
CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html" rel="nofollow" link="external" 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="nofollow" link="external" 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="nofollow" link="external" target="_blank">http://public.kitware.com/mailman/listinfo/cmake</a><br></blockquote></div></div></div></div></div><div><div><br><br clear="all"><span><div><br></div>-- <br><div><div dir="ltr"><div><div dir="ltr">Craig Scott<br><div>Melbourne, Australia</div><div><a href="http://crascit.com" rel="nofollow" link="external" target="_blank">http://crascit.com</a><br></div></div></div></div></div>
</span></div></div></div><div><div><span>
<br>-- 
<br><br>Powered by <a href="http://www.kitware.com" rel="nofollow" link="external" 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="nofollow" link="external" 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="nofollow" link="external" target="_blank">http://cmake.org/cmake/help/support.html</a><br>CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" rel="nofollow" link="external" target="_blank">http://cmake.org/cmake/help/consulting.html</a><br>CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html" rel="nofollow" link="external" 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="nofollow" link="external" 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="nofollow" link="external" target="_blank">http://public.kitware.com/mailman/listinfo/cmake</a>

        
        
        
        <br>
        <br>
        </span></div></div><hr color="#cccccc" noshade size="1">
        <div style="color:rgb(68,68,68);font:12px tahoma,geneva,helvetica,arial,sans-serif"><span>
                <div style="font-weight:bold">If you reply to this email, your message will be added to the discussion below:</div>
                </span><a href="http://cmake.3232098.n2.nabble.com/CMake-how-to-use-if-condition-in-command-add-custom-command-tp7593278p7593281.html" rel="nofollow" link="external" target="_blank">http://cmake.3232098.n2.nabble.com/CMake-how-to-use-if-condition-in-command-add-custom-command-tp7593278p7593281.html</a>
        </div><div><div>
        <div style="color:rgb(102,102,102);font:11px/1.5em tahoma,geneva,helvetica,arial,sans-serif;margin-top:0.4em">
                
                To unsubscribe from CMake: how to use 'if condition' in command add_custom_command(...), <a rel="nofollow" link="external">click here</a>.<br>
                <a href="http://cmake.3232098.n2.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml" rel="nofollow" style="font:9px serif" link="external" target="_blank">NAML</a>
        </div></div></div></blockquote></div><br></div>


        
        
        
<br><hr align="left" width="300">
View this message in context: <a href="http://cmake.3232098.n2.nabble.com/CMake-how-to-use-if-condition-in-command-add-custom-command-tp7593278p7593283.html" target="_blank">Re: CMake: how to use 'if condition' in command add_custom_command(...)</a><div><div><br>
Sent from the <a href="http://cmake.3232098.n2.nabble.com/" target="_blank">CMake mailing list archive</a> at Nabble.com.<br></div></div><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></div>