1
votes

Using CMake I try to expand environment variable values in custom file. I do the following

configure_file(config.cnf.in config.cnf)

I do not use @ONLY attribute.

config.cnf.in content:

[options]
some_value1 = @VAR_FROM_CMAKE@   // ok
some_value2 = ${SYSTEM_ENV_VAR}  // empty result
some_value2 = ${VAR_FROM_CMAKE}  // ok -- from CMake?!

@VAR_FROM_CMAKE@ is expanded successfully, but ${SYSTEM_ENV_VAR} is not - empty value.

I confused - @VAR@ and ${VAR} - are leading only to the CMAKE variables, but not to system env?

So my question is: Is it possible to expand system env variables in the custom file using CMake?

1

1 Answers

3
votes

You are not evaluating the system variable correctly: the correct command is $ENV{SYSTEM_ENV_VAR} (have a look here: https://cmake.org/cmake/help/latest/variable/ENV.html)

[options]
some_value1 = @VAR_FROM_CMAKE@
some_value2 = $ENV{SYSTEM_ENV_VAR}
some_value2 = ${VAR_FROM_CMAKE}