Reputation: 77
How can I remove all variables defined by cmake -D
at once?
For example, I defined FOO
and BAR
using:
cmake -DFOO=foo -DBAR=bar
Errors occur when I run cmake -U* ../
,
CMake Error: File /Modules/CMakeSystem.cmake.in does not exist.
CMake Error at /usr/share/cmake-3.10/Modules/CMakeDetermineSystem.cmake:186 (configure_file):
configure_file Problem configuring file
Call Stack (most recent call first):
CMakeLists.txt:3 (project)
-D
option at once?Upvotes: 1
Views: 1020
Reputation: 18386
When using the cmake -D
command line option to define cache variables, they are placed in the CMakeCache.txt
file, along with all of the other CMake-defined cache variables. To list all of the cached variables, you can run cmake -LAH
. The variables prefixed with CMAKE_
are set and used internally by CMake. When you run:
cmake -U* ..
you remove all of the cached variables, including these crucial CMAKE_
variables. This leaves your CMake project build in a broken state. The documentation for the cmake -U
option even warns about this:
Use with care, you can make your
CMakeCache.txt
non-working.
There is no special method to remove only those cached variables manually defined by the user via the cmake -D
option. You have to remove them individually:
cmake -U FOO -U BAR ..
or, you can open the CMakeCache.txt
file, and manually delete them from the file.
Another alternative would be to simply delete the CMakeCache.txt
file altogether, which will run CMake on your project from scratch.
I recommend adding a common prefix to your -D
command line variables (such as MYVAR_
).
cmake -D MYVAR_FOO=foo -D MYVAR_BAR=bar ..
This way, they are neatly grouped when viewed in the CMake GUI, and you can safely delete all of them from the cache using a -U
globbing expression:
cmake -U MYVAR_* ..
Upvotes: 2