cmake-examples README

The project's README from github.com/ttroy50/cmake-examples. As one markdown file: README.md.

= CMake Examples :toc: :toc-placement!:

toc::[]

Introduction

https://cmake.org/[CMake] is a cross-platform open-source meta-build system which can build, test and package software. It can be used to support multiple native build environments including make, Apple's xcode and Microsoft Visual Studio.

This repository includes some example modern CMake configurations which I have picked up when exploring it's usage for various projects. The examples are laid out in a tutorial like format. The first examples are very basic and slowly increase in complexity drawing on previous examples to show more complex use cases.

These examples have been tested on Ubuntu 16.04 but should work under any Linux system that supports CMake v3.5+.

This branch works with the CMake version 3.5 onwards.

image:https://travis-ci.org/ttroy50/cmake-examples.svg?branch=master["Build Status", link="https://travis-ci.org/ttroy50/cmake-examples"]

Requirements

The basic requirements for most examples are:

Installation on Ubuntu

The easiest way to install the above on Ubuntu is as follows

[source,bash]

$ sudo apt-get install build-essential $ sudo apt-get install cmake

Some specific examples may require other tools including:

Docker

Docker containers with all requirements and various versions of CMake are generated to help make testing the examples easier. These are available from the docker hub repository link:https://hub.docker.com/r/matrim/cmake-examples/[matrim/cmake-examples].

To build the full set of cmake-examples test cases you can run:

[source,bash]

docker run -it matrim/cmake-examples:3.5.1 cd ~ git clone https://github.com/ttroy50/cmake-examples.git code cd code ./test.sh

For more details on build and running the docker containers link:here[dockerfiles].

Other Links

There are many CMake tutorials and examples online. The list below includes links to some of these which I have found helpful in my CMake journey.

cmake-examples (ttroy50/cmake-examples)

Searching Database…

这是什么?这是一个教程仓库,包含一系列由浅入深的 CMake 示例项目,展示如何使用现代 CMake 来构建、测试和打包 C++ 软件。
这是一个库,还是一组示例项目?这是一组独立的 CMake 示例项目,每个项目位于各自的文件夹中,适合作为分步教程阅读和动手尝试,而不是作为库来导入使用。
我该怎么试用这些示例?先安装 CMake 和 C++ 编译器,然后克隆仓库,进入任意示例目录并进行构建;也可以使用 'test.sh' 脚本,在提供的 Docker 容器中运行全部示例。
构建这些示例前需要先安装什么?CMake v3.5 或更高版本、C++ 编译器(默认为 gcc)以及 make;部分特定示例还需要 Boost、protobuf、cppcheck、clang、ninja-build 或 conan 等工具。
这些示例能在任何 CMake 版本上运行吗?此分支面向 CMake 3.5 及更高版本;针对 CMake 2.x 和 3.0 编写的示例则分别放在其他分支中。
我能在 Ubuntu/Linux 之外的系统上运行这些示例吗?这些示例已在 Ubuntu 16.04 上测试过,在任何安装了 CMake v3.5+ 的 Linux 系统上应该也能运行;CMake 本身是跨平台的(支持 make、Xcode、Visual Studio),但给出的安装说明是针对 Ubuntu 的。
这些示例在基础构建之外还涵盖哪些主题?内容会逐步深入到使用 CTest、Google Test 和 Catch 进行测试,使用 CPack 进行打包,通过 Cppcheck 和 clang 进行静态分析,使用 clang-format 进行代码格式化,以及使用 Boost 和 Conan 等依赖库。
有没有更简便的方式,无需手动安装所有环境就能测试全部示例?有。已在 Docker Hub(matrim/cmake-examples)上发布了包含所有依赖及多种 CMake 版本的 Docker 镜像,也可以使用 test.sh 脚本在容器中运行全部示例。
这些示例对初学者来说是怎样组织的?示例从非常基础的内容开始,复杂度逐步提升,后面的示例会建立在前面介绍的概念之上,因此初学者大致可以按顺序逐个学习。
Creator
ttroy50
Size
0.5 MB
Stars
13.1K
Age
10y
Commits · 90 Days