Cmake gives this warning when building one third-party script:
CMake Warning:
Manually-specified variables were not used by the project:
CMAKE_TOOLCHA
In case you get this message with CLion after you set the
-DCMAKE_TOOLCHAIN_FILE=xxx
option, you'll want to delete all the CMake build directories.
Do
Tools-> CMake -> Show Generated CMake Files in File Manager
then delete all build directories. Then do
Tools-> CMake -> Reload the CMake Project
Once you do this, you will still get the warning, but at least it will be observed the first time cmake is run.
Same happened here, as @js pointed out, this usually means you have build relicts of cmake from a past config.
Do a rm -rf CMakeCache.txt CMakeFiles/
and the message will be gone the first time you do the cmake -DCMAKE_TOOLCHAIN_FILE=foo.cmake .
. The second time, they will be there again and as @Guilaume answered that's ok.
P.S.:
I first did a git clean --force
but since those files are usually in .gitignore
, that does not reset the build.
The reasons for this specific unused variable were already explained in @Guillaume's answer. A simple and useful way to circumvent the warning about the unused variable is to use it in a status message.
message(STATUS "Using toolchain file: ${CMAKE_TOOLCHAIN_FILE}.")
This is the standard warning gives you when you're giving it a command line option it's not using. That is giving -DFOO=bar
to cmake when the CMakeLists.txt doesn't use FOO variable.
Now, that's a bit of a special case here: CMAKE_TOOLCHAIN_FILE is used by CMake the first time you're configuring your build, but as you can't change the toolchain for an already configured build, it's ignored every other time, thus the warning.
As @Answeror said, you can safely ignore the warning, but if it really bother you, you can hide it by giving --no-warn-unused-cli
to cmake.