Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why am I warned that the "CMAKE_TOOLCHAIN_FILE" variable is not used by the project?

When I build some third-party code, I am seeing the following warning from CMake:

CMake Warning:   Manually-specified variables were not used by the project:      CMAKE_TOOLCHAIN_FILE 

What is causing this warning? I checked the configuration files, but could not find anywhere where this variable is defined.

Should I be concerned about this warning? How can I fix it so that the warning goes away?

like image 656
pleerock Avatar asked Feb 07 '13 17:02

pleerock


People also ask

What is Cmake_toolchain_file?

It is the path to a file which is read early in the CMake run and which specifies locations for compilers and toolchain utilities, and other target platform and compiler related information.


1 Answers

This is the standard warning that CMake generates when you're giving it a command line option that it's not using. For example, passing -DFOO=bar to cmake when the CMakeLists.txt file doesn't actually use the FOO variable.

Now, this is a bit of a special case: CMAKE_TOOLCHAIN_FILE is used by CMake the first time it configures your build, but, since you can't change the toolchain for an already-configured build, this variable is ignored every other time; hence the warning.

As Answeror noted in a comment, you can safely ignore the warning. Brad King explained on the CMake mailing list on February 7, 2011:

I can only get this to happen by running CMake on a build tree that already exists. The variable *does* get used on the *first* run in a fresh tree. It does *not* get used later because you don't need to specify it to regenerate. CMake has already recorded a rule to load the file in CMakeFiles/CMakeSystem.cmake and does not support changing the toolchain of an existing build tree.

IOW, this is a legitimate instance of the warning.

If this warning really bothers you, you have a couple of options for suppressing it:

  • You can pass the --no-warn-unused-cli option when you run cmake.

    This is a bit of a blunt instrument, though, because it suppresses all warnings from unused variables specified on the command line. That may hide some legitimate warnings.

  • You can remove the temporary files generated by the first invocation of CMake before invoking it a second time. As mentioned in a comment by js., you need to delete the CMakeCache.txt file and the CMakeFiles folder. For example, by executing:

     rm -rf CMakeCache.txt CMakeFiles/ 

    But, as javs notes, this is a bit pointless. There's no reason to delete these generated files unless you are actually changing the toolchain. Although it does make the warning go away, it does so merely by forcing the files to be re-generated, which wastes time for minimal gain.

  • A third option (and perhaps the best) is given by Roland Sarrazin's answer. This involves simply using the variable by outputting it in a status message. This way, it is not unused, so the warning is not triggered. You may even find the message to be useful for debugging problems related to the toolchain configuration.

like image 72
Guillaume Avatar answered Oct 12 '22 03:10

Guillaume