CLion
 
Get CLion
Join the CLion 2025.1 Early Access Program and try out new features before they are released! Find out more

CLion IDE macro for CMake

Last modified: 26 May 2024

In some cases, you may want a CMake script to detect whether it is being called from CLion or another instance like console. For this, use the special environment variable CLION_IDE. This variable is platform-independent and is only TRUE when CMake generation or build is invoked from CLion.

Using the CLION_IDE variable, you can set specific paths (for example, customize build directories), execute additional scripts, or add extra logging.

Placing this variable into your CMake code is easy with the environment variables completion available for CMakeLists.txt files:

code completion for environment variables in cmake files