Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

How to use shell environment variables in CMake

📅 2015-Aug-05 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ cmake, environment variables ⬩ 📚 Archive

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

© 2023 Ashwin Nanjappa • All writing under CC BY-SA license • 🐘📧