export CMake variables from GUI to command line

北慕城南 提交于 2019-12-23 19:23:50

问题


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

回答1:


You can get them from

Tools->"Show My Changes"



回答2:


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


来源:https://stackoverflow.com/questions/48993866/export-cmake-variables-from-gui-to-command-line

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!