Using CMake I'm trying to expand system environment variable values in custom file. I do the following command:
configure_file(config.cnf.in config.cnf)
config.cnf.in content:
[options]
some_value1 = $ENV{SYSTEM_ENV_VAR}
The question is: Is it possible to set the default value for SYSTEM_ENV_VAR variable, if it is not defined?
I tried to do this:
some_value1 = $ENV{SYSTEM_ENV_VAR:-defaultValue}
and got an cmake error: Invalid character (':') in a variable name: 'SYSTEM_ENV_VAR'
I didn't find the answer in the docs: https://cmake.org/cmake/help/v3.2/command/configure_file.html
You cannot set a default value for the variable, but you can store the environment variable inside a normal cmake variable, and if it was not set define a default value. I tested this:
My output for this is