3.20.0 sets TOOL variable by default
Hello!
GitHub Actions runners recently upgraded to CMake 3.20 on Windows, which broke our build. After some investigation, we found out that a variable we have set as an option
called TOOL
is set before our call to option
, leaving it to its default value (which seems empty?). For some reason, if we run CMake twice (with a cache), the TOOL
option is set correctly.
For now, I guess our workaround is to prefix all these variables with something unique like our project name, but this extends our command line length by quite a lot.
I can reproduce this with the following CMakeLists.txt on Windows with the VS2019 generator and MSVC:
cmake_minimum_required(VERSION 3.20.0)
project(foobar)
option(TOOL "This variable doesn't work" TRUE)
option(NOT_TOOL "This variable does work" TRUE)
file(GENERATE OUTPUT foo.cpp CONTENT "int main(){return 0;}")
if (TOOL)
add_library(lib foo.cpp)
endif()
if (NOT_TOOL)
add_library(not_lib foo.cpp)
endif()
add_executable(bin foo.cpp)
add_dependencies(bin lib not_lib)
This should fail to generate because lib
is not defined. Adding unset(TOOL)
in front of the option
call should let it build, though this defeats the purpose of the option!
Please let me know if I can provide more information regarding this issue!