The project provides a set of macros to help bootstrap the creation of new projects.
A typical top level CMakeLists.txt file starts with these lines:
# 1
cmake_minimum_required(VERSION 3.0.0)
# 2
project("ProjName" VERSION "0.0.1" LANGUAGES C CXX)
# 3
list (APPEND CMAKE_MODULE_PATH "$ENV{CMAKE_MODULE_PATH}")
IF(WIN32)
string(REPLACE "\\" "/" CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}")
ENDIF()
# 4
include(pile_support)
It declares minimum CMake version (1) and provides a name for the project using standard project CMake command (2). This defines following variables with obvious content:
By default Cmake does not inspect the content of CMAKE_MODULE_PATH environment variable, thus forcing the user to employ the -D... command line option. If such an environment variable was defined we can make use of it using script in 3; we take into account the fact that CMake expects it to have forward-slashes as path delimiters even in Windows environments.
Previous point is important because we need a way to find pile_support CMake script (4). It will make sure to include all other CMake helpers provided by the project.
The main part of the top-level CMake script has following format:
pileProject("1")
pileProjectCommon()
# add sub-directories here ...
pileProjectEnd()
The pileProject macro adds a number of variables:
The pileProjectCommon invokes all common macros listed below. The user may choose to use only a subset of these macros.
The pileProjectEnd looks for a configuration file
called config.h.in and, if it exists, uses the
standard CMake
configure_file
command on it.
If a Doxyfile.in file exists
and the user enabled appropriate option
it is also run through same standard mechanism, Doxygeen is located
and a target is created for building the documentation.
The macro also includes CPack, so all relevant variables should be
assigned values before the invocation.