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

1

10

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?

Sped answered 13/2, 2020 at 22:31 Comment(6)
What is wrong in adding -D options in CMake options field?Winegar
@Tsyvarev: I suppose that could work, if I force a re-configuration.Sped
CLion will reconfigure project automatically as soon you change any of cmake related optionsSd
I am also very interested in this. Very frustrating that I have to change CMakeLists.txt to enable one or other option. Even worse: you have to additionally "reset cache and reload project" every time you set option ON/OFF.Jasper
@a_girl: See my answer.Sped
@Sped It appears you are the originator of the [cmakelists-options] tag. A meta has been opened to burninate the tag. You might want to weigh in if you want to keep itHighpowered
S
9

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.

Sped answered 19/5, 2020 at 22:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.