Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

CMake

From Wikipedia, the free encyclopedia
Cross-platform build tool for configuring platform-specific builds

CMake
DevelopersAndy Cedilnik, Bill Hoffman, Brad King, Ken Martin, Alexander Neundorf
Initial release2000; 26 years ago (2000)
Stable release
4.2.2[1] Edit this on Wikidata / 22 January 2026
Written inC,C++[2]
Operating systemCross-platform
TypeSoftware development tools
LicenseBSD-3-Clause
Websitecmake.org Edit this on Wikidata
Repository

CMake is a free,cross-platform,software development tool forbuildingapplications viacompiler-independent instructions. It also canautomatetesting,packaging andinstallation. It runs on a variety ofplatforms and supports manyprogramming languages.[3]

As a meta-build tool, CMake configuresnative build tools which in turn build thecodebase. CMake generatesconfiguration 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.[4]

Notable native build tools supported by CMake include:Make,Qt Creator,Ninja,Android Studio,Xcode, andVisual Studio.[4]

CMake is distributed asfree and open-source software under a permissiveBSD-3-Clause license.[5]

History

[edit]

Initial development began in 1999 atKitware with funding from theUnited States National Library of Medicine as part of theVisible Human Project.[4] CMake was first released in 2000.

CMake was developed to support building theInsight Segmentation and Registration Toolkit (ITK) for multiple platforms. Stated goals included addressing weaknesses while maintaining strengths of contemporary tools such asautoconf andlibtool, and to align with state of the art build technology of the time:configure scripts andMake files forUnix platforms, andVisual Studio project files forWindows.[6][4]

CMake was inspired by multiple contemporary tools. pcmaker – developed by Ken Martin and others to support building theVisualization Toolkit (VTK) – converted Unix Make files into NMake files for building on Windows.[4] 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:[4]

  • 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 separatedirectory trees forsource 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 usingTcl – 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.[4]

Subsequent development and improvements were fueled by the incorporation of CMake into developers’ own systems, including theVXL Project,[clarification needed] the CABLE[7] features added by Brad King,[clarification needed] andGE Corporate R&D for support of DART.[clarification needed] Additional features were created when VTK transitioned to CMake for its build environment and for supportingParaView.

Version 3.0 was released in June 2014.[8] It has been described as the beginning of "Modern CMake".[9] Experts now advise to avoid variables in favor oftargets andproperties.[10] The commandsadd_compile_options,include_directories,link_directories,link_libraries that were at the core of CMake 2 should now be replaced by target-specific commands.

Name

[edit]

CMake developer Brad King stated that "the 'C' in CMake stands for 'cross-platform'".

Features

[edit]

Generators and IDE support

[edit]

CMake can generate project files forIDEs likeMicrosoft Visual Studio,Xcode,Eclipse CDT and build scripts for MSBuild or NMake on Windows;Unix Make on Unix-like platforms such asLinux,macOS, andCygwin; andNinja on both Windows and Unix-like platforms by specifying generator for a platform-specific build tool. By default, CMake automatically determines default generator for the host environment it runs on. Command line option-G can be used to specify alternative generator. E.g.-G Unix Makefiles forces CMake to create build scripts formake.[4]

CMake does not support custom generators without modifying the CMake implementation. None-the-less, the CMake source code could be modified to include a custom generator.

Build targets

[edit]

CMake supports building executables, libraries (e.g.libxyz,xyz.dll etc.),object file libraries and 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.[11]

Target generation can be configured via target properties. With older versions, this was done viaCMAKE_-prefixed global variables, but this approach is deprecated.[10][12]

Hierarchical configuration

[edit]

CMake configuration files can be structured according the hierarchical structure of the source code; the source tree. ACMakeLists.txt in a root source directory serves as the root of the configuration. It may include sub-directories which each contain aCMakeLists.txt. Repeating this, results in a hierarchical structure of configuration that follows the structure of the source code.[10][12]

Separate build tree

[edit]

CMake can store generated files (both by CMake and the native build tools) in adirectory tree that is separate from the source tree.[4]

This enables multiple builds from the same source tree since each has non-overlappingfile system space. This may be leveraged to build different or even incompatible configurations such as for different platforms.

This also simplifies file management by allowing removing generated files by deleting a single directory tree instead of removing multiple files and directories throughout the source tree. This tends to prevent accidentally deleting source files or accidentally adding generated files tosource control.

Dependency management

[edit]

CMake ensures that downstream components are re-built when its sources are changed or built.[4]

Flexible project structure

[edit]

CMake can locate system-wide and user-specified executables, files, and libraries. These locations are stored in acache, 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.[13]

Compiler feature detection

[edit]

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

Compiler support

[edit]

CMake supports many compilers, including: Apple Clang,Clang,GNU GCC,MSVC,Oracle Developer Studio, andIntel C++ Compiler.[15]

Packaging

[edit]

CMake can produce packages that can be consumed both by end-user and third-party cmake-based project. Via CPack, built files may be packed into anarchive file for a target system's package manager (e.g.dpkg) orinstaller supported by the target platform.[16]: 132, 142 [17][18] CMake provides functions for pulling packages from a remote server that can be used as part of the build process or link previously installed cmake packages.[18]

GUI

[edit]

Cmake may be run by using ancurses program likeccmake that can be used to configure projects viacommand-line interface.

Precompiled headers and modules

[edit]

It is possible to generateprecompiled headers via CMake since version 3.6.[19] As of version 3.28, CMake can also compilemodules. Experimental support for header units also exists.[20]

JSON strings

[edit]

CMake supports extracting values into variables fromJSON-data strings (since version 3.19).[21]

Language

[edit]

CMake includes aninterpreter for a relatively simple, custom, imperativescripting language that supports variables, string manipulation, arrays, function and macro declaration, and module inclusion (importing).

The interpreter reads CMake language commands from files namedCMakeLists.txt which specify source files and build preferences. CMake uses this information to generate native tool configuration files. Additionally, files with suffix.cmake can be used for storing additional script.[22]

Command syntax

[edit]

CMake language commands are formatted as:

name(argument ...)

Arguments arewhitespace-separated and can include keywords to separate groups of arguments. For instance, in the following command, the keywordCOMPILE_FLAGS delimits a list of source files from compiler flags.[23]

set_source_file_properties(filename ... COMPILE_FLAGScompile_flag ...)

Implementation

[edit]

The CMake scripting language is implemented viaYacc andLex generators.

The executable programs CMake, CPack, and CTest are written inC++.

Much of CMake's functionality is implemented in modules written in theCMake language.[24]

CMake documentation (since release 3.0) usesreStructuredText markup. HTML pages and man pages are generated by theSphinxdocumentation generator.

Additional tools

[edit]

CMake ships with numerous.cmake script files and development tools that facilitate tasks such as finding dependencies (both built-in and external, e.g.FindXYZ modules), testing the toolchain environment and executables, packaging releases (CPack), and managing dependencies on external projects (ExternalProject module). Additional development tools include:[25][26]

  • ccmake andcmake-gui — for updating configuration variables intended for a native build tool
  • CPack — for packaging software as LinuxRPM,deb, andgzip packages,NSIS files (for Windows), andmacOS packages[27][28]
  • CTest andCDash — for software testing and reporting

Adoption

[edit]

CMake has been very widely adopted among commercial, open source, and academic software projects. A few notable users includeAndroid NDK,Netflix,Inria,MySQL,Boost (C++ libraries),KeePassXC,KDE,KiCAD,FreeCAD,Webkit,Blender,[29] Biicode,ReactOS,Apache Qpid, theATLAS experiment,[30] andSecond Life.[31]

Build process

[edit]

Building via CMake has a two major stages.[4] First, native build tool configuration files are generated from CMake configuration files – written in the CMake scripting language. The command line syntax iscmake <dir> where <dir> is a directory that contains aCMakeLists.txt file. Then, the native build tools are invoked either via CMake (cmake --build <dir>) or directly via the native tool's interface. The native build tools use the generated files.[13][32]

Examples

[edit]

Hello world

[edit]

The following demonstrates configuring CMake to build ahello world program written inC++, and using CMake to build the program.

hello.cpp:

#include<print>intmain(){std::println("Hello, world!");return0;}

CMakeLists.txt:

cmake_minimum_required(VERSION3.22)project(HelloWorldCXX)add_executable(hellohello.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-Bout.

All generated files will be under the directoryout as specified via-B out.

Then, build via the native build tool as supported thru CMake:

cmake--buildout

The program is then available for running. ViaBash, the command is like./out/hello. On Windows, the output file ends with.exe.

Include

[edit]

This example demonstrates configuring the preprocessor include path.

hello.cpp:

#include<print>#include"hello.hpp"intmain(){for(inti=0;i<TIMES;++i){std::println("Hello, world!");}return0;}

hello.hpp:

#pragma onceconstexprintTIMES=10;

CMakeLists.txt:

cmake_minimum_required(VERSION3.22)project(HelloWorldCXX)add_executable(hellohello.cpp)target_include_directories(helloPRIVATE${PROJECT_SOURCE_DIR})

See also

[edit]

References

[edit]
  1. ^"CMake 4.2.2 available for download". 22 January 2026. Retrieved28 January 2026.
  2. ^"The CMake Open Source Project on OpenHub". OpenHub. Retrieved9 April 2016.
  3. ^"CMake".
  4. ^abcdefghijk"The Architecture of Open Source Applications (Volume 1)CMake".aosabook.org. Retrieved11 June 2023.
  5. ^"Licenses · master · CMake / CMake".GitLab. Retrieved13 November 2020.
  6. ^"FLOSS Weekly 111: CMake".podcast. TWiT Network. Retrieved27 February 2011.
  7. ^"The CABLE". Archived fromthe original on 19 June 2013. Retrieved10 November 2010.
  8. ^Maynard, Robert (10 June 2014)."[CMake] [ANNOUNCE] CMake 3.0.0 Released".
  9. ^"Effective Modern CMake".Gist.
  10. ^abcBinna, Manuel (22 July 2018)."Effective Modern CMake".
  11. ^"cmake-buildsystem(7) — CMake 3.19.0-rc3 Documentation".cmake.org. Retrieved14 November 2020.
  12. ^abPfeifer, Daniel (19 May 2017).Effective Cmake(PDF). CPPNow.
  13. ^abNeundorf, Alexander (21 June 2006)."Why the KDE project switched to CMake—and how".LWN.net.
  14. ^"CMake compiler feature detect".www.scivision.dev. 15 November 2020. Retrieved22 January 2022.
  15. ^"Supported Compilers".CMake Documentation. Retrieved22 January 2022.
  16. ^Berner, Dominik (2022).CMake Best Practices : Discover Proven Techniques for Creating and Maintaining Programming Projects with CMake. Mustafa Kemal Gilor. Birmingham: Packt Publishing, Limited.ISBN 978-1-80324-424-2.OCLC 1319218167.
  17. ^"cmake-packages(7) — CMake 3.24.1 Documentation".cmake.org. Retrieved11 September 2022.
  18. ^ab"Exposing a module's configuration (advanced) — CMake build procedure 1.0 documentation".docs.salome-platform.org. Retrieved11 September 2022.
  19. ^"target_precompile_headers — CMake 3.21.20210925-gb818e3c Documentation".cmake.org. Retrieved25 September 2021.
  20. ^"CXX_MODULE_HEADER_UNIT_SETS".cmake.org. Kitware. Retrieved31 October 2025.
  21. ^"CMake 3.19 Release Notes — CMake 3.19.7 Documentation".cmake.org. Retrieved15 March 2021.
  22. ^"cmake-language(7) — CMake 3.19.0-rc2 Documentation".cmake.org. Retrieved29 October 2020.
  23. ^Cedilnik, Andrej (30 October 2003)."Cross-Platform Software Development Using CMake Software". Linux Journal. Retrieved29 January 2021.
  24. ^"cmake-language(7) — CMake 3.19.0-rc1 Documentation".cmake.org. Retrieved25 October 2020.
  25. ^"cmake-modules(7) — CMake 3.14.7 Documentation".cmake.org. Retrieved24 October 2020.
  26. ^"ExternalProject — CMake 3.14.7 Documentation".cmake.org. Retrieved24 October 2020.
  27. ^"Packaging With CPack".CMake Community Wiki.
  28. ^cpack(1) – Linux General CommandsManual from ManKier.com.
  29. ^"Building Blender - Blender Developer Wiki".wiki.blender.org. Retrieved1 July 2021.
  30. ^Elmsheuser, J; Krasznahorkay, A; Obreshkov, E; Undrus, A (2017)."Large Scale Software Building with CMake in ATLAS"(PDF). CERN.Archived(PDF) from the original on 28 July 2018.
  31. ^"CMake Success".cmake.org. Kitware. 2011. Retrieved12 March 2022.
  32. ^"cmake-toolchains(7) — CMake 3.19.0-rc2 Documentation".cmake.org. Retrieved29 October 2020.

External links

[edit]
Retrieved from "https://en.wikipedia.org/w/index.php?title=CMake&oldid=1334834137"
Categories:
Hidden categories:

[8]ページ先頭

©2009-2026 Movatter.jp