This tries to be a minimal cmake example, that covers sources resources dependencies and packaging.

Overview

Minimal CMake Example

This project tries to be a minimal cmake example. It covers sources, resources, dependencies and packaging.

I created this project, because I think the official documentation of CMake is not the best. It avoidids talking about the actually important parts to setup a new project, but instead explains and focuses on unnecessary fuss like how to write configuration headers.

I think that a configuariton headers are something you shouldn't do at all. In my opinion the project should just compile the source without any magic happening. Generating configuration headers just makes the build unnecessarily complicated, and tools that work on the source code get a harder job. I also disagree that every source folder should have it's own CMake file. I think when there is no really good reason do do it otherwise, one CMake file should be enough for the entire project. In one file you should be able to see everything that is important to build all parts of the project. This information should not be scattered around in different source folders within the project.

build can fail because of boost

The build of this project might fail, when CMake does not find boost. This does not mean that there is an error in the CMakeLists.txt file, it just means, that CMake could not find boost in your system. You can simply remove the boost dependency, if you don't want or need it. Or you could tell CMake where to find boost with ccmake or cmake-gui. It's just there to serve as an example, how you could declare dependencies that you do not distribute with your project.

You might also like...
CMake scripts for painless usage of SuiteSparse+METIS from Visual Studio and the rest of Windows/Linux/OSX IDEs supported by CMake

CMake scripts for painless usage of Tim Davis' SuiteSparse (CHOLMOD,UMFPACK,AMD,LDL,SPQR,...) and METIS from Visual Studio and the rest of Windows/Lin

CMake module to enable code coverage easily and generate coverage reports with CMake targets.

CMake-codecov CMake module to enable code coverage easily and generate coverage reports with CMake targets. Include into your project To use Findcodec

unmaintained - CMake module to activate certain C++ standard, feature checks and appropriate automated workarounds - basically an improved version of cmake-compile-features

Compatibility This library provides an advanced target_compile_features() and write_compiler_detection_header(). The problem with those is that they a

📦 CMake's missing package manager. A small CMake script for setup-free, cross-platform, reproducible dependency management.
📦 CMake's missing package manager. A small CMake script for setup-free, cross-platform, reproducible dependency management.

Setup-free CMake dependency management CPM.cmake is a CMake script that adds dependency management capabilities to CMake. It's built as a thin wrapper

CMake checks cache helper modules – for fast CI CMake builds!

cmake-checks-cache Cross platform CMake projects do platform introspection by the means of "Check" macros. Have a look at CMake's How To Write Platfor

 cmake-font-lock - Advanced, type aware, highlight support for CMake
cmake-font-lock - Advanced, type aware, highlight support for CMake

cmake-font-lock - Advanced, type aware, highlight support for CMake

cmake-avr - a cmake toolchain for AVR projects

cmake-avr - a cmake toolchain for AVR projects Testing the example provided The toolchain was created and tested within the following environment: Lin

Make CMake less painful when trying to write Modern Flexible CMake
Make CMake less painful when trying to write Modern Flexible CMake

Izzy's eXtension Modules IXM is a CMake library for writing Modern flexible CMake. This means: Reducing the amount of CMake written Selecting reasonab

[CMake] [BSD-2] CMake module to find ICU

FindICU.cmake A CMake module to find International Components for Unicode (ICU) Library Note that CMake, since its version 3.7.0, includes a FindICU m

Comments
  • Build failure due to missing pthread library reference for unit_tests

    Build failure due to missing pthread library reference for unit_tests

    Thank you for releasing this project; it has helped me a lot in getting CMake set up for a new C++ project.

    I ran into a problem where the target unit_tests fails to build which I tracked down to a missing reference to the pthread library. The following shows my system information (OS, compiler, and CMake version), the steps to reproduce the error, and a diff showing the one line fix.

    I submitted a pull request (pr #2) for this change if you want to incorporate it into the main branch. I tested the fix and it seems to resolve the problem and also resolves Issue #1 (closed for lack of info & followup).

    Thanks again,

    -- Bob

    Version Info

    I cloned the current minimal_cmake_example repo for this test. My OS, CMake, and compiler versions are shown below

    $ cat /etc/lsb-release
    DISTRIB_ID=LinuxMint
    DISTRIB_RELEASE=19
    DISTRIB_CODENAME=tara
    DISTRIB_DESCRIPTION="Linux Mint 19 Tara"
    
    
    $ cmake --version
    cmake version 3.10.2
    
    CMake suite maintained and supported by Kitware (kitware.com/cmake).
    
    $ gcc --version
    gcc (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0
    Copyright (C) 2017 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions.  There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    

    Minimum Error Demonstration

    I created a _build directory next to the cloned source directory and built the project to trigger the error:

    $ mkdir _build && cd _build && cmake ../minimal_cmake_example && make
    -- The C compiler identification is GNU 7.3.0
    -- The CXX compiler identification is GNU 7.3.0
    -- Check for working C compiler: /usr/bin/cc
    -- Check for working C compiler: /usr/bin/cc -- works
    -- Detecting C compiler ABI info
    -- Detecting C compiler ABI info - done
    -- Detecting C compile features
    -- Detecting C compile features - done
    -- Check for working CXX compiler: /usr/bin/c++
    -- Check for working CXX compiler: /usr/bin/c++ -- works
    -- Detecting CXX compiler ABI info
    -- Detecting CXX compiler ABI info - done
    -- Detecting CXX compile features
    -- Detecting CXX compile features - done
    -- Boost version: 1.65.1
    -- Found the following Boost libraries:
    --   filesystem
    --   system
    -- Found GTest: /usr/local/lib/libgtest.a
    -- Configuring done
    -- Generating done
    -- Build files have been written to: /home/apthorpe/Documents/Projects/minimal_cmake_example/_build
    Scanning dependencies of target example
    [ 20%] Building CXX object CMakeFiles/example.dir/src/main/main.cpp.o
    [ 40%] Linking CXX executable example
    [ 40%] Built target example
    Scanning dependencies of target unit_tests
    [ 60%] Building CXX object CMakeFiles/unit_tests.dir/src/test/test.cpp.o
    [ 80%] Building CXX object CMakeFiles/unit_tests.dir/src/main/main.cpp.o
    [100%] Linking CXX executable unit_tests
    /usr/bin/ld: /usr/local/lib/libgtest.a(gtest-all.cc.o): undefined reference to symbol 'pthread_key_delete@@GLIBC_2.2.5'
    //lib/x86_64-linux-gnu/libpthread.so.0: error adding symbols: DSO missing from command line
    collect2: error: ld returned 1 exit status
    CMakeFiles/unit_tests.dir/build.make:124: recipe for target 'unit_tests' failed
    make[2]: *** [unit_tests] Error 1
    

    Fix

    Add -lpthread to end of target_link_libraries list in GTest section of CMakeList.txt:

    $ diff -u CMakeLists.broken.txt CMakeLists.txt 
    --- CMakeLists.broken.txt       2019-01-17 09:16:10.509836205 -0600
    +++ CMakeLists.txt      2019-01-17 09:16:17.441894497 -0600
    @@ -70,6 +70,7 @@
       target_link_libraries(unit_tests PUBLIC
         ${GTEST_BOTH_LIBRARIES}
         example
    +    -lpthread
       )
     
       target_include_directories(unit_tests PUBLIC
    
    
    opened by apthorpe 1
Owner
Arne Döring
Arne Döring
Simple library for embedding static resources into C++ binaries using CMake

libromfs libromfs is an easy way to bundle resources directly into any C++ application and access them through a simple interface. The main advantage

WerWolv 28 Nov 30, 2022
Tundra is a code build system that tries to be accurate and fast for incremental builds

Tundra, a build system Tundra is a high-performance code build system designed to give the best possible incremental build times even for very large s

Andreas Fredriksson 400 Dec 23, 2022
Get dependencies with cmake

cmake-get A cmake module to get dependencies. This module can be used in config mode or in script mode. Installation The module is just one file 'CMak

Paul Fultz II 59 Feb 14, 2022
Example library that shows best practices and proper usage of CMake by using targets

Modern CMake Sample Sample project that shows proper modern CMake usage on a dummy library and an executable that uses it. Accompanying code to my blo

Pablo Arias 601 Dec 29, 2022
Helpful example of a gtest and cmake set up for C++.

What is this? This is an example setup of cmake with google test. I got it working after consulting the google test primer, among other things. Hopefu

David Y. Zhang 302 Dec 10, 2022
Example of a gtest and cmake set up for C++ on Travis-CI.

What is this? This is an example setup of Travis-CI with cmake and google test. I finally got all three working together nicely with the help of dmono

Gunnar 41 Apr 30, 2021
A minimal CMake template for Qt 5 & 6 projects

Minimal CMake Template for Qt 6 Projects This project is updated for Qt 6. Visit qt5 branch if you are looking for the Qt 5 template. This is a minima

Vincent Lee 180 Sep 21, 2022
Installation example for a C++ project (Windows) with Cmake.

CMakeInstallExample Installation example for a C++ project (Windows) with Cmake. Contents This project demonstrates how to use cmake with cpack to gen

Paul T 30 Jan 3, 2023
Example project which demonstrates various CMake features.

CMake example Example project which demonstrates various CMake features. CDash testing dashboard (probably empty but you can submit your test result t

Radovan Bast 142 Nov 4, 2022
Tutorial/Example to deal with modern cmake.

modern_cmake Tutorial/Example to deal with modern cmake. This tutorial assume that you already know how to write a CMakeLists.txt Introduction This re

Marc Schweitzer 24 Nov 14, 2022