Skip to content
A set of cmake modules to assist in building code
Branch: master
Clone or download
henryiii Merge pull request #1 from Maxopoly/patch-2
Fix broken link in README
Latest commit 7fe259a Sep 9, 2018
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore Initial commit Mar 22, 2017
AddCLI.cmake Adding correct location for CLI11 Mar 30, 2017
AddGoogleTest.cmake Using FetchContent if avaiable Apr 2, 2018
AddHydra.cmake Better Intel support Apr 14, 2017
AddMinuit2.cmake Updates from GooFit Apr 19, 2017
AddPybind.cmake Updates from GooFit Apr 19, 2017
AddRang.cmake Updates from GooFit Apr 19, 2017
AddThrust.cmake Nicer output message Mar 27, 2017
CCache.cmake Fix CCache Mar 23, 2018
CUDA.cmake Updates to fix CUDA.cmake Mar 28, 2018
CodeCoverage.cmake Adding Find and Add modules Mar 22, 2017 Adding Find and Add modules Mar 22, 2017
DownloadProject.cmake Adding Find and Add modules Mar 22, 2017
FindROOT.cmake Removing ROOT::ROOT since ROOT::Libraries is the new version May 2, 2018
FindThrust.cmake Adding Find and Add modules Mar 22, 2017
LICENSE Update LICENSE Oct 26, 2017
PatchOpenMPApple.cmake Support for newest FindOpenMP Mar 8, 2018 Fix broken link in README Sep 8, 2018
select_compute_arch.cmake Fix bug in script for current CMakes Apr 12, 2018

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- "" | 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.


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)

enable_testing() # Must be in main file

include(AddGoogleTest) # Could be in /tests/CMakeLists.txt

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)


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/ to set your PATH and other useful variables. Then your CMakeLists.txt should look like:

cmake_minimum_required(VERSION 3.4)
project(MyProject CXX)

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:


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)


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

You can’t perform that action at this time.