CMake
CMake is a cross-platform free and open-source software tool for managing the build process of software using a compiler-independent method. 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, Apple's Xcode, and Microsoft Visual Studio. It has minimal dependencies, requiring only a C++ compiler on its own build system.
Developer(s) | Andy Cedilnik, Bill Hoffman, Brad King, Ken Martin, Alexander Neundorf |
---|---|
Initial release | 2000 |
Stable release | 3.18.1[1]
/ July 30, 2020 |
Repository | |
Written in | C, C++[2] |
Operating system | Cross-platform |
Type | Software development tools |
License | New BSD License |
Website | cmake |
Features
CMake can handle in-place and out-of-place builds, enabling several builds from the same source tree, and cross-compilation. The ability to build a directory tree outside the source tree is a key feature, ensuring that if a build directory is removed, the source files remain unaffected.
CMake can locate 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 included in the project.
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.[3]
CMake can generate project files for several prominent 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.
Build process
The build process with CMake takes place in two stages. First, standard build files are created from configuration files. Then the platform's native build tools are used for the actual building.[3]
Each build project contains a CMakeLists.txt file, in every (sub)directory, that controls the build process. The CMakeLists.txt file has one or more commands in the form COMMAND (args...), with COMMAND representing the name of each command and args the list of arguments, each separated by whitespace. While there are many built-in rules for compiling the software libraries (static and dynamic) and executables, there are also provisions for custom build rules. Some build dependencies can be determined automatically. Advanced users can also create and incorporate additional makefile generators to support their specific compiler and OS needs.
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.
History
CMake development began in 1999 in response to the need for a cross-platform build environment for the Insight Segmentation and Registration Toolkit.[4] 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[5] 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.[6] It has been described as the beginning of "Modern CMake".[7] Experts now advise to avoid variables in favor of targets and properties.[8] The commands add_compile_options, include_directories, link_directories, link_libraries that were at the core of CMake 2 should now be replaced by target-specific commands.
CPack
CPack is a packaging system for software distributions which is tightly integrated with CMake, but can function without it.[9][10]
It can be used to generate:
- Linux RPM, deb and gzip distributions of both binaries and source code.
- NSIS files (for Microsoft Windows)
- macOS packages
See also
- List of build automation software § Build script generation tools
- configure script
- GYP (Generate Your Projects)
- imake
- Meson
- xmake
- Premake
- qmake
- Autotools
References
- "CMake Release Tags on GitLab". Retrieved 5 August 2020.
- "The CMake Open Source Project on OpenHub". OpenHub. Retrieved 2016-04-09.
- Neundorf, Alexander (2006-06-21). "Why the KDE project switched to CMake—and how". LWN.net.
- "FLOSS Weekly 111: CMake". podcast. TWiT Network. Retrieved 27 February 2011.
- "The CABLE". Archived from the original on 2013-06-19. Retrieved 2010-11-10.
- https://cmake.org/pipermail/cmake/2014-June/057793.html
- https://gist.github.com/mbinna/c61dbb39bca0e4fb7d1f73b0d66a4fd1#file-effective_modern_cmake-md
- https://github.com/boostcon/cppnow_presentations_2017/blob/master/05-19-2017_friday/effective_cmake__daniel_pfeifer__cppnow_05-19-2017.pdf, https://gist.github.com/mbinna/c61dbb39bca0e4fb7d1f73b0d66a4fd1
- "Packaging With CPack". CMake Community Wiki.
- – Linux General Commands Manual