How to use shell environment variables in CMake

Many developer SDKs and libraries set their own environment variables. For example, installing OpenNI2 sets OPENNI2_INCLUDE to the path containing its header files. It would be convenient to use these shell environment variables directly in CMake without having to create another CMake variable for it.

This can be done in CMake easily. For example to set the above environment variable as an include directory:


Tried with: CMake and Ubuntu 14.04

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.