User:Dahnielson/CMake

From MaratisWiki
Jump to: navigation, search

The CMake build system consist of instruction files named CMakeLists.txt in the source tree. These CMakeLists.txt files uses macro variables and commands to define how something should be built and installed. A build system can consist of a single CMakeLists.txt file or a hierarchy of files in sub-directories. How the CMakeLists.txt files are organised and laid out is very much up to the author. Files in subdirectories inherit their parents variables and can redefine them for themselves and their children but not for anyone else. I've used a very common organisation that consist of three levels of responsibility: Root, Branch and Leaf.

Root

The root CMakeLists.txt file should contain all that belong to configuring the specific build. That means handling configuration options and platform specific issues. This is where the majority of all variables are set, either directly or by calling macro commands that figure them out for us.

Example: Maratis/CMakeLists.txt

Branch

Branch CMakeLists.txt files are generally the next level below root and placed in one or more levels of subdirectories. Their only responsibility is to include subdirectories, possibly using conditionals (e.g. to include a subdirectory with platform specific build targets).

Example: Maratis/MSDK/CMakeLists.txt

Leaf

Leaf CMakeLists.txt files finally contain the actual build targets. Instructions on how to build an executable or a library. These should be written with the assumption that everything has already been figured out -- all variables are set correctly by the configuration in at root and the target was correctly selected by the branch conditional and indeed should be built.

Example: Maratis/MSDK/MCore/CMakeLists.txt

See also

  • CMake Documentation [1]
  • CMake Tutorial [2]
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox