CMake Script Mode and Variables
Addy

Addy @zethon

About: Lifelong programmer. World traveler. Aspiring YouTuber * www.youtube.com/@AddyGoesLive * www.youtube.com/@AddyGoesPlaces * www.instagram.com/AddyGoesPlaces * www.x.com/AddyGoesPlaces

Location:
Washington DC area
Joined:
Nov 3, 2022

CMake Script Mode and Variables

Publish Date: Feb 8
0 0

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

or

> cmake --build . -DSOME_VAR=some_value
Enter fullscreen mode Exit fullscreen mode

Comments 0 total

    Add comment