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…

What is this?A tutorial repository of example CMake projects, laid out from basic to advanced, showing how to use modern CMake for building, testing, and packaging C++ software.
Is this a library or a collection of example projects?It is a collection of standalone example CMake projects, each in its own folder, meant to be read and tried as a step-by-step tutorial rather than imported as a library.
How do I try out the examples?Install CMake and a C++ compiler, then clone the repo, cd into any example directory, and build it; a 'test.sh' script can also run the full set of examples inside a provided Docker container.
What do I need installed before building the examples?CMake v3.5 or newer, a C++ compiler (gcc by default), and make; some specific examples additionally need tools like Boost, protobuf, cppcheck, clang, ninja-build, or conan.
Will these examples work on any CMake version?This branch targets CMake 3.5 and later; separate branches exist for examples written against CMake 2.x and 3.0.
Can I run these examples outside Ubuntu/Linux?They have been tested on Ubuntu 16.04 and should work on any Linux system with CMake v3.5+; CMake itself is cross-platform (supports make, Xcode, Visual Studio), but the install instructions given are Ubuntu-specific.
What topics do the examples cover beyond basic builds?They progress into testing with CTest, Google Test and Catch, packaging with CPack, static analysis via Cppcheck and clang, code formatting with clang-format, and dependency usage like Boost and Conan.
Is there an easier way to test all examples without installing everything manually?Yes, Docker images with all requirements and various CMake versions are published to Docker Hub (matrim/cmake-examples), and a test.sh script can run the full set of examples inside a container.
How are the examples organized for a beginner?They start very basic and gradually increase in complexity, with later examples building on concepts introduced in earlier ones, so a beginner can work through them roughly in order.
Creator
ttroy50
Size
0.5 MB
Stars
13.1K
Age
10y
Commits · 90 Days