Optional Argument in cmake macro

cmake

Solution

CMake does not (AFAIK) check the number of variables passed to a macro, so you can just go ahead and declare it as any other macro.

There is also a variable `${ARGN}` which expands to a list of all the "remaining" variables passed to a macro, which may be useful.

Update As stated in Sam's comment, CMake now fails unless all expected (named) arguments are given when calling a macro or function.

Problem

I want to create a macro whose argument is optional. If not specified, the argument's value should be an empty string. How can I do this?

Original source