How to retrieve a user environment variable in CMake (Windows)

Lars Bilke picture Lars Bilke · Mar 27, 2009 · Viewed 97.6k times · Source

I know how to retrieve a normal machine wide environment variable in CMAKE using

$ENV{EnvironmentVariableName}

but I can not retrieve a user specific environment variable. Is it possible and how?

Answer

Cameron Lowell Palmer picture Cameron Lowell Palmer · Oct 13, 2014

Getting variables into your CMake script

You can pass a variable on the line with the cmake invocation:

FOO=1 cmake

or by exporting a variable in BASH:

export FOO=1

Then you can pick it up in a cmake script using:

$ENV{FOO}