4

I have a library with a bunch of different configuration options. We usually configure the build with cmake-gui and ticking a few checkboxes.

I want to automate this into a .sh script using just cmake.

e.g.
In GUI -> selects a bunch of different options
equivalent cmake command -> cmake -D CMAKE_XXX=X -D CMAKE_XXY=XXY [a bunch of options here] ..

How can I find the "equivalent" cmake command-line command to any arbitrary configuration I choose from the GUI?

ButterDog
  • 5,115
  • 6
  • 43
  • 61
  • Do you consider your question answered? – Antonio Mar 13 '17 at 10:17
  • @Antonio Not really. The answers talk about how to invoke cmake with equivalent options but the question is a bit different. How to *export* a GUI set of options to it's equivalent command line options? Imagine you have a big project w/ lots of long-names hard-to-type options. Open CMAKE GUI, tick the boxes, then *somehow* copy the equivalent cmake command line invocation. It has to be possible since the GUI has to be backed by cmake cli. – ButterDog Mar 13 '17 at 16:44
  • 1
    Ah, ok! I believe the starting point should be a `diff` between the CMakeCache.txt generated without any manual configuration, and the CMakeCache.txt after the changes from cmake-gui – Antonio Mar 13 '17 at 17:08
  • Did you find a solution? – Royi Apr 13 '18 at 11:42

5 Answers5

4

The equivalent cmake command to cache a variable is explained here (-D option). Note that previous documentation was ambiguous, so take care of always checking the latest one.

Basically:

-D<var>:<type>=<value>

You have to specify also the type to have the variable cached in the same way as through your cmake-gui procedure. Note that variable definition is necessary only the first time: if not specified anymore, the cached value will be used.

Community
  • 1
  • 1
Antonio
  • 19,451
  • 13
  • 99
  • 197
  • @PeterK It will work, but with a different behaviour. Please check [this](http://stackoverflow.com/questions/30319646/ambiguous-documentation-for-how-to-define-a-cached-variable-in-cmake-from-comm). – Antonio May 20 '15 at 08:29
  • so, it will work as usual but will not be accessible in cmake-gui, and the point of this question is how to get rid of said gui =) – Peter K May 20 '15 at 11:25
  • This doesn't answer the question. What the OP asked is how could one get the `make` command which is equivalent to what one sees on CMake GUI. – Royi Apr 13 '18 at 11:31
  • @Royi True. As I mentioned in the comment of the questions, the starting point should be a diff between the CMakeCache.txt generated without any manual configuration, and the CMakeCache.txt after the changes from cmake-gui. Once you take a look at that, you can start thinking how to automatically process that. If you have trouble with that, you can post a new question after you have got this input data and you have more specific troubles in processing it. – Antonio Apr 13 '18 at 21:53
2

cmake-gui generates CMakeVars.txt and CMakeCache.txt files in the build directory once you click "Configure" button. They cache all variables you configured through the GUI.

Stone
  • 1,119
  • 9
  • 17
1

Had the same question ... and as you asked I looking up some of the options in the menu and found it. Menu Tools -> Show My Changes

Bringing up an Dialog with an edit field with content for command line options or cache file options.

yeah

p.s. I used cmake 3.11.1

JackGrinningCat
  • 480
  • 4
  • 9
0

just read file named like CMakeCache.txt (iirc) in the root of build directory and see variable names there

Peter K
  • 1,787
  • 13
  • 15
  • The options are there but you still need to put the command together though. Would need some scripting to assemble the equivalent command. – ButterDog May 19 '15 at 20:55
  • you'd better assemble the equivalent .cmake file - with SET'ing all the vars and handle that to your script. You can include that file from the top of your project's CMakeLists.txt and also do it conditionally if only it exists so no error would arise in non-scripted use-case – Peter K May 19 '15 at 22:18
  • @Xocoatzin There's no point in extracting values from CMakeCache.txt to pass them in the cmake command line: you will obtain exactly the same behaviour if you run cmake without arguments, as the existing cached values will be used. – Antonio May 20 '15 at 08:32
  • 1
    Antonio, yes, but the point is to learn those variable names from cache once, and then develop a script to be run many times (possibly from other scripts) to create and configure *new* build directories, that have no said cache yet – Peter K May 20 '15 at 11:22
  • @PeterK Possibly you are right, but let's see what OP says. – Antonio May 20 '15 at 11:49
  • You should not add a CMakeCache.txt file. The documentation states "The given file should be a CMake script containing SET commands that use the CACHE option, not a cache-format file." https://cmake.org/cmake/help/v3.3/manual/cmake.1.html – usr1234567 Jan 23 '16 at 15:01
  • A little late to the party, but I faced the same problem: extract build parameters from an existing cache to configure the build with a new tool chain. I extracted the relevant options (i.e. those not auto-detected) from the cache and used them to create the appropriate SET commands. I guess this could even automated with a simple script, if you wanted ... – Claas Jul 18 '19 at 08:12
-1

You can write a file containing all variables you want to set with set(<var_name> <value>) and pass this file to the CMake call via -C:

cmake -C <fileWithInitialValues> <pathToSrcDir>

Documentation:
https://cmake.org/cmake/help/v3.3/manual/cmake.1.html

This should would similar with cmake-gui and ccmake, but it is not a pure solution with the graphic interface.

usr1234567
  • 21,601
  • 16
  • 108
  • 128
  • This doesn't answer the question. What the OP asked is how could one get the make command which is equivalent to what one sees on CMake GUI. Namely how to export the command from CMake GUI to a text file (Or clipboard for that matter). – Royi Apr 13 '18 at 11:32