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

Re: [CMake] set(a b); set(b c); if(a STREQUAL b OR a STREQUAL c) ...

2014-09-04 Thread Clark Wang
On Thu, Sep 4, 2014 at 1:44 PM, Clark Wang dearv...@gmail.com wrote:

 On Thu, Sep 4, 2014 at 1:36 PM, Chuck Atkins chuck.atk...@kitware.com
 wrote:

 Hi Clark

 The expression inside the if statement has it's variables dereferenced
 before evaluating and the non-variables are treated as constant
 expressions.  In this case, a resolves to b, b resolves to c, and c is
 not a variable so it's treated as the constant expression c.  Thus


 if(a STREQUAL b OR a STREQUAL c)

 gets evaluated as

 if( (b STREQUAL c) OR (b STREQUAL c) )


 Thanks a lot. It's clear now. But is there a way to check if the value of
 the variable a equals to b or c?


Found
http://stackoverflow.com/questions/19982340/cmake-compare-to-empty-string-with-strequal-failed
which suggests to use if(a MATCHES ^b$).

-clark


 -clark


 which is clearly false.  Hope that helps.

  - Chuck



-- 

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] set(a b); set(b c); if(a STREQUAL b OR a STREQUAL c) ...

2014-09-03 Thread Clark Wang
Hi,

I don't understand why the following code would not print true (tested
with cmake-3.0):

  set(a b)
  set(b c)
  if(a STREQUAL b OR a STREQUAL c)
message(true)
  endif()

From my understanding, no matter how magic the if command interprets its
arguments, one of the expressions (a STREQUAL b) and (a STREQUAL c) must be
true but I'm wrong. Anyone has a reasonable explanation?

Thanks.

-clark
-- 

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] set(a b); set(b c); if(a STREQUAL b OR a STREQUAL c) ...

2014-09-03 Thread Clark Wang
On Thu, Sep 4, 2014 at 1:36 PM, Chuck Atkins chuck.atk...@kitware.com
wrote:

 Hi Clark

 The expression inside the if statement has it's variables dereferenced
 before evaluating and the non-variables are treated as constant
 expressions.  In this case, a resolves to b, b resolves to c, and c is
 not a variable so it's treated as the constant expression c.  Thus


 if(a STREQUAL b OR a STREQUAL c)

 gets evaluated as

 if( (b STREQUAL c) OR (b STREQUAL c) )


Thanks a lot. It's clear now. But is there a way to check if the value of
the variable a equals to b or c?

-clark


 which is clearly false.  Hope that helps.

  - Chuck


-- 

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] Write CMakeLists in another programming language?

2014-04-03 Thread Clark Wang
I've been using cmake for some time but still I'm confused about the
syntax. Following are 2 examples from me:

 - http://www.cmake.org/pipermail/cmake/2013-September/055924.html
 - http://www.cmake.org/pipermail/cmake/2013-October/056036.html

Someone ever told me cmake 3.0 may do some language cleanup work to address
this kind of problems but it did not happen. So my idea is can we use
another programming language syntax to write the CMakeLists file. (For
example, we can write CMakeLists in Tcl which is clean and simple.)

I'm not a language expert. Just want to get some feedback from others.

-clark
-- 

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://www.cmake.org/mailman/listinfo/cmake

Re: [CMake] How to write a correct wrapper of MESSAGE()?

2014-03-05 Thread Clark Wang
On Mon, Oct 21, 2013 at 6:06 PM, Johannes Zarl johannes.z...@jku.at wrote:

 On Thursday, 17. October 2013, 07:12:51, Clark WANG wrote:
  When I'm using CMake more and more I find it's not a real serious
  language. It's so tricky.

 I can see why you are frustrated. I don't think it's all bad though.
 Hopefully
 CMake3 will be used for some language cleanups at the expense of breaking
 some
 backwards-compatibility...


The 3.0 (now rc1) release
noteshttp://www.cmake.org/cmake/help/v3.0/release/3.0.0.htmldid not
mention about these kinds of things. :(


   Johannes
 --

 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://www.cmake.org/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://www.cmake.org/mailman/listinfo/cmake

Re: [CMake] How to write a correct wrapper of MESSAGE()?

2013-10-16 Thread Clark WANG
On Tue, Oct 15, 2013 at 8:12 PM, Johannes Zarl johannes.z...@jku.at wrote:

 On Monday, 14. October 2013, 19:07:06, Matthew Woehlke wrote:
   The IN LISTS signature of foreach seems to do additional list
   splitting, leading to (foo;bar baz) appearing as 3 elements.
   Accessing the ARGV array by the positional indices (e.g. ${ARGV0})
   prevents the splitting.
 
  Really? That... is surprising. I thought the whole point of 'IN LISTS'
  was to take a variable that already contains a list and NOT do
  additional splitting (the way 'foreach(NAME ${LIST})' would)...

 While the behaviour here is hardly what one would expect, the list is not
 really split.

 What happens, is the following:
  1) Function info gets two parameters: foo;bar and baz
  2) The ARGV list is created by adding the parameters to the list:
 set(ARGV)
 list(ADD ARGV foo;bar) # here the foo;bar list is flattened
 list(ADD ARGV baz)
  Since a list cannot contain another list, we get a flattened
 representation
  of  the arguments: ARGV == foo;bar;baz
  3) foreach(name IN LISTS ARGV) only gets to see the flattened
 representation
  contained in ARGV.


When I'm using CMake more and more I find it's not a real serious
language. It's so tricky.


   Johannes
 --

 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://www.cmake.org/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://www.cmake.org/mailman/listinfo/cmake

Re: [CMake] ARGC != list(LENGTH ARGV) and ARGV0 != list(GET ARGV 0)

2013-10-11 Thread Clark WANG
On Fri, Oct 11, 2013 at 2:20 PM, Rolf Eike Beer e...@sf-mail.de wrote:

 Am Freitag, 11. Oktober 2013, 12:07:58 schrieb Clark WANG:
  See following example:
 
  $ cmake --version
  cmake version 2.8.11.2
  $ cat CMakeLists.txt
  cmake_minimum_required(VERSION 2.8)
 
  FUNCTION(foo)
  list(LENGTH ARGV argc)
  message(ARGC=${ARGC} list(LENGTH ARGV)=${argc})
 
  list(GET ARGV 0 argv0)
  message(ARGV0=${ARGV0} list(GET ARGV 0)=${argv0})
  ENDFUNCTION()
 
  foo(a;b;c)
  $ cmake .
  ARGC=1 list(LENGTH ARGV)=3
  ARGV0=a;b;c list(GET ARGV 0)=a
  -- Configuring done
  -- Generating done
  -- Build files have been written to: /root/tmp
  $
 
  I know ';' is special in cmake but it's counter-intuitive that ARGC !=
  list(LENGTH ARGV). Is this a bug?

 CMake will not expand a string into a list when passed as arguments.


Yes I know this. But after the literal string is passed to the function, it
is broken into a list (ARGV). And the ARGC value is not consistent with the
length of of ARGV which I've never seen in other languages. And this
behavior makes it difficult to pass parameters around between cmake
functions.


 It would
 do when using a variable:

 set(foovar a;b;c)
 foo(${foovar})

 ARGC=3 list(LENGTH ARGV)=3
 ARGV0=a list(GET ARGV 0)=a

 Eike
 --

 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://www.cmake.org/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://www.cmake.org/mailman/listinfo/cmake

Re: [CMake] ARGC != list(LENGTH ARGV) and ARGV0 != list(GET ARGV 0)

2013-10-11 Thread Clark WANG
On Fri, Oct 11, 2013 at 2:20 PM, Rolf Eike Beer e...@sf-mail.de wrote:

 Am Freitag, 11. Oktober 2013, 12:07:58 schrieb Clark WANG:
  See following example:
 
  $ cmake --version
  cmake version 2.8.11.2
  $ cat CMakeLists.txt
  cmake_minimum_required(VERSION 2.8)
 
  FUNCTION(foo)
  list(LENGTH ARGV argc)
  message(ARGC=${ARGC} list(LENGTH ARGV)=${argc})
 
  list(GET ARGV 0 argv0)
  message(ARGV0=${ARGV0} list(GET ARGV 0)=${argv0})
  ENDFUNCTION()
 
  foo(a;b;c)
  $ cmake .
  ARGC=1 list(LENGTH ARGV)=3
  ARGV0=a;b;c list(GET ARGV 0)=a
  -- Configuring done
  -- Generating done
  -- Build files have been written to: /root/tmp
  $
 
  I know ';' is special in cmake but it's counter-intuitive that ARGC !=
  list(LENGTH ARGV). Is this a bug?

 CMake will not expand a string into a list when passed as arguments. It
 would
 do when using a variable:

 set(foovar a;b;c)
 foo(${foovar})


It's not quite about using a variable or not. For your example,
foo(${foovar}) would give the same result as mine.


 ARGC=3 list(LENGTH ARGV)=3
 ARGV0=a list(GET ARGV 0)=a

 Eike
 --

 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://www.cmake.org/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://www.cmake.org/mailman/listinfo/cmake

[CMake] ARGC != list(LENGTH ARGV) and ARGV0 != list(GET ARGV 0)

2013-10-10 Thread Clark WANG
See following example:

$ cmake --version
cmake version 2.8.11.2
$ cat CMakeLists.txt
cmake_minimum_required(VERSION 2.8)

FUNCTION(foo)
list(LENGTH ARGV argc)
message(ARGC=${ARGC} list(LENGTH ARGV)=${argc})

list(GET ARGV 0 argv0)
message(ARGV0=${ARGV0} list(GET ARGV 0)=${argv0})
ENDFUNCTION()

foo(a;b;c)
$ cmake .
ARGC=1 list(LENGTH ARGV)=3
ARGV0=a;b;c list(GET ARGV 0)=a
-- Configuring done
-- Generating done
-- Build files have been written to: /root/tmp
$

I know ';' is special in cmake but it's counter-intuitive that ARGC !=
list(LENGTH ARGV). Is this a bug?

-Clark
--

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://www.cmake.org/mailman/listinfo/cmake

Re: [CMake] How to write a correct wrapper of MESSAGE()?

2013-10-09 Thread Clark WANG
On Wed, Oct 9, 2013 at 7:44 PM, Johannes Zarl johannes.z...@jku.at wrote:

 I guess you search for something like this:

 function(info)
 set(msg)
 foreach(i RANGE ${ARGC})
 set(msg ${msg}${ARGV${i}})
 endforeach()
 message(STATUS [info] ${msg})
 endfunction()

 message(Foo:bar;baz space FOO)
 info(Foo:bar;baz space FOO)
 message(two words)
 info(two words)

 ...which yields the following output:

 Foo:bar;baz spaceFOO
 -- [info] Foo:bar;baz spaceFOO
 twowords
 -- [info] twowords

 The IN LISTS signature of foreach seems to do additional list splitting,
 leading to (foo;bar baz) appearing as 3 elements. Accessing the ARGV
 array
 by the positional indices (e.g. ${ARGV0}) prevents the splitting.


This works. Thank you so much.


 HTH,
   Johannes

 On Wednesday, 9. October 2013, 05:33:26, Clark WANG wrote:
  On Sat, Oct 5, 2013 at 1:38 AM, Matthew Woehlke
  matthew.woeh...@kitware.com
 
   wrote:
  
   On 2013-09-27 04:18, Clark WANG wrote:
   I'm trying to write some MESSAGE() wrappers like info(), warning(),
   fatal(), etc which may be a bit easier to use. But I failed to
 simulate
   the
   correct MESSAGE() behavior no matter I use MACRO or FUNCTION. For
   example: [snip]
  
   FUNCTION vs MACRO shouldn't make a difference in argument parsing
 AFAIK.
   The difference is primarily that FUNCTION creates a scope, while MACRO
   operates in the scope from which it is called.
  
   The behavior of MESSAGE seems to concatenate multiple arguments with no
   separators. So maybe you could do something like:
  
   set(msg )
   foreach(part IN LISTS ARGN)
  
 set(msg ${msg}{$part})
  
   endforeach()
   # ...do stuff with ${msg}
 
  This does not work either. For example:
 
  $ cat CMakeLists.txt
  cmake_minimum_required(VERSION 2.8)
 
  FUNCTION(info_f)
  set(msg )
  foreach(part IN LISTS ARGN)
set(msg ${msg}${part})
endforeach()
  message([info_f] ${msg})
  ENDFUNCTION()
 
  MACRO(info_m)
  set(msg )
  foreach(part IN LISTS ARGN)
set(msg ${msg}${part})
endforeach()
  message([info_m] ${msg})
  ENDMACRO()
 
  message(foo;bar)
  info_f(foo;bar)
  info_m(foo;bar)
  $ cmake .
  foo;bar
  [info_f] foobar
  [info_m]
  $
 
   (I like ARGN since it is 'unnamed positional arguments'. Since you have
   no named arguments, ARGV == ARGN, but generally speaking I can't think
   of why you'd ever need to use ARGV.)
 
  Good point.
 
   --
   Matthew
  
   --
  
   Powered by www.kitware.com
  
   Please keep messages on-topic and check the CMake FAQ at:
   http://www.cmake.org/Wiki/**CMake_FAQ
 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
 http://cmake.org/cmake/help/s
   upport.html CMake Consulting:
   http://cmake.org/cmake/help/**consulting.html
 http://cmake.org/cmake/hel
   p/consulting.html CMake Training Courses:
   http://cmake.org/cmake/help/**training.html
 http://cmake.org/cmake/help/
   training.html
  
   Visit other Kitware open-source projects at http://www.kitware.com/**
   opensource/opensource.html
 http://www.kitware.com/opensource/opensource.h
   tml
  
   Follow this link to subscribe/unsubscribe:
   http://www.cmake.org/mailman/**listinfo/cmake
 http://www.cmake.org/mailma
   n/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://www.cmake.org/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://www.cmake.org/mailman/listinfo/cmake

Re: [CMake] How to write a correct wrapper of MESSAGE()?

2013-10-08 Thread Clark WANG
On Sat, Oct 5, 2013 at 1:38 AM, Matthew Woehlke matthew.woeh...@kitware.com
 wrote:

 On 2013-09-27 04:18, Clark WANG wrote:

 I'm trying to write some MESSAGE() wrappers like info(), warning(),
 fatal(), etc which may be a bit easier to use. But I failed to simulate
 the
 correct MESSAGE() behavior no matter I use MACRO or FUNCTION. For example:
 [snip]


 FUNCTION vs MACRO shouldn't make a difference in argument parsing AFAIK.
 The difference is primarily that FUNCTION creates a scope, while MACRO
 operates in the scope from which it is called.

 The behavior of MESSAGE seems to concatenate multiple arguments with no
 separators. So maybe you could do something like:

 set(msg )
 foreach(part IN LISTS ARGN)
   set(msg ${msg}{$part})
 endforeach()
 # ...do stuff with ${msg}


This does not work either. For example:

$ cat CMakeLists.txt
cmake_minimum_required(VERSION 2.8)

FUNCTION(info_f)
set(msg )
foreach(part IN LISTS ARGN)
  set(msg ${msg}${part})
  endforeach()
message([info_f] ${msg})
ENDFUNCTION()

MACRO(info_m)
set(msg )
foreach(part IN LISTS ARGN)
  set(msg ${msg}${part})
  endforeach()
message([info_m] ${msg})
ENDMACRO()

message(foo;bar)
info_f(foo;bar)
info_m(foo;bar)
$ cmake .
foo;bar
[info_f] foobar
[info_m]
$


 (I like ARGN since it is 'unnamed positional arguments'. Since you have no
 named arguments, ARGV == ARGN, but generally speaking I can't think of why
 you'd ever need to use ARGV.)


Good point.


 --
 Matthew

 --

 Powered by www.kitware.com

 Please keep messages on-topic and check the CMake FAQ at:
 http://www.cmake.org/Wiki/**CMake_FAQhttp://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.htmlhttp://cmake.org/cmake/help/support.html
 CMake Consulting: 
 http://cmake.org/cmake/help/**consulting.htmlhttp://cmake.org/cmake/help/consulting.html
 CMake Training Courses: 
 http://cmake.org/cmake/help/**training.htmlhttp://cmake.org/cmake/help/training.html

 Visit other Kitware open-source projects at http://www.kitware.com/**
 opensource/opensource.htmlhttp://www.kitware.com/opensource/opensource.html

 Follow this link to subscribe/unsubscribe:
 http://www.cmake.org/mailman/**listinfo/cmakehttp://www.cmake.org/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://www.cmake.org/mailman/listinfo/cmake

[CMake] How to write a correct wrapper of MESSAGE()?

2013-09-27 Thread Clark WANG
I'm trying to write some MESSAGE() wrappers like info(), warning(),
fatal(), etc which may be a bit easier to use. But I failed to simulate the
correct MESSAGE() behavior no matter I use MACRO or FUNCTION. For example:

  MACRO(info_mac_1)
  message([MACRO 1]  ${ARGV})
  ENDMACRO()
  MACRO(info_mac_2)
  message([MACRO 2]  ${ARGV})
  ENDMACRO()
  FUNCTION(info_fun_1)
  message([FUNC 1]  ${ARGV})
  ENDFUNCTION()
  FUNCTION(info_fun_2)
  message([FUNC 2]  ${ARGV})
  ENDFUNCTION()

  message(foo;bar)
  info_mac_1(foo;bar)

  message(foo bar)
  info_mac_2(foo bar)

  message(foo;bar)
  info_fun_1(foo;bar)

  message(foo bar)
  info_fun_2(foo bar)

The output (tested with 2.8.8) would be like this:

  foo;bar
  [MACRO 1] foobar
  foobar
  [MACRO 2] foo;bar
  foo;bar
  [FUNC 1] foobar
  foobar
  [FUNC 2] foo;bar

As you can see all the 4 commands I defined did not work the same way as
MESSAGE(). So how should I define a correct wrapper on MESSAGE()?

Thanks.

-Clark
--

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://www.cmake.org/mailman/listinfo/cmake