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

2016-04-19 Thread Clark Wang
On Tue, Apr 19, 2016 at 4:55 PM, Chaos Zhang <zcsd2...@gmail.com> wrote:

> 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"?
>

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:

  PRE_BUILD − run before all other dependencies
  PRE_LINK − run after other dependencies
  POST_BUILD − run after the target has been built

So PRE_BUILD comes first and then PRE_LINK and at last POST_BUILD.

-clark

>
> Thanks for you reply,
> Chaos Zhang
> ​
>
> 2016-04-19 15:50 GMT+08:00 Craig Scott-3 [via CMake] <[hidden email]
> <http:///user/SendEmail.jtp?type=node=7593283=0>>:
>
>> 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=7593281=0>> wrote:
>>
>> On Tue, Apr 19, 2016 at 1:15 PM, Chaos Zhang <[hidden email]
>>> <http:///user/SendEmail.jtp?type=node=7593281=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
>> Melbou

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

2016-04-19 Thread Chaos Zhang
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+s3232098n7593281...@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=7593281=0>> wrote:
>
> On Tue, Apr 19, 2016 at 1:15 PM, Chaos Zhang <[hidden email]
>> <http:///user/SendEmail.jtp?type=node=7593281=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

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

2016-04-19 Thread Craig Scott
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  wrote:

> On Tue, Apr 19, 2016 at 1:15 PM, Chaos Zhang  wrote:
>
>> Hi,
>>
>> Is there a way to use Linux command 'if' like this :
>> 
>> 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

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

2016-04-19 Thread Clark Wang
On Tue, Apr 19, 2016 at 1:15 PM, Chaos Zhang  wrote:

> Hi,
>
> Is there a way to use Linux command 'if' like this :
> 
> 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

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

2016-04-18 Thread Chaos Zhang
Hi, 

Is there a way to use Linux command 'if' like this : 
 
For i need to execute 'if condition' in make phase rather than cmake phase. 

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