-
Notifications
You must be signed in to change notification settings - Fork 9
CMake Primer
CMake is a replacement for Makefiles aimed at c++ projects. It's what's known as a build system. If you have worked with MINERvA's Gaudi/AnaTool components, CMake does the same job as CMT. CMake has a few advantages over writing Makefiles yourself:
- It's platform independent. CMake's higher level commands are supposed to know how to do their jobs equally effectively on Ubuntu, OS X, and Windows 10. You don't need to worry about how a Windows user should
cd
into a build subdirectory. - It has higher level commands. CMake macros do things like
add_executable
instead of callingg++
directly. CMake versions after version 3 are better about this than older versions.
- Install dependencies
- Make a working directory. Mine is called
MINERvA101_2021/
- Download the complete source from MinervaExpt:
git clone https://github.com/MinervaExpt/MINERvA-101-Cross-Section.git src #Makes a src subdirectory for you
- Make a build directory:
mkdir opt && cd opt && mkdir build && cd build && mkdir MINERvA-101-Cross-Section && cd MINERvA-101-Cross-Section #opt for optimized build as opposed to debug build
- Run cmake to generate a build system:
cmake ../../../src -DCMAKE_INSTALL_PREFIX=`pwd`/.. -DCMAKE_BUILD_TYPE=Release
You may have to tell CMake about dependencies with additional flags like this example for PlotUtils: -DPlotUtils_DIR=/path/to/PlotUtils/opt/lib/cmake
. Remember to put any such dependencies on your LD_LIBRARY_PATH
to run the executables you build here!
6. Compile and install: make install
For debugging, produce a debug
build by creating a second build directory and replacing step 5 with: cmake ../../src -DCMAKE_INSTALL_PREFIX=`pwd`/.. -DCMAKE_BUILD_TYPE=Debug
. This will turn on assert()
s and include debug symbols that gdb
and valgrind
use to tell you line numbers of memory errors. You probably want to rebuild each dependency in debug mode too to maximize helpfulness of the debugger.