Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling a CMake function: number of arguments

Tags:

cmake

There is a function named myfunc defined as

function (myfunc var1 var2 var3)
...
endfunction()

Then, I see a function call

myfunc(custom hahaha platform ALL
        COMMAND echo "hello world"
        SOURCES ${some_var} )

My question is

The function myfunc takes 3 variables. In the above function call, which are the 3 variables? Also, how can there be additional commands COMMAND and SOURCES within the function call?

like image 517
kgf3JfUtW Avatar asked Sep 20 '25 05:09

kgf3JfUtW


1 Answers

3 variables will be the first 3 arguments.

If your function was defined as follows:

function (myfunc var1 var2 var3)
  message ("var1: ${var1}")
  message ("var2: ${var2}")
  message ("var3: ${var3}")
  message ("number of arguments sent to function: ${ARGC}")
  message ("all function arguments:               ${ARGV}")
  message ("all arguments beyond defined:         ${ARGN}") 
endfunction()

after calling it as you stated:

set (some_var "some var")
myfunc(custom hahaha platform ALL
        COMMAND echo "hello world"
        SOURCES ${some_var} )

the outuput will be:

var1: custom
var2: hahaha
var3: platform
number of arguments sent to function: 9
all function arguments:               custom;hahaha;platform;ALL;COMMAND;echo;hello world;SOURCES;some var
all arguments beyond defined:         ALL;COMMAND;echo;hello world;SOURCES;some var

so you have called your function with 9 arguments, that are referenced with ${ARGV}, all arguments that are not defined can also be referenced using variable ${ARGN}.

Note that when calling function, ALL, COMMAND, and SOURCES are just arguments to the function, nothing else.

In the end, here is the full documentation about cmake functions and arguments

like image 119
gordan.sikic Avatar answered Sep 22 '25 22:09

gordan.sikic