<< Modern CMake >> translation 1. CMake Introduction

<< Modern CMake >> translation 1. CMake Introduction

People love to hate the build system. Just watch the speech on CppCon17, you can see examples of developers because build systems and absurd. This allows us to ponder a question: why is this so? Of course, you can not be perfect when building systems. But I think, in 2018, we can solve some of these problems. This is CMake. But CMake 2.8 may not work; it before C ++ 11 release on the release! For CMake is no example (even in those instances publish their tutorials KitWare list) terrible. Let's talk about modern CMake. CMake 3.1+, perhaps even CMake 3.15+! It is clean, powerful, elegant, so you can spend most of their time on coding, instead of writing unreadable, unmaintainable Make (or CMake 2) file. Of course, CMake 3.11+ should be up and running significantly faster!

 

 

This book is published as an online document. You can  GitLab  ask questions or submit the merger request. You can also  download the PDF from here .

 

In short, if you are considering the use of modern CMake, which may be the problem you are most concerned about:

Why do I need to build a good system?

Which of the following points for you?

  • You want to avoid hard-coded path
  • You need to build the software on multiple computers
  • You want to use the CI (continuous integration)
  • You need to support different operating systems (although it may only Unix style)
  • You want to support multiple compilers
  • You want to use the IDE, but sometimes they do not
  • You want to describe the logical structure of the program, instead of a flag and command
  • You want to use a third-party packages
  • You want to use tools like Clang-Tidy to help you write code
  • You want to use a debugger (debugger)

If so, you will benefit from similar CMake build system.

Why do we choose CMake?

Construction of the system is a hot topic. Of course, we have many options. But even very good, or reuse a familiar syntax, and CMake can not be compared. why? Ecological support. Each IDE supports CMake (or CMake support these IDE). There are more packages in use CMake instead of other building systems. So, if you are using a software package that is designed to be included in your code, you can choose: create your own build system or build a system that supports: These packages are almost always supported by CMake. If you want to use multiple software packages, CMake will soon become common. And, if you need to pre-install a package, then it has the possibility to find or CMake configuration script is very high.

Why use modern CMake?

About CMake 2.6-2.8 time, CMake became popular. Package manager appeared in the list of most Linux operating systems, and is used in many software packages. Then came the Python 3. I know that this has nothing to do with CMake. But it is the third edition. It is preceded by a second edition: It's a tough, ugly transition, even today, some software still use the second edition.

I believe luck CMake 3 Python 3 will not be better than where to go. 1  Although each version of CMake efforts are backward compatible, but CMake 3 series is regarded as any course something new. Therefore, you will find that operating systems like CentOS 7, already have GCC 4.8, almost completely supports C ++ 14, is still in use in CMake 2.8 C ++ 11 before it launched.

You really at least should use CMake version of the compiler that occur after the release, because the system needs to know to build a new version of the compiler compiler flags and other information. Moreover, because of their CMake will be reduced to the minimum required CMake file indicated, so even if you install a new CMake system-wide, is also very safe. Or you at least should install it locally. It's easy (it thing one or two lines of code in most cases), you will find five minutes of work will save you hundreds of lines and hours of  CMakeLists.txt writing time, and will be easier to maintain in the long run. This book attempts to solve those problems and bad examples can be seen everywhere on the network, and the method proposed best practices.

Other Resources

There are other places on the Internet to find useful information. Here are some of them:

  • Official Help at The : really great documentation. Well-organized, easy search, you can also switch the version at the top. It's just not a great "Best Practices Guide", this book attempts to fill this gap in
  • Modern CMake as Effective : Use a very good list of guidelines
  • Modern CMake Embracing : the term has a very good description of the posts
  • Time to do CMake's IT Right : A good best practice of modern CMake project
  • The Ultimate Guide to Modern CMake slightly outdated posts with similar intentions:
  • Modern CMake More : Meeting C ++ 2018 recommendation from the CMake 3.12+ wonderful presentation. This speech makes CMake 3.0+  modern CMake  , and CMake 3.12+  more modern CMake  become a topic
  • toeb / moderncmake : on a good demonstration and example CMake 3.5+ by the project organization describes the syntax

Acknowledgments

Modern CMake originally developed by  Henry Schreiner  written. Other contributors information can  GitLab project contributors list  found in.

Chinese version of the book by the  South Common  Engineer  He Jiang  translation in his spare time.

1. CMake 3.0 also remove from a very old version of CMake in several long-term deprecated functions, and associated with the square bracket syntax made a very slight backward incompatible changes, so it is not entirely fair; possible there will be some very, very old CMake file CMake 3+ not run in; although I have never seen.  ↩

Guess you like

Origin www.cnblogs.com/hejiang/p/11247618.html