如何跟踪CMakeLists.txt [英] How to Trace CMakeLists.txt

查看:771
本文介绍了如何跟踪CMakeLists.txt的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法检查 cmake 在失败的运行中所做的事情?例如,我有一个程序取决于libbacktrace,我可以链接到 gcc foo.c -lbacktrace 。但是当我写一个 CMakeLists.txt

Is there a way to examine what cmake is doing in a failing run? For example, I have a program depending on libbacktrace, which I can link to by gcc foo.c -lbacktrace. But when I write a CMakeLists.txt like

cmake_minimum_required(VERSION 2.8)
find_library (BACKTRACE_LIBRARY backtrace)
message (BACKTRACE_LIBRARY=${BACKTRACE_LIBRARY})

并键入 cmake< path> ,将打印出 BACKTRACE_LIBRARY = BACKTRACE_LIBRARY- NOTFOUND

我如何去弄清楚问题在哪里?什么命令是在放弃找到libbacktrace之前执行 cmake ?它执行任何东西吗?在autoconf中,这些命令都记录在 config.log 中,但在这种情况下, CMakeOutput.log 为空。同样, cmake --trace 只会在一系列系统cmake文件后回显 CMakeLists.txt

How do I go about figuring out where the problem is? What commands is cmake executing before giving up on finding libbacktrace? Is it executing anything at all? In autoconf, the commands are all recorded in config.log, but CMakeOutput.log in this case is blank. Likewise, cmake --trace only echoes the contents of CMakeLists.txt after a bunch of system cmake files, which is useless in this case.

请注意,我不是在寻找一种方法来调用 find_library 工作 - 这只是一个例子。我的问题是:我有一个CMakeLists.txt,不能正常工作;

Please note that I'm not looking for a way to make this particular invocation of find_library work - that's just an example. My question is: I have a CMakeLists.txt that isn't working as expected; what tools exist to help me figure out where and why it's failing?

推荐答案

有一个无CMake调试器或类似的¹。你可以做的是:

There is no CMake debugger or similar¹. What you can do is:


  1. 读取CMake的输出,有时它已经提供了像missing INCLUDE_MYLIB_DIR的提示。删除CMakeCache.txt和/或删除构建目录,以确保您不会错过输出,因为结果已缓存。重复并检查缓存是否有影响。您可以使用 -Wdev 获得更多警告(这些意见适用于CMake脚本的作者/开发人员,而不是用户)。更多有用的选项是 - warn-uninitialized - warn-unused-vars --check-system-vars ,请参阅文档了解详情。

  1. Read the output of CMake, sometimes it already gives hints like "missing INCLUDE_MYLIB_DIR"). Delete you CMakeCache.txt and/or remove the build directory, to be sure you don't miss output because the result was cached. Repeat and check whether caching had an influence. You get more warnings (those meant for the author/developer of the CMake script, not for the user) with -Wdev. More helpful options are --warn-uninitialized, --warn-unused-vars and --check-system-vars, see the documentation for more details.

检查生成的文件,如 CMakeCache.txt 和您生成的其他文件像 config.h 或为Doxygen输入文件。

Check the generated files like the CMakeCache.txt and additional files you generate like a config.h or input files for Doxygen. Variables with values you expect different, are indicators for further research.

请查看CMakeFiles子目录中的CMakeError.log和CMakeOuput.log。不幸的是,许多测试不写入这些文件,但有些做。例如C编译器运行将编译器输出放在那里,这有助于发现非预期标志或错误(交叉)编译器的问题。

Have a look into CMakeError.log and CMakeOuput.log in the CMakeFiles sub-directory. Unfortunately, many test do not write into these files, but some do. For example C compiler runs put the compiler output there, which helps to find the problem with unintended flags or wrong (cross-)compilers.

使用 printf 。这意味着当您大致知道问题位于何处时,使用 message 输出中间变量。当您不知道如何评估分支或子表达式(具有AND或OR的表达式的一部分)时,这是有帮助的。此外,你可以把消息像在分支,其中mylib版本> 3.2在里面遵循工作流程。

Debug with printf. This means when you roughly know where you problem is located, output intermediate variables with message. That is helpful, when you don't know how a branch or a sub-expression (a part of a expression with AND or OR) is evaluated. Further you can put messages like "in branch where mylib version is > 3.2" inside to follow the workflow.

降低复杂性。抛出你不知道的一切,直到你的问题消失。再次添加内容,直到问题重新出现。有时,使用最小示例来启动新模块以重现问题更容易。

Reduce complexity. Throw everything out you don't know, until your problem vanishes. Add the stuff again until the problem reappears. Sometimes it is easier to start a new module to reproduce the problem with a minimal example. Surprisingly, this often helps to pinpoint the problem.

使用调试 - debug-output 调试输出) - trace (完整跟踪)和 - trace-expand (跟踪和扩展变量)。对于这些,非常有帮助的第5点取得进展,因为否则输出会泛滥你。

Debug with --debug-output (for debug output) --trace (complete trace) and --trace-expand (trace and expanded variables). For these it is extremely helpful to make progress with point 5., because otherwise the output will flood you.

,则有Steveire的 CMake Daemon工具 。我没有使用它们自己,但他们声称提供了可能性的内省,看起来非常接近调试器。

编辑:他们现在称为 CMake-server ,并将成为CMake 3.7的一部分。您可以期望许多工具和IDE将选择这一点,并改进我们开发CMake的方式。

¹Well, there are the steveire's CMake Daemon Tools. I haven't used them myself, but they claim to offer possibilities for introspection that seem to be pretty close to a debugger.
They are now called CMake-server and are going to be part of CMake 3.7. You can expect that many tools and IDEs will pick this up and improve the way we develop CMake.

这篇关于如何跟踪CMakeLists.txt的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆