3

Is it possible to export all variables values that were set in CMake-GUI to single command line string so it can be used from external tools quickly?

So the output would be something like:

cmake -DVar1=ON -DVar2="foo" ...
Humam Helfawi
  • 19,566
  • 15
  • 85
  • 160

2 Answers2

4

You can get them from

Tools->"Show My Changes"
MikeMB
  • 20,029
  • 9
  • 57
  • 102
  • Thanks! But it only works if the changes has been done during the current session. It can not export the already edited options – Humam Helfawi Feb 27 '18 at 13:29
  • @HumamHelfawi: For me it shows all changes. Have you tried "File->Reload Cache"? – MikeMB Feb 27 '18 at 17:46
  • @HumamHelfawi: Btw.: I had essentially the same question [for ccmake](https://stackoverflow.com/questions/48997572/print-changes-made-via-ccmake) if you find another method that also works for ccmake I'd be grateful if you could inform me. – MikeMB Feb 27 '18 at 17:48
  • it did not.. BTW I am on MS Windows.. I will of course – Humam Helfawi Feb 27 '18 at 17:57
0

There is no cmake-gui integrated way to export or document the changed variables over several configure/generate runs.

But each change to a cached variable runs the configure step again and so I came up with the following code you can add to your main CMakeLists.txt to persist the original variables and diff against any future list of variables:

if (EXISTS "${CMAKE_BINARY_DIR}/CMakeCache.txt")
    file(
        STRINGS 
        "${CMAKE_BINARY_DIR}/CMakeCache.txt"
        _vars
        REGEX "^[^#/]"
    )
    if (NOT EXISTS "${CMAKE_BINARY_DIR}/CMakeCacheVars.txt")
        file(
            WRITE "${CMAKE_BINARY_DIR}/CMakeCacheVars.txt"
            "${_vars}"
        )
    else()
        file(
            READ "${CMAKE_BINARY_DIR}/CMakeCacheVars.txt"
            _vars_ori
        )
        list(REMOVE_ITEM _vars ${_vars_ori})
        message("Changed values: ${_vars}")
    endif()
endif()
Florian
  • 39,996
  • 9
  • 133
  • 149