Differences

This shows you the differences between two versions of the page.

Link to this comparison view

cmake [2019/03/31 14:49] (current)
Line 1: Line 1:
 +====== 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.
 +
 +<code cmake>
 +cmake_minimum_required (VERSION 2.6)
 +project (Tutorial)
 +add_executable(Tutorial tutorial.cxx)
 +</​code>​
 +
 +===== 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 ''​%%@[email protected]%%''​
 +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 
 +
 +<code cmake>
 +add_library(MathFunctions mysqrt.cxx)
 +</​code>​
 +
 +===== 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:
 +<code cmake>
 +set(CMAKE_BUILD_TYPE Debug)
 +</​code>​
 +
  
  • cmake.txt
  • Last modified: 2019/03/31 14:49
  • (external edit)