less than 1 minute read

CMake lets users write scripts in “Script Mode” that can do various tasks. I originally tried doing:

> cmake -P somescript.cmake -DSOME_VAR=some_value

However the SOME_VAR was never set. That’s because in Script Mode the variables have to come before the script:

> cmake -DSOME_VAR=some_value -P somescript.cmake

This may seem obvious, but when using CMake to generate, config and even build, this is not the case. For example something like the following is perfectly valid:

> cmake .. -DSOME_VAR=some_value

or

> cmake --build . -DSOME_VAR=some_value

Tags:

Categories:

Updated: