Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
652 views
in Technique[技术] by (71.8m points)

makefile - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...