Humam Helfawi
Humam Helfawi

Reputation: 20304

export CMake variables from GUI to command line

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" ...

Upvotes: 3

Views: 878

Answers (2)

Florian
Florian

Reputation: 43030

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()

Upvotes: 0

MikeMB
MikeMB

Reputation: 21166

You can get them from

Tools->"Show My Changes"

Upvotes: 4

Related Questions