26

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? 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.
    – Velkan
    Apr 6, 2016 at 13:05
  • remove those unwanted variables (-D<variable>), when calling cmake. When not in use, remove them, than suppressing them.
    – parasrish
    Oct 24, 2017 at 14:18
  • @parasrish, can't do it.
    – Velkan
    Oct 24, 2017 at 14:54
  • 3
    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.
    – Lothar
    May 21, 2021 at 11:08

1 Answer 1

28

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.

1
  • 2
    The next email has an excellent "rebuttal" of the CMake author, recommended.
    – MarcH
    Sep 17, 2020 at 19:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.