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 <dearv...@gmail.com> wrote:

> On Tue, Apr 19, 2016 at 1:15 PM, Chaos Zhang <zcsd2...@gmail.com> 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

Reply via email to