Introduction: This paper introduces a cross-platform automated building system CMake on Linux. CMake is a tool that is easier to use than Automake, which frees programmers from the complexities of compiling connections. This article introduces some examples of how to use CMake to process multiple source file directories, find and use other development packages, and generate debug and release programs.
CMake Introduction
CMake is a cross-platform automated construction system that uses a file called CMakeLists.txt to describe the build process that can produce standard build files, such as Unix Makefile or Windows Visual C + + Projects/works Paces. File CMakeLists.txt need to be written by hand or by scripting for semi-automatic generation. CMake provides a more concise syntax than AutoConfig. The process of generating Makefile and compiling using CMake under the Linux platform is as follows:
Write CmakeLists.txt.
Executes the command "CMake path" or "Ccmake path" Generation Makefile (PATH is the directory where CMakeLists.txt resides).
Compile using the Make command.
First Project
It is assumed that there is only one source file in our project Main.cpp
Listing 1 source Files Main.cpp
1 #include <iostream>
2
3 int main ()
4 {
5 std::cout<< "Hello word!" <<std::endl;
6 return 0;
7}
To build this project, we need to write a file CMakeLists.txt and put it in the same directory as main.cpp:
Listing 2 CMakeLists.txt
1 PROJECT (Main)
2 cmake_minimum_required (VERSION 2.6)
3 aux_source_directory (. DIR_SRCS)
4 add_executable (main ${dir_srcs})