Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does cmake .. do?

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

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) :

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.

like image 325
batman Avatar asked Sep 02 '12 14:09

batman


People also ask

What is the use of CMake?

CMake is a meta build system that uses scripts called CMakeLists to generate build files for a specific environment (for example, makefiles on Unix machines). When you create a new CMake project in CLion, a CMakeLists. txt file is automatically generated under the project root.

Why do you need CMake?

CMake can generate a native build environment that will compile source code, create libraries, generate wrappers and build executables in arbitrary combinations. CMake supports in-place and out-of-place builds, and can therefore support multiple builds from a single source tree.

Where is CMake used?

CMake is [...] software for managing the build process of software using a compiler-independent method. It is designed to support directory hierarchies and applications that depend on multiple libraries. It is used in conjunction with native build environments such as make, Apple's Xcode, and Microsoft Visual Studio.

What does CMake do in Windows?

Cmake allows to provide cross platform build files that would generate platform specific project/make files for particular compilation/platform. cmake . inside your project's directory on Windows platform,Cmake will generate all the necessary project/solution files ( . sln etc.).


1 Answers

cmake is a Makefile generator.

When you call cmake [path], you ask it to generate a Makefile in the current directory following instructions given in [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.

CMakeLists.txt files can reference other CMakeLists.txt file in sub-directories, so you are usually only interested by the CMakeLists.txt of the top directory, not the other ones.

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.

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.)

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.

like image 124
Offirmo Avatar answered Sep 17 '22 14:09

Offirmo