====== CMake ======
This tutorial [[https://cmake.org/cmake-tutorial/|link]] shows how to
autogenerate header files that contain variables whose values get populated by
CMake. These autogenerated header files go into the source folder.
===== Basic CMakeLists.txt =====
Here is the most basic ''%%CMakeLists.txt%%'' file which contains the minimum needed for
successful compilation.
cmake_minimum_required (VERSION 2.6)
project (Tutorial)
add_executable(Tutorial tutorial.cxx)
===== Adding Version Number and Configured Header File =====
We make use of the ''%%configure_file%%'' CMake function which takes in an input file and
generates an output file whereever we want. You write the input file with variables
that you want to get fleshed out by CMake. The variable syntax is ''%%@VAR@%%''
or ''%%${VAR}%%''.
===== Adding a Library =====
Add a libary by adding code in its own directory. I then added a
CMakeLists.txt file in that directory which has one line that says
add_library(MathFunctions mysqrt.cxx)
===== Making Libraries Optional =====
By making use of a cool CMake feature we can set libraries to be optional, and create
c++ code that selectively compiles with blocks of code by us simply flipping switches
in the CMake configurations. We do this by my making use of CMake's ability to
generate header files. We then use conditionals in our blocks of code that rely on
whether or not something has been defined.
We also use ''%%#cmakedefine%%'' to conditionally define stuff in our header depending on an
option was set in CMake configuration. Really cool shit.
===== Installing and Testing =====
We will make install rules by setting up the library and header files to be installed
by adding the install rules in the ''%%CMakeLists.txt%%'' file.
To make a CMake debugabe target put this in the CMake lists file:
set(CMAKE_BUILD_TYPE Debug)