Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Options for user-defined CMake functions

Tags:

cmake

function(print2Args arg1 arg2)
  message(STATUS ${arg1} " " ${arg2})
endfunction(print2Args)

Is it possible to update user defined function print2Args s.t. it will accept options like the built-in CMake function execute_process?

like image 956
Konstantin Burlachenko Avatar asked Mar 15 '26 12:03

Konstantin Burlachenko


1 Answers

CMake offers this via the CMakeParseArguments. You do not specify the arguments in the function signature as you did in your example.

CMake accepts more arguments then given in the function signature. You define options, one-valued arguments and pairs of arguments in variables and pass these to cmake_parse_arguments. This command sets several variables which you can use to check what arguments where set.

Documentation and an example: https://cmake.org/cmake/help/latest/module/CMakeParseArguments.html

like image 155
usr1234567 Avatar answered Mar 17 '26 02:03

usr1234567