Preserving build settings for CMake GUI

I’m using CMake GUI to build large projects like OpenCV. There is over 20 settings I have to change from defaults while experimenting with different build scenarios. What is the way to preserve these settings when I erase build directory and start from scratch?

Here is my build directory:

paul@desktop:~/opencv/build$ ls
3rdparty               CMakeVars.txt            doc                   OpenCVConfig-version.cmake  test-reports
a.out                  configured               downloads             opencv_data_config.hpp      text_config.hpp
apps                   CPackConfig.cmake        include               OpenCVDetectCudaArch.o      tmp
bin                    CPackSourceConfig.cmake  install_manifest.txt  OpenCVModules.cmake         unix-install
CMakeCache.txt         CTestTestfile.cmake      lib                   opencv_python_tests.cfg     version_string.tmp
CMakeDownloadLog.txt   custom_hal.hpp           Makefile              opencv_tests_config.hpp
CMakeFiles             cvconfig.h               modules               python_loader
cmake_install.cmake    cv_cpu_config.h          opencv2     
cmake_uninstall.cmake  data                     OpenCVConfig.cmake    share

Would keeping some of these files or directories preserve the settings? I tried with CMakeCache.txt and CMakeVars.txt, but it didn’t work.

I don’t see a way to provide a cache initialization file (the -C flag) in the GUI. However, there are cmake presets which may be able to help with this.


Yes, presets would be my go-to feature for this now. I use them for exactly this reason, among others.

+1. This is exactly what presets were designed for.