Changing the name of a variable in CMake

Here's a neat trick in CMake: you want to change the name of a variable, but worry that anyone you've distributed the code to already will lose the option they've selected.

Use the old variable as the default value for the new one:

option(OLD_VARIABLE "Some variable" ON) option(NEW_VARIABLE "Some variable" ${OLD_VARIABLE})

or...

set( OLD_STRING_VARIABLE "Old default" CACHE STRING "Help text" )

set( NEW_STRING_VARIABLE "${OLD_STRING_VARIABLE}" "Help text" )