Search code examples
cmakeclionbuildconfigurationcmakelists-options

In CLion, how do you set CMakeLists.txt option values?


I'm trying to use CLion (latest version - 2019.3) to work on a source repository of mine, which already uses CMake (i.e. has a CMakeLists.txt). Now, the package has some options regarding which targets to build; by default it builds just a few, but if you set an option to ON, then a bunch of tests are compiled and built.

Unfortunately, I don't quite see where CLion lets you set CMake option values for the build subdirectories it generates. Is it really forcing the defaults on you, or am I missing something in the main UI or the preferences?


Solution

  • CLion 2022.2 and later

    CMake now supports setting (cached) option values:

    1. On the Menu, choose File | Settings...
    2. In the navigation tree, locate Build, Execution, Deployment | CMake
    3. In the Profiles pane, choose the CMake profile for which you want to edit options.
    4. You will see an expandable area entitled "Cache Variables".

    enter image description here

    CMake 2022.1 and earlier

    For now, there's no UI for setting option values. You'll need to edit your CMake profiles (on the menu: File | Settings | Build, Execution, Deployment | CMake) and manually add CMake command-line options, e.g. -DBUILD_TESTS:BOOL=ON.

    I've filed bug CPP-20268 about this fact.

    CLion developers are planning to allow this through a mechanism for editing all of the CMake cache - an approach which I disapprove of, but it'll be better than nothing I suppose. That is issue CPP-423.