Linux 在执行之前制作 CMake 打印命令
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4808303/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Making CMake print commands before executing
提问by DarenW
I'm working on a large C++ project built with CMake on Linux. CMake runs okay, producing a horde of Makefiles in the tree of modules and applications. Running GNU make
leads to linker errors. How can I get make
to print out the exact commands before running them?
我正在开发一个在 Linux 上使用 CMake 构建的大型 C++ 项目。CMake 运行正常,在模块和应用程序树中生成了大量 Makefile。运行 GNUmake
会导致链接器错误。如何make
在运行之前打印出确切的命令?
The -d option does not print the commands, but plenty of information that hasn't been helpful.
-d 选项不会打印命令,但会打印大量无用的信息。
The -n option prints all the commands, but does not run them, so I can't tell were exactly the trouble is. Examining the stdout from make -n, I don't see any commands that are relevant. I suspect some commands change depending on the results of earlier commands, and the hierarchy of Makefiles makes it difficult to tell what's really going on.
-n 选项打印所有命令,但不运行它们,所以我不知道问题到底出在哪里。从 make -n 检查标准输出,我没有看到任何相关的命令。我怀疑某些命令会根据较早命令的结果而改变,并且 Makefile 的层次结构使得很难判断到底发生了什么。
I don't see any other options in make's manpage that seem helpful.
我在 make 的手册页中没有看到任何其他有用的选项。
采纳答案by Bill Lynch
I am fairly sure this will work:
我相当确定这会起作用:
make VERBOSE=1
You should also be able to add this to your CMakeLists.txt to permanently set that:
您还应该能够将此添加到您的 CMakeLists.txt 以永久设置:
set(CMAKE_VERBOSE_MAKEFILE on)
This is covered in the CMake FAQ.
回答by k107
For automake-generated Makefiles, try:
对于 automake 生成的 Makefile,请尝试:
make V=1
回答by TrentP
An option, which applies to GNU make and works with any Makefile, whether generated by CMake or not, is to use the --trace
option to make. This will print out the commands make
is executing and still execute them.
一个适用于 GNU make 并适用于任何 Makefile(无论是否由 CMake 生成)的--trace
选项是使用make 选项。这将打印出make
正在执行的命令并仍然执行它们。
This applies to all commands, not just those that VERBOSE=1
or V=1
triggers the printing of in CMake/automake generated makefiles.
这适用于所有的命令,而不仅仅是那些VERBOSE=1
或V=1
触发器中的CMake / automake的生成的makefile打印。
And yet another alternative on Linux is to run make under strace, as strace -f -e trace=execve make <make options>
. The output from strace will include everyprocess that is executed: by make, by a shell script that make ran, etc.
Linux 上的另一种选择是在strace下运行 make ,作为strace -f -e trace=execve make <make options>
. strace 的输出将包括执行的每个进程:由 make、由 make 运行的 shell 脚本等。
For instance, you might find that the CMake-generated makefile executes /usr/bin/cmake -E __run_co_compile <lots of options ...>
and still wonder what the exact compiler invocation(s) are that this in turn will run. You can get that with the strace method.
例如,您可能会发现 CMake 生成的 makefile 正在执行/usr/bin/cmake -E __run_co_compile <lots of options ...>
,但仍然想知道它将依次运行的确切编译器调用是什么。你可以用 strace 方法得到它。
回答by Scott McPeak
For those using cmake --build
, which invokes make
internally, use either:
对于那些使用内部cmake --build
调用的make
,请使用:
$ cmake --build <dir> -- VERBOSE=1
Note the --
before VERBOSE=1
! That passes the argument to the underlying make
process.
注意--
之前VERBOSE=1
!这将参数传递给底层make
进程。
Or:
或者:
$ VERBOSE=1 cmake --build <dir>
which also passes VERBOSE=1
to make
, this time via an environment variable.
这一次也通过环境变量传递VERBOSE=1
给make
。
Or, if using cmake
version 3.14or higher:
或者,如果使用cmake
3.14或更高版本:
$ cmake --build <dir> --verbose
Note the order of the arguments! The --verbose
option must come after --build
and its argument.
注意参数的顺序!该--verbose
选项必须跟从--build
和它的参数。