CMake

Uses your system voice; voice and rate in settings.

Q1023904Snapshot

≈ 7 min read

Names in other languages

  • DeutschCMake
  • EnglishCMake
  • FrançaisCMake
  • ItalianoCMake
  • 한국어CMake
  • PortuguêsCMake
  • РусскийCMake
  • 中文CMake

Article bodies are English and are not machine-translated. A name in another language is not a translation of the article.

CMake is a free, cross-platform, software development tool for building applications via compiler-independent instructions. It also can automate testing, packaging and installation. It runs on a variety of platforms and supports many programming languages. As a meta-build tool, CMake configures native build tools which in turn build the codebase. CMake generates configuration files for other build tools based on CMake-specific configuration files. The other tools are responsible for more directly building, using the generated files. A single set of CMake-specific configuration files can be used to build a codebase using the native build tools of multiple platforms. Notable native build tools supported by CMake include: Make, Qt Creator, Ninja, Android Studio, Xcode, and Visual Studio. CMake is distributed as free and open-source software under a permissive BSD-3-Clause license.

CMake is a free, cross-platform, software development tool for building applications via compiler-independent instructions. It also can automate testing, packaging and installation. It runs on a variety of platforms and supports many programming languages. As a meta-build tool, CMake configures native build tools which in turn build the codebase. CMake generates configuration files for other build tools based on CMake-specific configuration files. The other tools are responsible for more directly building, using the generated files. A single set of CMake-specific configuration files can be used to build a codebase using the native build tools of multiple platforms. Notable native build tools supported by CMake include: Make, Qt Creator, Ninja, Android Studio, Xcode, and Visual Studio. CMake is distributed as free and open-source software under a permissive BSD-3-Clause license. ==History== Initial development began in 1999 at Kitware with funding from the United States National Library of Medicine as part of the Visible Human Project. CMake was first released in 20001. CMake was developed to support building the Insight Segmentation and Registration Toolkit (ITK) for multiple platforms. Stated goals included addressing weaknesses while maintaining strengths of contemporary tools such as autoconf and libtool, and to align with state of the art build technology of the time: configure scripts and Make files for Unix platforms, and Visual Studio project files for Windows. CMake was inspired by multiple contemporary tools. pcmaker developed by Ken Martin and others to support building the Visualization Toolkit (VTK) converted Unix Make files into NMake files for building on Windows. gmake supported Unix and Windows compilers, but its design led to issues that were hard to resolve. Both tools were working examples of a build tool that supported both Unix and Windows, but they suffered from a serious flaw: they required Windows developers to use the command line even though many prefer to use an integrated development environment (IDE) such as Visual Studio. CMake was to provide similar cross-platform support but to better satisfy the preferences of the developers on each platform. The design goals of the first version included: Depend only on host C++ compiler; no other third-party tools or libraries required Generate Visual Studio project files (as well as Unix files) Support building targets: program, static library, shared library Run build-time code generators Support separate directory trees for source vs. build files Support host computer capability introspection Support automatic dependency scanning of C/C++ header files All features must work consistently and equally well on all supported platforms For various reasons, CMake developers chose to develop a scripting language for CMake instead of using Tcl a popular language for building at the time. Use of Tcl would have then added a dependency to the host machine which is counter to the goal of no dependencies other than a compiler. Also, Tcl was not well supported on Windows and some Unix systems at the time of initial development. Subsequent 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 (which is deprecated since 3.7.). Additional features were created when VTK transitioned to CMake for its build environment and for supporting ParaView. Version 3.0 was released in June 20141. 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. ==Name== CMake developer Brad King stated that "the 'C' in CMake stands for 'cross-platform . ==Features== ==Implementation== The CMake scripting language is implemented via Yacc and Lex generators. The executable programs CMake, CPack, and CTest are written in C++. Much of CMake's functionality is implemented in modules written in the CMake language. CMake documentation (since release 3.0) uses reStructuredText markup. HTML pages and man pages are generated by the Sphinx documentation generator. ==Additional tools== CMake ships with numerous script files and development tools that facilitate tasks such as finding dependencies (both built-in and external, e.g. modules), testing the toolchain environment and executables, packaging releases (CPack), and managing dependencies on external projects ( module). Additional development tools include: ccmake and cmake-gui — for updating configuration variables intended for a native build tool CPack — for packaging software as Linux RPM, deb, and gzip packages, NSIS files (for Windows), and macOS packages CTest and CDash — for software testing and reporting ==Build process== Building via CMake has two major stages. First, native build tool configuration files are generated from CMake configuration files written in the CMake scripting language. The command line syntax is where is a directory that contains a file. Then, the native build tools are invoked either via CMake ( ) or directly via the native tool's interface. The native build tools use the generated files. ==Examples== ===Hello world=== The following demonstrates configuring CMake to build a hello world program written in C++, and using CMake to build the program. : include int main() { std::println("Hello, world!"); return 0; } : cmake_minimum_required(VERSION 3.22) project(HelloWorld CXX) add_executable(hello hello.cpp) To build via CMake, first cd to the directory containing the two files above. Then, generate the native build config files via the cross-platform CMake command: cmake -B out . All generated files will be under the directory out as specified via . Then, build via the native build tool as supported thru CMake: cmake --build out The program is then available for running. Via Bash, the command is like . On Windows, the output file ends with . ===Include=== This example demonstrates configuring the preprocessor include path. : include include "hello.hpp" int main() { for (int i = 0; i : pragma once constexpr int TIMES = 10; : cmake_minimum_required(VERSION 3.22) project(HelloWorld CXX) add_executable(hello hello.cpp) target_include_directories(hello PRIVATE ${PROJECT_SOURCE_DIR}) ==See also== ==References== ==External links==

Text derived from https://en.wikipedia.org/w/index.php?oldid=1375094948 under CC BY-SA 4.0; modifications have been made.

References

  1. ↩Wikipedia release date (×2) · confidence 0.95 https://en.wikipedia.org/w/index.php?oldid=1375094948