[CMake] CMake: how to use 'if condition' in command add_custom_command(...)

Chaos Zhang zcsd2012 at gmail.com
Tue Apr 19 04:55:52 EDT 2016


I have read the description of PRE_BUILD before in CMake doc, but when i
use it, i found something confuesed.
(1) In CMakeLists.txt, the content as below:

​(2)After i make the makefile generated by this CMakeLists.txt, i get
result as below:
"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"?

Thanks for you reply,
Chaos Zhang
​

2016-04-19 15:50 GMT+08:00 Craig Scott-3 [via CMake] <
ml-node+s3232098n7593281h30 at n2.nabble.com>:

> 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.
>
> On Tue, Apr 19, 2016 at 5:24 PM, Clark Wang <[hidden email]
> <http:///user/SendEmail.jtp?type=node&node=7593281&i=0>> wrote:
>
> On Tue, Apr 19, 2016 at 1:15 PM, Chaos Zhang <[hidden email]
>> <http:///user/SendEmail.jtp?type=node&node=7593281&i=1>> wrote:
>>
>>> Hi,
>>>
>>> Is there a way to use Linux command 'if' like this :
>>> <http://cmake.3232098.n2.nabble.com/file/n7593278/2016-04-19_113005.png>
>>> For i need to execute 'if condition' in make phase rather than cmake
>>> phase.
>>>
>>
>> Try like this:
>>
>> % cat CMakeLists.txt
>> add_custom_target(foo ALL)
>> add_custom_command(TARGET foo
>>     PRE_BUILD
>>     COMMAND if [ -f bar ]\; then echo yes\; else echo no\; fi)
>> % cmake .
>> % make
>> no
>> Built target foo
>> % touch bar
>> % make
>> yes
>> Built target foo
>> %
>>
>>
>>> Thanks a lot
>>> Chaos Zhang
>>>
>>>
>>>
>>> --
>>> View this message in context:
>>> http://cmake.3232098.n2.nabble.com/CMake-how-to-use-if-condition-in-command-add-custom-command-tp7593278.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
>>
>
>
>
> --
> Craig Scott
> Melbourne, Australia
> http://crascit.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
>
> ------------------------------
> If you reply to this email, your message will be added to the discussion
> below:
>
> http://cmake.3232098.n2.nabble.com/CMake-how-to-use-if-condition-in-command-add-custom-command-tp7593278p7593281.html
> To unsubscribe from CMake: how to use 'if condition' in command
> add_custom_command(...), click here
> <http://cmake.3232098.n2.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=7593278&code=emNzZDIwMTJAZ21haWwuY29tfDc1OTMyNzh8MjA3OTI5NzIwMg==>
> .
> NAML
> <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>
>


1.png (9K) <http://cmake.3232098.n2.nabble.com/attachment/7593283/0/1.png>
2.png (5K) <http://cmake.3232098.n2.nabble.com/attachment/7593283/1/2.png>




--
View this message in context: http://cmake.3232098.n2.nabble.com/CMake-how-to-use-if-condition-in-command-add-custom-command-tp7593278p7593283.html
Sent from the CMake mailing list archive at Nabble.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20160419/90de0d4b/attachment.html>


More information about the CMake mailing list