35

What is the preferred way to just touch the variable, inside the CMakeLists.txt?

I've got a bunch of similar ExternalProjects that are called in a loop with the same variables. Some of the projects don't need specific variables.

5
  • 3
    What does 'touch a variable' mean? Commented Apr 6, 2016 at 12:50
  • 1
    @user3159253, it means to do with the variable something that has no effect. But it has to be robust, so it isn't confusing and it won't produce more warnings in the future CMake versions. Commented Apr 6, 2016 at 13:05
  • remove those unwanted variables (-D<variable>), when calling cmake. When not in use, remove them, than suppressing them. Commented Oct 24, 2017 at 14:18
  • 1
    @parasrish, can't do it. Commented Oct 24, 2017 at 14:54
  • 4
    The problem is that the unused detection in cmake is just not good enough. If you use the variable only in a conditional it is not flagged as used. if (DEFINED SOME_CONDITION) does not mark SOME_CONDITION as used. Commented May 21, 2021 at 11:08

1 Answer 1

35

You could simply disable this warning all-together by passing --no-warn-unused-cli to CMake. See: https://cmake.org/cmake/help/latest/manual/cmake.1.html#options

Touching the variable is explicitly not wanted according to one of the CMake authors: https://cmake.org/pipermail/cmake/2011-February/042908.html

Nevertheless, for variables passed by -DFOO=bar -DBAR=3 -DBAZ=true you can add a line

set(ignoreMe "${FOO}${BAZ}${BAR}") 

to one of your CMakeLists.txt which should be enough to suppress the warning.

Sign up to request clarification or add additional context in comments.

1 Comment

The next email has an excellent "rebuttal" of the CMake author, recommended.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.