CMake
In software development, CMake is cross-platform free and open-source software for build automation, testing, packaging and installation of software by using a compiler-independent method. CMake is not a build system but rather 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, Qt Creator, Ninja, Android Studio, Apple's Xcode, and Microsoft Visual Studio. It has minimal dependencies, requiring only a C++ compiler on its own build system. CMake is distributed as open-source software under  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. The project is funded by the United States National Library of Medicine as part of the Visible Human Project. It was partially inspired by pcmaker, which was made by Ken Martin and other developers to support the Visualization Toolkit (VTK). At Kitware, Bill Hoffman blended components of pcmaker with his own ideas, striving to mimic the functionality of Unix configure scripts. 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 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. 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 (optionally) place compiler outputs (such as object files) outside of the source tree. This enables multiple builds from the same source tree and cross-compilation. It also keeps the source tree separate, 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, 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, Xcode, and Eclipse CDT. It can also produce build scripts for MSBuild or NMake on Windows; Unix Make on Unix-like platforms such as Linux, macOS, and Cygwin; and Ninja 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, GNU GCC, MSVC, Oracle Developer Studio, and Intel C++ Compiler. Build process. The build of a program or library with CMake is a  two-stage process. First, standard build files 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 build files are configured depending on the used generator (e.g. "Unix Makefiles" for make). 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. Once the Makefile (or alternative) has been generated, build behavior can be fine-tuned via target properties (since version 3.1) or via -prefixed global variables. The latter is discouraged for target-only configurations because variables are also used to configure CMake itself and to set up initial defaults. Types of build targets. Depending on CMakeLists.txt configuration the build files may be either executables, libraries (e.g. , etc.), object file 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 headers 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: JSON strings. CMake supports extracting values into variables from JSON-data strings (since version 3.19). Internals. The executable programs CMake, CPack, and CTest are written in the C++ 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 markup. HTML pages and man pages are generated by the Sphinx documentation generator. Modules & 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): CPack. CPack is a packaging system for software distributions. It is tightly integrated with CMake but can function without it. It can be used to generate: Adoption. CMake has been very widely adopted among commercial, open source, and academic software projects. A few notable users include Netflix, Inria, MySQL, Boost (C++ libraries), KeePassXC, KDE/KDE Plasma 5, KiCAD, FreeCAD, Webkit, Blender 3D, Biicode, ReactOS, Apache QPid, the ATLAS experiment, and Second Life. Examples. Hello  World. The following source code files demonstrate how to build a simple hello world program written in C++ by using CMake. // hello.cpp int main() cmake_minimum_required(VERSION 3.5) project(HelloWorld CXX) add_executable(hello hello.cpp) Shell commands to run CMake on a Linux system (to be entered in the directory that contains the two above files): 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!")