2014-08-03 19:52:23 +02:00
|
|
|
ENV
|
|
|
|
---
|
|
|
|
|
2019-11-11 23:01:05 +01:00
|
|
|
Operator to read environment variables.
|
2014-08-03 19:52:23 +02:00
|
|
|
|
2018-10-28 12:09:07 +01:00
|
|
|
Use the syntax ``$ENV{VAR}`` to read environment variable ``VAR``.
|
|
|
|
|
2019-11-11 23:01:05 +01:00
|
|
|
To test whether an environment variable is defined, use the signature
|
|
|
|
``if(DEFINED ENV{<name>})`` of the :command:`if` command.
|
|
|
|
|
2023-12-07 09:12:54 +01:00
|
|
|
.. note::
|
|
|
|
|
|
|
|
Environment variable names containing special characters like parentheses
|
|
|
|
may need to be escaped. (Policy :policy:`CMP0053` must also be enabled.)
|
|
|
|
For example, to get the value of the Windows environment variable
|
|
|
|
``ProgramFiles(x86)``, use:
|
|
|
|
|
|
|
|
.. code-block:: cmake
|
|
|
|
|
|
|
|
set(ProgramFiles_x86 "$ENV{ProgramFiles\(x86\)}")
|
|
|
|
|
2022-08-04 22:12:04 +02:00
|
|
|
For general information on environment variables, see the
|
|
|
|
:ref:`Environment Variables <CMake Language Environment Variables>`
|
|
|
|
section in the :manual:`cmake-language(7)` manual.
|