CMake with --warn-unused-vars warns about all unused CMAKE_* variables

Viewed 776

I want to use the --warn-unused-vars flag with CMake, but it floods the output with warnings to unused CMAKE_* variables. It happens even with an empty CMakeLists.txt file, but to generate an example I used this one:

cmake_minimum_required(VERSION 3.15)

project(p)

set(myVar)

If I run cmake --warn-unused-vars .. it generates the following output:

Finding unused variables.
CMake Warning (dev) in build/CMakeFiles/3.15.4/CMakeSystem.cmake:
  unused variable (changing definition) 'CMAKE_CURRENT_LIST_FILE'
Call Stack (most recent call first):
  CMakeLists.txt:3 (project)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) in build/CMakeFiles/3.15.4/CMakeSystem.cmake:
  unused variable (changing definition) 'CMAKE_CURRENT_LIST_DIR'
Call Stack (most recent call first):
  CMakeLists.txt:3 (project)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at build/CMakeFiles/3.15.4/CMakeSystem.cmake:1 (set):
  unused variable (changing definition) 'CMAKE_HOST_SYSTEM'
Call Stack (most recent call first):
  CMakeLists.txt:3 (project)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at build/CMakeFiles/3.15.4/CMakeSystem.cmake:2 (set):
  unused variable (changing definition) 'CMAKE_HOST_SYSTEM_NAME'
Call Stack (most recent call first):
  CMakeLists.txt:3 (project)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at build/CMakeFiles/3.15.4/CMakeSystem.cmake:3 (set):
  unused variable (changing definition) 'CMAKE_HOST_SYSTEM_VERSION'
Call Stack (most recent call first):
  CMakeLists.txt:3 (project)
This warning is for project developers.  Use -Wno-dev to suppress it.

[This and similar stuff goes on for 6000+ lines]

I expected CMake to only warn about myVar (it does warn about it as well among all that noise). Do I have to filter the output by myself or is there some kind of additional flag I have to pass or configuration I have to change in order to limit the warnings to my CMake files? With -Wno-dev it also suppresses the warning about myVar which I want to keep.

0 Answers
Related