C++ cmake .. 做什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12236642/
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
What does cmake .. do?
提问by batman
I got the Box2D project source and want to compile the testbed portion of it. The project folder contains folders like: freeglu glui testbed(a demo) helloword(a demo) Box2D Build CMakeFiles
我得到了 Box2D 项目源代码并想编译它的测试平台部分。项目文件夹包含以下文件夹:freeglu glui testbed(a demo) helloword(a demo) Box2D Build CMakeFiles
There are many CMakeLists.txt in all the different folders. I was thinking that I should cmake all those files so that make files are created in all places required. I read this (as instructions to do do want I want) :
在所有不同的文件夹中有许多 CMakeLists.txt。我在想我应该 cmake 所有这些文件,以便在所有需要的地方创建 make 文件。我读了这个(作为做我想要的说明):
wget http://box2d.googlecode.com/files/Box2D_v2.2.1.zip
unzip Box2D_v2.2.1.zip
cd Box2D_v2.2.1/Build
cmake ..
make
What does the cmake .. do? There is no CMakeLists.txt in the build folder.
cmake .. 做什么?构建文件夹中没有 CMakeLists.txt。
回答by Offirmo
cmakeis a Makefile generator.
cmake是一个 Makefile 生成器。
When you call cmake [path]
, you ask it to generate a Makefilein the current directoryfollowing instructions given in [path]/CMakeLists.txt
当你打电话cmake [path]
,你问它来生成一个Makefile在当前目录下面给出的说明[path]/CMakeLists.txt
Usually cmake output some messages while it is working, and after it is done without errors, you can type "make" to execute your newly created Makefile.
通常cmake在工作时会输出一些消息,在没有错误的情况下完成后,您可以键入“make”来执行您新创建的Makefile。
CMakeLists.txtfiles can reference other CMakeLists.txtfile in sub-directories, so you are usually only interested by the CMakeLists.txtof the topdirectory, not the other ones.
的CMakeLists.txt文件可以引用其他的CMakeLists.txt在子目录中的文件,所以你通常只用感兴趣的CMakeLists.txt中的顶级目录,而不是其他的。
Using an empty "build" directory is a technique called "out-of-source build", in which all your generated files (.o, executable, Makefile, .anything) are generated in the separate "build" directory and not mixed with source files. If you want to clean all, you can delete all the content of the build directory.
使用空的“build”目录是一种称为“out-of-source build”的技术,其中所有生成的文件(.o、executable、Makefile、.anything)都在单独的“build”目录中生成,而不是与源文件。如果要全部清理,可以删除build目录下的所有内容。
In fact, you can put your "build" directory in any place, as long as you give cmake the correct path of the top CMakeLists.txt. You can even have several build directories. It is very useful if you need several different builds at the same time (with different options, different versions of gcc, etc.)
其实你可以把你的“build”目录放在任何地方,只要你给cmake顶层CMakeLists.txt的正确路径即可。您甚至可以有多个构建目录。如果您同时需要多个不同的构建(具有不同的选项、不同版本的 gcc 等),这将非常有用。
In old programs, you generate the Makefile too, but using ./configure
(this is called auto-tools. You may have encountered that already). cmake is considered a successor of the auto-tools.
在旧程序中,您也生成 Makefile,但使用./configure
(这称为自动工具。您可能已经遇到过)。cmake 被认为是自动工具的继承者。
回答by Alex F
cmake ..
generates makefiles in the current directory, using ../CMakeLists.txt
file as starting point. makecommand, executed after this, builds the program, using generated makefile(s) as an input. This is convenient to keep a source code and build results in different folders. General syntax is: cmake source-dir(of course, there are a lot of other switches).
cmake ..
在当前目录中生成makefile,以../CMakeLists.txt
文件为起点。在此之后执行的make命令构建程序,使用生成的 makefile(s) 作为输入。这样可以方便地将源代码和构建结果保存在不同的文件夹中。一般语法是:cmake source-dir(当然还有很多其他的开关)。
回答by Rook
Well, ..
is shorthand for the parent folder, so it will presumably act upon whatever it finds in Box2D_v2.2.1
.
嗯,..
是父文件夹的简写,所以它大概会根据它在Box2D_v2.2.1
.