I have a file /home/me/.config/Kitware/CMakeCache.txt
that contains some initial cache settings I'd like to use everywhere. I run cmake -C /home/me/.config/Kitware/CMakeCache.txt
and it gives me a parse error on line 3 with this file:
set(CMAKE_CXX_FLAGS "-march=native -mtune=native" CACHE STRING "Flags used by the compiler during all build types.")
set(CMAKE_CXX_FLAGS_DEBUG "-Og -ggdb" CACHE STRING "Flags used by the compiler during debug builds.")
This is the error I get:
CMake Error: Parse error in cache file /home/me/.config/Kitware/CMakeCache.txt on line 3. Offending entry: set(CMAKE_CXX_FLAGS_DEBUG "-Og -ggdb" CACHE STRING "Flags used by the compiler during debug builds.")
But, if I change the line (adding =
) to:
set(CMAKE_CXX_FLAGS_DEBUG "=-Og -ggdb" CACHE STRING "Flags used by the compiler during debug builds.")
it works fine, but then the resulting cache file in my project has the option set to =-Og -ggdb
. In fact, the =
sign can appear anywhere in the entire set
statement. But it results in different problems no matter where you put it.
If I rename the file to /home/me/.config/Kitware/default.cmake
(or anything else besides CMakeCache.txt
it also works fine and doesn't require an =
sign in the value for every option.
This is very weird behavior, and I don't understand it. What's going on here?
Turning my comments into an answer
See
cmake.cxx
: Anything in the command line that has the namecmakelists.txt
orcmakecache.txt
is taken as the path to those files.So CMake is ignoring your
-C
option here and tries to load yourCMakeCache.txt
as an actual variable cache file. And those files have a different formatting/syntax ofNAME:TYPE=VALUE
.You can consider this behavior a bug in CMake. Or you just avoid using
CMakeCache.txt
for your initial cache file name.