[CMake] help with cmake_parse_arguments

Eric Clark eclark at ara.com
Fri Oct 19 16:19:33 EDT 2012


Anytime John! I ran into the same problem as you when I tried to figure out a way to parse the arguments to my functions and/or macros. Because I couldn't find the right documentation, I just went ahead and opened up the module file itself (YourCMakeInstallPath/share/cmake-2.8/Modules/CMakeParseArguments.cmake). I have found from a lot of banging my head against the wall that sometimes it is just easier to look at the code itself. Typically, the module developers do an excellent job of documenting the commands within the comments header of the file, and I have found that to be the easiest way to find exactly what I need to explain how to use it. Just as an example, here is the section in the CMakeParseArguments.cmake file that explains what I explained to you:

# As an example here a my_install() macro, which takes similar arguments as the
# real install() command:
#
#   function(MY_INSTALL)
#     set(options OPTIONAL FAST)
#     set(oneValueArgs DESTINATION RENAME)
#     set(multiValueArgs TARGETS CONFIGURATIONS)
#     cmake_parse_arguments(MY_INSTALL "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )
#     ...

Do you happen to know what docs you were looking at? It may be worth a little bit to post that to this mailing list so that hopefully the person that wrote those docs could be so kind as to update them with the correct syntax.

Take Care!
Eric

From: Biddiscombe, John A. [mailto:biddisco at cscs.ch]
Sent: Friday, October 19, 2012 2:35 PM
To: Eric Clark
Cc: CMake Mailing List (cmake at cmake.org)
Subject: RE: help with cmake_parse_arguments

Eric

Thanks for pointing that out, the help docs I was looking at didn't mention <multi_value_keywords>, with that added it works as expected.

Cheers

JB




From: Eric Clark [mailto:eclark at ara.com]
Sent: 19 October 2012 19:17
To: Biddiscombe, John A.
Cc: CMake Mailing List (cmake at cmake.org<mailto:cmake at cmake.org>)
Subject: RE: help with cmake_parse_arguments

John,

The cmake_parse_arguments command takes 5 arguments, not 4. My guess is that you just need to get the arguments right and things should then work for you assuming the rest of your code is correct. If you look in CMakeParseArguments.cmake you should see the documentation for the command, but I can tell you that the command takes the following arguments:

cmake_parse_arguments(prefix options singleValueArgs multiValueArgs ${ARGN})

The prefix is what is added to the beginning of each variable that is set, the options is a list of parameters that do not have any arguments associated with them (i.e. REQUIRED, NO_DEFAULT_PATH, etc.), the singleValueArgs is a list of all parameters that have only one argument associated with them, the mutliValueArgs is a list of all parameters that have one or more arguments associated with them, and the last parameter should always be ${ARGN}.

Hope this helps...
Eric

From: cmake-bounces at cmake.org<mailto:cmake-bounces at cmake.org> [mailto:cmake-bounces at cmake.org] On Behalf Of Biddiscombe, John A.
Sent: Friday, October 19, 2012 11:32 AM
To: cmake at cmake.org<mailto:cmake at cmake.org>
Subject: [CMake] help with cmake_parse_arguments

I don't understand why this stripped down test gives the wrong results. Can anyone point out what I've done wrong. I'm using cmake 2.8.9

Thanks

JB

=== TEST cmake ===

include (CMakeParseArguments)

MACRO(ADD_TEXT_TEST)
  CMAKE_PARSE_ARGUMENTS(
    TEST ""
       "NAME;COMMAND;ARGSLIST;BASELINE"
       ${ARGN}
  )
  message("TEST_DEFAULT_ARGS is ${TEST_DEFAULT_ARGS} from ${ARGN}")
  message("TEST_NAME is ${TEST_NAME}")
  message("TEST_COMMAND is ${TEST_COMMAND}")
  message("TEST_ARGSLIST is ${TEST_ARGSLIST}")
  message("TEST_BASELINE is ${TEST_BASELINE}")
ENDMACRO(ADD_TEXT_TEST)

set (datafile "Test1.xxx")

  ADD_TEXT_TEST(
    NAME
      testiso_${datafile}
    COMMAND
      "RunMe"
    ARGSLIST
      3.5555 nodal "${EAVL_SOURCE_DIR}/data/${datafile}"
    BASELINE
      "${CMAKE_CURRENT_SOURCE_DIR}/baseline/testiso/${datafile}.out"
  )


=== output ===

Gives output as follows - the name is missing and the arglist is truncated ...

TEST_DEFAULT_ARGS is from NAME;testiso_Test1.xxx;COMMAND;RunMe;ARGSLIST;3.5555;nodal;D:/Code/EAVL/data/Test1.xxx;BASELINE;D:/Code/EAVL/test/baseline/testiso/Test1.xxx.out
TEST_NAME is
TEST_COMMAND is RunMe
TEST_ARGSLIST is 3.5555
TEST_BASELINE is D:/Code/EAVL/test/baseline/testiso/Test1.xxx.out



--
John Biddiscombe,                        email:biddisco @.at.@ cscs.ch
http://www.cscs.ch/
CSCS, Swiss National Supercomputing Centre  | Tel:  +41 (91) 610.82.07
Via Trevano 131, 6900 Lugano, Switzerland   | Fax:  +41 (91) 610.82.82

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20121019/1af5f945/attachment-0001.htm>


More information about the CMake mailing list