Use cmake to manage projects

Source: Internet
Author: User

1. What is cmake?

See

Http://en.wikipedia.org/wiki/CMake

Http://www.cmake.org/

In short, cmake is a cross-platform engineering build tool. The traditional * nix makefile generation tool is mainly the autotools series. These tools can generate makefiles based on different systems. Compared with traditional autotools tools. Cmake can generate corresponding engineering files based on IDE on different platforms. Currently, at least makefile, Visual Studio series, eclipse CDT, mingw, and codeblocks are supported.

2. A cmake example.

Assume that you want to generate a project named test, including a file named hello. cpp (under the directory test)

1 # include <stdio. h>
2
3 int main (INT argc, char ** argv)
4 {
5 printf ("Hello world! \ N ");
6 RETURN 0;
7}

Now we want cmake to build this project.

First, configure the cmakepoliccmakelists.txt file. Therefore, the cmakelists.txt file is created in the testobject directory.

Cmakelists.txt File Content

Project (test)
Set (src_list hello. cpp)
Add_executable (test $ {src_list })

Then build the project, go to the command line (corresponding to the command shell in Windows), and enter the test directory.

Cmake.

You can (note. indicates the current directory ). Cmake automatically generates the corresponding makefile (or Visual Studio project file)

3. For more information, see

The above example is relatively simple. For more usage of cmake, refer to the official documents of cmake and wiki, http://www.cmake.org --> help --> document and Wiki.

In addition, I personally feel that cmake's official documentation is very blunt and obscure. The following tutorial is recommended for general applications.

Http://sewm.pku.edu.cn/src/paradise/reference/CMake%20Practice.pdf

(In the last line of the 6th page of the PDF file, the src_list should be $ {src_list}. I believe you can easily see the original text incorrect)

Basically, the content required for normal use is included in the above tutorial. There are many examples, which are strongly recommended.

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.