Skip to content
GitLab
Projects Groups Topics Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Register
  • Sign in
  • CMake CMake
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributor statistics
    • Graph
    • Compare revisions
  • Issues 4,167
    • Issues 4,167
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 16
    • Merge requests 16
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Releases
  • Packages and registries
    • Packages and registries
    • Container Registry
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • External wiki
    • External wiki
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • CMakeCMake
  • CMakeCMake
  • Issues
  • #22035
Closed
Open
Issue created Apr 06, 2021 by Mischa Alff@GenuineAster

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!

Edited Apr 06, 2021 by Brad King
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking