Using CMake to build applications under Linux

Source: Internet
Author: User
Tags windows visual

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.