[CMake] A function and its arguments

Kristian kristianonline28 at gmail.com
Sun Feb 28 15:57:51 EST 2016


Hey,

I have a question. I have read the article about functions:
https://cmake.org/cmake/help/v3.0/command/function.html

I tried to write myself a very simple function (nothing special)

************************************

function(test_me add1 add2)
        message("test_me")
        message(" -> " ${add1})
        message(" -> " ${add2})
        message(" -> Number of arguments: " ${ARGC})
        message(" -> All arguments: " ${ARGV})
        message(" -> 0. argument: " ${ARGV0})
        message(" -> 1. argument: " ${ARGV1})
        message(" -> 2. argument: " ${ARGV2})
        message(" -> Unexpected arguments: " ${ARGN})
endfunction(test_me)

************************************

But when calling the function with

************************************
test_me("1" "2" "3")
************************************

or

************************************
test_me(1 2 3)
************************************

Then I get this output:

************************************
test_me
 -> 1
 -> 2
 -> Number of arguments: 3
 -> All arguments: 123
 -> 0. argument: 1
 -> 1. argument: 2
 -> 2. argument: 3
 -> Unexpected arguments: 3

************************************

I would expect, that the line "All arguments" would look like "All
arguments: 1 2 3", and not "All arguments: 123".

What is the thought behind this behaviour?


More information about the CMake mailing list