CMake
   HOME

TheInfoList



OR:

In
software development Software development is the process of conceiving, specifying, designing, programming, documenting, testing, and bug fixing involved in creating and maintaining applications, frameworks, or other software components. Software development invol ...
, CMake is
cross-platform In computing, cross-platform software (also called multi-platform software, platform-agnostic software, or platform-independent software) is computer software that is designed to work in several computing platforms. Some cross-platform software r ...
free and open-source software Free and open-source software (FOSS) is a term used to refer to groups of software consisting of both free software and open-source software where anyone is freely licensed to use, copy, study, and change the software in any way, and the source ...
for build automation,
testing An examination (exam or evaluation) or test is an educational assessment intended to measure a test-taker's knowledge, skill, aptitude, physical fitness, or classification in many other topics (e.g., beliefs). A test may be administered verba ...
,
packaging Packaging is the science, art and technology of enclosing or protecting products for distribution, storage, sale, and use. Packaging also refers to the process of designing, evaluating, and producing packages. Packaging can be described as a co ...
and
installation Installation may refer to: * Installation (computer programs) * Installation, work of installation art * Installation, military base * Installation, into an office, especially a religious (Installation (Christianity) Installation is a Christian li ...
of software by using a
compiler In computing, a compiler is a computer program that translates computer code written in one programming language (the ''source'' language) into another language (the ''target'' language). The name "compiler" is primarily used for programs that ...
-independent method. CMake is not a build system itself; it generates another system's build files. It supports directory hierarchies and applications that depend on multiple libraries. It is used in conjunction with native build environments such as
Make Make or MAKE may refer to: * Make (magazine), a tech DIY periodical *Make (software), a software build tool *Make, Botswana, in the Kalahari Desert *Make Architects Make Architects is an international architecture practice headquartered in Londo ...
,
Qt Creator Qt Creator is a cross-platform C++, JavaScript and QML integrated development environment (IDE) which simplifies GUI application development. It is part of the SDK for the Qt GUI application development framework and uses the Qt API, which e ...
,
Ninja A or was a covert agent or mercenary in feudal Japan. The functions of a ninja included reconnaissance In military operations, reconnaissance or scouting is the exploration of an area by military forces to obtain information about enem ...
,
Android Studio Android Studio is the official integrated development environment (IDE) for Google's Android operating system, built on JetBrains' IntelliJ IDEA software and designed specifically for Android development. It is available for download on Windows ...
, Apple's
Xcode Xcode is Apple's integrated development environment (IDE) for macOS, used to develop software for macOS, iOS, iPadOS, watchOS, and tvOS. It was initially released in late 2003; the latest stable release is version 14.2, released on December 13, ...
, and
Microsoft Visual Studio Visual Studio is an integrated development environment (IDE) from Microsoft. It is used to develop computer programs including websites, web apps, web services and mobile apps. Visual Studio uses Microsoft software development platforms such a ...
. It has minimal dependencies, requiring only a
C++ C++ (pronounced "C plus plus") is a high-level general-purpose programming language created by Danish computer scientist Bjarne Stroustrup as an extension of the C programming language, or "C with Classes". The language has expanded significan ...
compiler on its own build system. CMake is distributed as
open-source software Open-source software (OSS) is computer software that is released under a license in which the copyright holder grants users the rights to use, study, change, and distribute the software and its source code to anyone and for any purpose. Op ...
under a permissive BSD-3-Clause license.


History

CMake development began in 1999 in response to the need for a cross-platform build environment for the
Insight Segmentation and Registration Toolkit __NOTOC__ ITK is a cross-platform, open-source application development framework widely used for the development of image segmentation and image registration programs. Segmentation is the process of identifying and classifying data found in a dig ...
. The project is funded by the
United States National Library of Medicine The United States National Library of Medicine (NLM), operated by the United States federal government, is the world's largest medical library. Located in Bethesda, Maryland, the NLM is an institute within the National Institutes of Health. Its ...
as part of the
Visible Human Project The Visible Human Project is an effort to create a detailed data set of cross-sectional photographs of the human body, in order to facilitate anatomy visualization applications. It is used as a tool for the progression of medical findings, in which ...
. It was partially inspired by pcmaker, which was made by Ken Martin and other developers to support the Visualization Toolkit (VTK). At
Kitware __NOTOC__ Kitware, Inc. is a technology company headquartered in Clifton Park, New York. The company is involved in the research and development of open-source software in the fields of computer vision, medical imaging, visualization, 3D data publ ...
, Bill Hoffman blended components of pcmaker with his own ideas, striving to mimic the functionality of
Unix Unix (; trademarked as UNIX) is a family of multitasking, multiuser computer operating systems that derive from the original AT&T Unix, whose development started in 1969 at the Bell Labs research center by Ken Thompson, Dennis Ritchie, and ot ...
configure script A configure script is an executable script designed to aid in developing a program to be run on a wide number of different computers. It matches the libraries on the user's computer, with those required by the program before compiling it from its ...
s. CMake was first implemented in 2000 and further developed in 2001. Continued development and improvements were fueled by the incorporation of CMake into developers’ own systems, including the
VXL VXL, the Vision-something-Library, is a large collection of open source C++ libraries for computer vision. The idea of the naming is to replace X with one of many letters to obtain the smaller library names, i.e. G (VGL) is a geometry library, N ...
Project, the CABLE features added by Brad King, and GE Corporate R&D for support of DART. Additional features were created when VTK transitioned to CMake for its build environment and for supporting
ParaView ParaView is an open-source multiple-platform application for interactive, scientific visualization. It has a client–server architecture to facilitate remote visualization of datasets, and generates level of detail (LOD) models to maintain in ...
. Version 3.0 was released in June 2014. It has been described as the beginning of "Modern CMake". Experts now advise to avoid variables in favor of ''targets'' and ''properties''. The commands , , , that were at the core of CMake 2 should now be replaced by target-specific commands.


Features

A key feature is the ability to place compiler outputs (such as object files) outside of the source tree. This enables multiple builds from the same source tree and
cross-compilation A cross compiler is a compiler capable of creating executable code for a platform other than the one on which the compiler is running. For example, a compiler that runs on a PC but generates code that runs on an Android smartphone is a cross ...
. Placing the compiler outputs outside of the source tree keeps the tree separate from the build files, ensuring that removing a build directory will not remove the source files. However, the users aren't protected in any way from removing the original source code folder.


Flexible project structure

CMake can locate system-wide and user-specified executables, files, and libraries. These locations are stored in a
cache Cache, caching, or caché may refer to: Places United States * Cache, Idaho, an unincorporated community * Cache, Illinois, an unincorporated community * Cache, Oklahoma, a city in Comanche County * Cache, Utah, Cache County, Utah * Cache County ...
, which can then be tailored before generating the target build files. The cache can be edited with a graphical editor, which is shipped with CMake. Complicated directory hierarchies and applications that rely on several libraries are well supported by CMake. For instance, CMake is able to accommodate a project that has multiple toolkits, or libraries that each have multiple directories. In addition, CMake can work with projects that require executables to be created before generating code to be compiled for the final application. Its open-source, extensible design allows CMake to be adapted as necessary for specific projects.


IDE configuration support

CMake can generate project files for several popular IDEs, such as
Microsoft Visual Studio Visual Studio is an integrated development environment (IDE) from Microsoft. It is used to develop computer programs including websites, web apps, web services and mobile apps. Visual Studio uses Microsoft software development platforms such a ...
,
Xcode Xcode is Apple's integrated development environment (IDE) for macOS, used to develop software for macOS, iOS, iPadOS, watchOS, and tvOS. It was initially released in late 2003; the latest stable release is version 14.2, released on December 13, ...
, and Eclipse CDT. It can also produce build scripts for MSBuild or NMake on Windows; Unix Make on Unix-like platforms such as
Linux Linux ( or ) is a family of open-source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991, by Linus Torvalds. Linux is typically packaged as a Linux distribution, which ...
,
macOS macOS (; previously OS X and originally Mac OS X) is a Unix operating system developed and marketed by Apple Inc. since 2001. It is the primary operating system for Apple's Mac computers. Within the market of desktop and lapt ...
, and
Cygwin Cygwin ( ) is a POSIX-compatible programming and runtime environment that runs natively on Microsoft Windows. Under Cygwin, source code designed for Unix-like operating systems may be compiled with minimal modification and executed. The Cygwin in ...
; and
Ninja A or was a covert agent or mercenary in feudal Japan. The functions of a ninja included reconnaissance In military operations, reconnaissance or scouting is the exploration of an area by military forces to obtain information about enem ...
on both Windows and Unix-like platforms.


Compiler feature detection

CMake allows specification of features that the compiler is required to support in order to get the target program or library compiled.


Compilers

CMake supports an extensive list of compilers, including: Apple Clang,
Clang Clang is a compiler front end for the C, C++, Objective-C, and Objective-C++ programming languages, as well as the OpenMP, OpenCL, RenderScript, CUDA, and HIP frameworks. It acts as a drop-in replacement for the GNU Compiler Collection (GCC), ...
, GNU GCC,
MSVC Microsoft Visual C++ (MSVC) is a compiler for the C, C++ and C++/CX programming languages by Microsoft. MSVC is proprietary software; it was originally a standalone product but later became a part of Visual Studio and made available in both tri ...
,
Oracle Developer Studio Oracle Developer Studio, formerly named Oracle Solaris Studio, Sun Studio, Sun WorkShop, Forte Developer, and SunPro Compilers, is Oracle Corporation's flagship software development product for the Solaris (operating system), Solaris and Linux o ...
, and
Intel C++ Compiler Intel oneAPI DPC++/C++ Compiler and Intel C++ Compiler Classic are Intel’s C, C++, SYCL, and Data Parallel C++ (DPC++) compilers for Intel processor-based systems, available for Windows, Linux, and macOS operating systems. Overview Intel o ...
.


Packaging system

Even though CMake is not a
package manager A package manager or package-management system is a collection of software tools that automates the process of installing, upgrading, configuring, and removing computer programs for a computer in a consistent manner. A package manager deals wi ...
, it provides basic modules (see CPack) functions for installing binaries and package information declared by the script to be used by consumer CMake projects. The package may also be packed into an
archive file In computing, an archive file is a computer file that is composed of one or more files along with metadata. Archive files are used to collect multiple data files together into a single file for easier portability and storage, or simply to compress ...
for package manager or
installer Installation (or setup) of a computer program (including device drivers and plugins), is the act of making the program ready for execution. Installation refers to the particular configuration of a software or hardware with a view to making it us ...
supported by a target platform. Third-party packages may also be imported via configured CMake files which are either provided by the same third-party or created manually.


GUI

Cmake is shipped with built-in
ncurses ncurses (new curses) is a programming library providing an application programming interface (API) that allows the programmer to write text-based user interfaces (TUI) in a terminal-independent manner. It is a toolkit for developing "GUI-like" ...
program that can be used to configure projects via command-line interface.


Build process

The build of a program or library with CMake is a two-stage process. First, standard build files (usually scripts) are created (generated) from configuration files (CMakeLists.txt) which are written in CMake language. Then the platform's native build tools (native toolchain) are used for actual building of programs. The scripts generated by CMake are further used to produce actual binary files or other output files.


Generators

The build files are configured depending on the used generator (e.g. ''Unix Makefiles'' for
make Make or MAKE may refer to: * Make (magazine), a tech DIY periodical *Make (software), a software build tool *Make, Botswana, in the Kalahari Desert *Make Architects Make Architects is an international architecture practice headquartered in Londo ...
) and associated toolchain files. Advanced users can also create and incorporate additional makefile generators to support their specific compiler and OS needs. Generated files are typically placed (by using 's flag) into a folder outside of the source's one (out of source build), e.g., . Each build project in turn contains its own file and directory in every project (sub-)directory of included by the command, helping to avoid or speed up regeneration when it is run repeatedly. The generation process and the output could fine-tuned via target properties. Previously it was done via -prefixed global variables that are also used to configure CMake itself and to set up initial defaults. The older approach is discouraged now.


Types of build targets

Depending on CMakeLists.txt configuration the build files may be either executables, libraries (e.g. , etc.),
object file An object file is a computer file containing object code, that is, machine code output of an assembler or compiler. The object code is usually relocatable, and not usually directly executable. There are various formats for object files, and the ...
libraries or pseudo-targets (including aliases). CMake can produce object files that can be linked against by executable binaries/libraries, avoiding dynamic (run-time) linking and using static (compile-time) linking instead. This enables flexibility in configuration of various optimizations. Build dependencies may be determined automatically.


Precompiled headers

It's possible to generate
precompiled header In computer programming, a precompiled header (PCH) is a ( C or C++) header file that is compiled into an intermediate form that is faster to process for the compiler. Usage of precompiled headers may significantly reduce compilation time, espe ...
s by using CMake since version 3.6.


Language


CMakeLists.txt

CMake has a relatively simple interpreted, imperative scripting language. It supports variables, string manipulation methods, arrays, function/macro declarations, and module inclusion (importing). CMake Language commands (or directives) are read by from a file named . This file specifies the source files and build parameters, which CMake will place in the project's build specification (such as a Makefile). Additionally, -suffixed files can contain scripts used by CMake. To generate a project's build files, one invokes in terminal and specifies the directory that contains . This file contains one or more commands in the form of .


Command syntax

The arguments of the commands are whitespace-separated and can include keywords to separate groups of arguments. Commands can take keywords. For instance, in the command the keyword is . It serves as a delimiter between the list of source files and some other options. Examples of commands that CMake offers to specify targets and their dependencies and which serve as the starting point of the CMakeLists.txt: * — declares an executable binary target with sources (depend on language chosen) to be built * — the same but for a library * — adds dependencies etc.


JSON strings

CMake supports extracting values into variables from
JSON JSON (JavaScript Object Notation, pronounced ; also ) is an open standard file format and data interchange format that uses human-readable text to store and transmit data objects consisting of attribute–value pairs and arrays (or other ser ...
-data strings (since version 3.19).


Internals

The executable programs CMake, CPack, and CTest are written in the
C++ C++ (pronounced "C plus plus") is a high-level general-purpose programming language created by Danish computer scientist Bjarne Stroustrup as an extension of the C programming language, or "C with Classes". The language has expanded significan ...
programming language. Much of CMake's functionality is implemented in modules that are written in the CMake language. Since release 3.0, CMake's documentation uses
reStructuredText reStructuredText (RST, ReST, or reST) is a file format for textual data used primarily in the Python programming language community for technical documentation. It is part of the Docutils project of the Python Doc-SIG (Documentation Special Inte ...
markup. HTML pages and man pages are generated by the
Sphinx A sphinx ( , grc, σφίγξ , Boeotian: , plural sphinxes or sphinges) is a mythical creature with the head of a human, the body of a lion, and the wings of a falcon. In Greek tradition, the sphinx has the head of a woman, the haunches of ...
documentation generator.


Modules and tools

CMake ships with numerous modules and tools. These facilitate work such as finding dependencies (both built-in and external, e.g. modules), testing the toolchain environment and executables, packaging releases ( module and command), and managing dependencies on external projects ( module): * ctest — is used for target testing commands specified by CMakeLists.txt * ccmake and cmake-gui — tweaks and updates configuration variables intended for the native build system * cpack — helps to package software


CPack

CPack is a
packaging Packaging is the science, art and technology of enclosing or protecting products for distribution, storage, sale, and use. Packaging also refers to the process of designing, evaluating, and producing packages. Packaging can be described as a co ...
system for software distributions. It is tightly integrated with CMake but can function without it. It can be used to generate: * Linux
RPM Revolutions per minute (abbreviated rpm, RPM, rev/min, r/min, or with the notation min−1) is a unit of rotational speed or rotational frequency for rotating machines. Standards ISO 80000-3:2019 defines a unit of rotation as the dimensionl ...
, deb, and
gzip gzip is a file format and a software application used for file compression and decompression. The program was created by Jean-loup Gailly and Mark Adler as a free software replacement for the compress program used in early Unix systems, and in ...
packages (for both
binaries A binary file is a computer file that is not a text file. The term "binary file" is often used as a term meaning "non-text file". Many binary file formats contain parts that can be interpreted as text; for example, some computer document fil ...
and
source code In computing, source code, or simply code, is any collection of code, with or without comments, written using a human-readable programming language, usually as plain text. The source code of a program is specially designed to facilitate the wo ...
). * NSIS files (for
Microsoft Windows Windows is a group of several proprietary graphical operating system families developed and marketed by Microsoft. Each family caters to a certain sector of the computing industry. For example, Windows NT for consumers, Windows Server for serv ...
). *
macOS macOS (; previously OS X and originally Mac OS X) is a Unix operating system developed and marketed by Apple Inc. since 2001. It is the primary operating system for Apple's Mac computers. Within the market of desktop and lapt ...
packages.


Adoption

CMake has been very widely adopted among commercial, open source, and academic software projects. A few notable users include
Android NDK Code written in C/C++ can be compiled to ARM, or x86 native code (or their 64-bit variants) using the Android Native Development Kit (NDK). The NDK uses the Clang compiler to compile C/C++. GCC was included until NDK r17, but removed in r18 in ...
,
Netflix Netflix, Inc. is an American subscription video on-demand over-the-top streaming service and production company based in Los Gatos, California. Founded in 1997 by Reed Hastings and Marc Randolph in Scotts Valley, California, it offers a fil ...
,
Inria The National Institute for Research in Digital Science and Technology (Inria) () is a French national research institution focusing on computer science and applied mathematics. It was created under the name ''Institut de recherche en informatiq ...
,
MySQL MySQL () is an open-source relational database management system (RDBMS). Its name is a combination of "My", the name of co-founder Michael Widenius's daughter My, and "SQL", the acronym for Structured Query Language. A relational database o ...
, Boost (C++ libraries),
KeePassXC KeePassXC is a free and open-source password manager. It started as a community fork of KeePassX (itself a cross-platform port of KeePass). It is built using Qt5 libraries, making it a multi-platform application which can be run on Linux, Wi ...
,
KDE KDE is an international free software community that develops free and open-source software. As a central development hub, it provides tools and resources that allow collaborative work on this kind of software. Well-known products include the ...
,
KiCAD KiCad ( ) is a free software suite for electronic design automation (EDA). It facilitates the design and simulation of electronic hardware. It features an integrated environment for schematic capture, PCB layout, manufacturing file viewing, ...
,
FreeCAD FreeCAD is a general-purpose parametric 3D computer-aided design (CAD) modeler and a building information modeling (BIM) software application with finite element method (FEM) support. It is intended for mechanical engineering product design bu ...
,
Webkit WebKit is a browser engine developed by Apple and primarily used in its Safari web browser, as well as on the iOS and iPadOS version of any web browser. WebKit is also used by the BlackBerry Browser, PlayStation consoles beginning from the PS ...
,
Blender A blender (sometimes called a mixer or liquidiser in British English) is a kitchen appliance, kitchen and laboratory appliance used to mix, crush, purée or emulsion, emulsify food and other substances. A stationary blender consists of a blender ...
, Biicode,
ReactOS ReactOS is a free and open-source operating system for amd64/i686 personal computers intended to be binary-compatible with computer programs and device drivers made for Windows Server 2003 and later versions of Windows. ReactOS has been noted a ...
, Apache QPid, the
ATLAS experiment ATLAS is the largest general-purpose particle detector experiment at the Large Hadron Collider (LHC), a particle accelerator at CERN (the European Organization for Nuclear Research) in Switzerland. The experiment is designed to take advantage ...
, and
Second Life ''Second Life'' is an online multimedia platform that allows people to create an avatar for themselves and then interact with other users and user created content within a multi player online virtual world. Developed and owned by the San Fra ...
.


Examples


Hello world

The following source code files demonstrate how to build a simple
hello world ''Hello'' is a salutation or greeting in the English language. It is first attested in writing from 1826. Early uses ''Hello'', with that spelling, was used in publications in the U.S. as early as the 18 October 1826 edition of the ''Norwich C ...
program written in C++ by using CMake. // hello.cpp #include int main() # CMakeLists.txt cmake_minimum_required(VERSION 3.5) project(HelloWorld CXX) add_executable(hello hello.cpp)
Shell Shell may refer to: Architecture and design * Shell (structure), a thin structure ** Concrete shell, a thin shell of concrete, usually with no interior columns or exterior buttresses ** Thin-shell structure Science Biology * Seashell, a hard o ...
commands to run CMake on a
Linux Linux ( or ) is a family of open-source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991, by Linus Torvalds. Linux is typically packaged as a Linux distribution, which ...
system (to be entered in the directory that contains the two files above): cmake -B build . # Configure the build directory. cmake --build build # Build the program in the build directory. ./build/hello # Run the program (outputs "Hello, world!")


See also

* *
configure script A configure script is an executable script designed to aid in developing a program to be run on a wide number of different computers. It matches the libraries on the user's computer, with those required by the program before compiling it from its ...
*
Monorepo In version-control systems, a monorepo ("mono" meaning 'single' and "repo" being short for ' repository') is a software-development strategy in which the code for a number of projects is stored in the same repository. This practice dates back to a ...
*
Qmake qmake is a utility that automates the generation of makefiles. Makefiles are used by the program make to build executable programs from source code; therefore qmake is a make-makefile tool, or ''makemake'' for short. The makefiles that qmake pro ...


References


External links

* * {{GitHub, Kitware/CMake
CMake Online Documentation
*
C++Now 2017: Daniel Pfeifer "Effective CMake"
on YouTube 2000 software Build automation Compiling tools Software that uses Qt Software using the BSD license