将 CMake 与 GNU Make 结合使用:如何查看确切的命令?

发布于 2024-08-29 14:37:29 字数 161 浏览 10 评论 0原文

我将 CMake 与 GNU Make 一起使用,并希望准确地查看所有命令(例如编译器如何执行、所有标志等)。

GNU make 有 --debug,但它似乎没有那么有用,还有其他选项吗? CMake 是否在生成的 Makefile 中提供附加标志以用于调试目的?

I use CMake with GNU Make and would like to see all commands exactly (for example how the compiler is executed, all the flags etc.).

GNU make has --debug, but it does not seem to be that helpful are there any other options? Does CMake provide additional flags in the generated Makefile for debugging purpose?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

情绪操控生活 2024-09-05 14:37:29

运行 make 时,添加 VERBOSE=1 以查看完整的命令输出。例如:

cmake .
make VERBOSE=1

或者您可以将 -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON 添加到 cmake 命令,以从生成的 Makefile 中获得永久详细命令输出。

cmake -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON .
make

为了减少一些可能不太有趣的输出,您可能需要使用以下选项。选项 CMAKE_RULE_MESSAGES=OFF 删除诸如 [ 33%] Building C object... 之类的行,而 --no-print-directory 告诉 make不打印当前目录,过滤掉诸如 make[1]: Entering Directorymake[1]: Leaving Directory 之类的行。

cmake -DCMAKE_RULE_MESSAGES:BOOL=OFF -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON .
make --no-print-directory

When you run make, add VERBOSE=1 to see the full command output. For example:

cmake .
make VERBOSE=1

Or you can add -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON to the cmake command for permanent verbose command output from the generated Makefiles.

cmake -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON .
make

To reduce some possibly less-interesting output you might like to use the following options. The option CMAKE_RULE_MESSAGES=OFF removes lines like [ 33%] Building C object..., while --no-print-directory tells make to not print out the current directory filtering out lines like make[1]: Entering directory and make[1]: Leaving directory.

cmake -DCMAKE_RULE_MESSAGES:BOOL=OFF -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON .
make --no-print-directory
拒绝两难 2024-09-05 14:37:29

CMakeLists.txt 文件中将选项设置为:

set(CMAKE_VERBOSE_MAKEFILE ON)

It is convenient to set the option in the CMakeLists.txt file as:

set(CMAKE_VERBOSE_MAKEFILE ON)
恋竹姑娘 2024-09-05 14:37:29

或者简单地在 shell 上导出 VERBOSE 环境变量,如下所示:
<代码>
导出详细=1

Or simply export VERBOSE environment variable on the shell like this:

export VERBOSE=1

沙与沫 2024-09-05 14:37:29

cmake --build 。 --verbose

在 Linux 上生成 Makefile,这可能只是在底层调用 make VERBOSE=1,但是 cmake --build对于您的构建系统来说可以更具可移植性,例如跨操作系统工作,或者如果您决定稍后进行 Ninja 构建:

mkdir build
cd build
cmake ..
cmake --build . --verbose

其文档还表明它相当于 VERBOSE=1

--详细,-v

启用详细输出 - 如果支持 - 包括要执行的构建命令。

如果 VERBOSE 环境变量或CMAKE_VERBOSE_MAKEFILE 缓存变量已设置。

在 Cmake 3.22.1、Ubuntu 22.04 上测试。

cmake --build . --verbose

On Linux and with Makefile generation, this is likely just calling make VERBOSE=1 under the hood, but cmake --build can be more portable for your build system, e.g. working across OSes or if you decide to do e.g. Ninja builds later on:

mkdir build
cd build
cmake ..
cmake --build . --verbose

Its documentation also suggests that it is equivalent to VERBOSE=1:

--verbose, -v

Enable verbose output - if supported - including the build commands to be executed.

This option can be omitted if VERBOSE environment variable or CMAKE_VERBOSE_MAKEFILE cached variable is set.

Tested on Cmake 3.22.1, Ubuntu 22.04.

情栀口红 2024-09-05 14:37:29

如果您使用 CMake GUI,则切换到高级视图,该选项称为 CMAKE_VERBOSE_MAKEFILE。

If you use the CMake GUI then swap to the advanced view and then the option is called CMAKE_VERBOSE_MAKEFILE.

瘫痪情歌 2024-09-05 14:37:29

CMake 3.14+

CMake 现在具有 --verbose 来指定详细构建输出。无论您的发电机如何,这都有效。

cd project
cmake -B build/
cmake --build build --verbose

值得注意的是,Xcode 可能无法与 -- 一起使用verbose

Some generators such as Xcode don't support this option currently.

另一种选择是使用 VERBOSE 环境变量。

New in version 3.14.

Activates verbose output from CMake and your build tools of choice when you start to actually build your project.

Note that any given value is ignored. It's just checked for existence.

CMake 3.14+

CMake now has --verbose to specify verbose build output. This works regardless of your generator.

cd project
cmake -B build/
cmake --build build --verbose

It's worth noting however Xcode may not work with --verbose

Some generators such as Xcode don't support this option currently.

Another option it to use the VERBOSE environment variable.

New in version 3.14.

Activates verbose output from CMake and your build tools of choice when you start to actually build your project.

Note that any given value is ignored. It's just checked for existence.
思念满溢 2024-09-05 14:37:29

我正在尝试类似的方法来确保 -ggdb 标志存在。

在干净的目录中调用 make 并 grep 您要查找的标志。寻找 debug 而不是 ggdb 我只会写。

<代码>使详细= 1 | grep debug

-ggdb 标志非常模糊,只弹出编译命令。

I was trying something similar to ensure the -ggdb flag was present.

Call make in a clean directory and grep the flag you are looking for. Looking for debug rather than ggdb I would just write.

make VERBOSE=1 | grep debug

The -ggdb flag was obscure enough that only the compile commands popped up.

灯角 2024-09-05 14:37:29

cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=TRUE 将生成一个文件 编译命令

某些 LSP 需要此文件来了解如何开箱即用地编译源文件,但它也可以帮助调试编译问题。

输出文件名为 ${CMAKE_BINARY_DIR}/compile_commands.json

cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=TRUE will generate a file with all compilation commands.

This file is required by some LSP to know how to compile a source file out of the box, but it could also help for debugging compilation problems.

The output file is named ${CMAKE_BINARY_DIR}/compile_commands.json.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文