Reputation: 24111
If I have a CMakeLists.txt file:
cmake_minimum_required(VERSION 2.8)
OPTION(FOO "Foo Option" OFF)
MESSAGE("FOO? " ${FOO})
And then I call cmake on it, I get the following output:
FOO? ON
Why is this? Haven't I specified the default for FOO is to be OFF?
Upvotes: 7
Views: 12085
Reputation: 382472
Instead of deleting our entire build directory as per https://stackoverflow.com/a/56119191/895245 you could also try to unset just one variable with:
cmake -U FOO
to ensure that it is not being cached to a non-default value.
Upvotes: 1
Reputation: 141
Delete CMakeCache.txt from build directory and reload project. This happens because CMake is caching global variables
Upvotes: 7
Reputation: 325
You may open up cmake gui.It can show you every each option value. The option value in build folder may different with default value.
Recheck your CMakeLists.txt file. Maybe somewhere you set value on it.
cmake_minimum_required(VERSION 2.8)
OPTION(FOO "Foo Option" OFF)
SET(FOO ON) # Don't do this
MESSAGE("FOO? " ${FOO})
Upvotes: 4
Reputation: 764
Try this:
SET(FOO OFF CACHE BOOL "Foo Option")
or
SET(FOO OFF CACHE BOOL "Foo Option" FORCE)
Upvotes: 4