A set of cmake modules to assist in building code

Related tags

Build Systems cmake
Overview

CMake 3 Tools

Warning: These tools are being replaced by the Modern CMake. Some of the tools are still being maintained for now, but new projects should check that repository first.

A set of CMake modules to assist in building code, with some tools for common general use packages and a few High Energy Physics packages. These tools are built around modern CMake (See The Ultimate Guide to Modern CMake), which allows clean, simple user CMake files. Although modern CMake is still a little odd in a few places, it is relatively clean and descriptive.

Installing CMake 3 anywhere

CMake is incredibly easy to install. The following line will install the latest 3.7.2 on Linux to your .local directory:

wget -qO- "https://cmake.org/files/v3.7/cmake-3.7.2-Linux-x86_64.tar.gz" | tar --strip-components=1 -xz -C ~/.local

If you don't want to put this in the .local directory, simply replace with any pre-existing directory, and add <directory>/bin to your PATH. See the other files in CMake downloads to find similar installers for Mac and Windows, as well as the latest development versions.

AddGoogleTest

This is a downloader for GoogleTest, based on the excellent DownloadProject tool. Downloading a copy for each project is the recommended way to use GoogleTest (so much so, in fact, that they have disabled the automatic CMake install target), so this respects that design decision. This method downloads the project at configure time, so that IDE's correctly find the libraries. Using it is simple:

cmake_minimum_required(VERSION 3.4)
project(MyProject CXX)
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)

enable_testing() # Must be in main file

include(AddGoogleTest) # Could be in /tests/CMakeLists.txt
add_executable(SimpleTest SimpleTest.cu)
add_gtest(SimpleTest)

Note: add_gtest is just a macro that adds gtest, gmock, and gtest_main, and then runs add_test to create a test with the same name:

target_link_libraries(SimpleTest gtest gmock gtest_main)
add_test(SimpleTest SimpleTest)

FindROOT

The following is an example of a CMakeLists.txt file that will build a project using ROOT. Clone the repository to your project's cmake folder, or use git submodule add if you are already using git. The root-config tool should be in your PATH; if is not, please run source /my/root/install/bin/thisroot.sh to set your PATH and other useful variables. Then your CMakeLists.txt should look like:

cmake_minimum_required(VERSION 3.4)
project(MyProject CXX)
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)

find_package(ROOT 6 REQUIRED COMPONENTS Minuit)

add_executable(MyExecutable MySourceFile.cpp)
target_link_libraries(MyExecutable ROOT::ROOT ROOT::Minuit)

In most cases, you should specify the C++ version (ROOT sets the compiler and linker flags needed, so you can ignore it if using a ROOT target). In CMake < 3.8, that looks like this:

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

If you are using CMake 3.8 (not yet released), you could replace the C++11 selection code with the following line right at the end:

target_compile_features(MyExecutable PUBLIC cxx_std_11)

AddHydra

See the example repository (under development) for an example of the CMake 3.8 AddHydra module.

You might also like...
A simple CMake utility for building and deploying Qt based applications on Android without QtCreator

Qt Android CMake utility What it is When using Qt for Android development, QMake & QtCreator is the only sane option for compiling and deploying. But

CMake module for building IDL files with MIDL and generating CLR DLL using Tlbimp

FindIDL CMake module for building IDL files with MIDL and generating CLR DLL using Tlbimp. Introduction Requirements Usage find_package() add_idl() ad

CMake module for building Windows Installer packages with WiX toolset

FindWiX CMake module for building Windows Installer packages with WiX toolset Introduction Requirements Usage find_package() wix_add_project() WiX com

CMake find module for Intel Threading Building Blocks

FindTBB Module FindTBB is a CMake find package module for Intel® Threading Building Blocks (TBB). Usage The signature of the TBB find module in CMake

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

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

📦 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 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-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

Owner
null
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

HPC 82 Oct 25, 2022
CMake modules to help use sanitizers

sanitizers-cmake CMake module to enable sanitizers for binary targets. Include into your project To use FindSanitizers.cmake, simply add this reposito

Matt Arsenault 292 Nov 18, 2022
CMake Community Modules

CMake Community Modules The CMake Community Modules are CMake modules created and maintained by the community. This repository's main product is the C

Edgar 1 May 12, 2022
Extra CMake Modules for YARP and friends

YCM Extra CMake Modules for YARP and friends Documentation Online documentation is available

Robotology 43 Oct 20, 2022
Extra modules and scripts for CMake.

Extra CMake Modules Introduction The Extra CMake Modules package, or ECM, adds to the modules provided by CMake, including ones used by find_package()

KDE GitHub Mirror 104 Nov 16, 2022
CMake modules for some scientific libraries

A collection of CMake modules, which can mostly be used independently. The utilities for writing robust Find* modules might be useful until CMake take

Jed Brown 82 Nov 4, 2022
Common CMake modules

CMake Modules This repository contains common CMake modules and a collection of find scripts to locate non-CMake dependencies. The recommended way to

Eyescale Software GmbH 144 Sep 21, 2022
Additional CMake functionality. Most of the modules are from Ryan Pavlik

Additional CMake functionality. Most of the modules are from Ryan Pavlik

Lars Bilke 444 Nov 12, 2022
Ryan's CMake Modules Collection

This is a collection of CMake modules that I've produced during the course of a variety of software development.

Ryan A. Pavlik 881 Nov 24, 2022
CMake scripts for building OpenSceneGraph third party libraries.

osg-3rdparty-cmake CMake scripts for building OpenSceneGraph third party libraries. These scripts can be used to build third party libraries from sour

Björn Blissing 154 Oct 13, 2022