Issue
I run cmake
as follows:
cmake . -G Ninja -D CMAKE_PREFIX_PATH=~/libs/QT6.5d -DCMAKE_WARN_DEPRECATED=OFF
but get the following warning while building my project with GCC12:
/usr/include/c++/12/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header which may be removed without further notice at a future date. Please use a non-deprecated interface with equivalent functionality instead. For a listing of replacement headers and interfaces, consult the file backward_warning.h. To disable this warning use -Wno-deprecated. [-Wcpp]
32 | #warning \
| ^~~~~~~
why doesn't CMAKE_WARN_DEPRECATED
take an effect?
Running cmake with -Wno-deprecated
also does not help.
cmake . -G Ninja -D CMAKE_PREFIX_PATH=~/libs/QT6.5d -Wno-deprecated
Solution
CMAKE_WARN_DEPRECATED
controls CMake warnings (those emitted by message(DEPRECATION ...)
), and passing -Wno-deprecated
to CMake is an alias for setting this variable to OFF
.
Your deprecation warning is issued by the compiler, and you need to pass the -Wno-deprecated
flag to the compiler. One way to do this is to use target_compile_options
:
target_compile_options(<target> [PRIVATE|PUBLIC] "-Wno-deprecated")
Answered By - You Answer Checked By - Willingham (WPSolving Volunteer)