cmake
repository·master·Indexed 27 days ago
https://github.com/kitware/cmakeThe CMake build system repository, including documentation for contributing via GitLab, local development environment setup, and utility modules for integrating third-party libraries such as Expat, PDCurses, Zstandard (zstd), and the Kitware Information Macro Library (KWIML).
What's inside cmake
- PDCurses Portable Core contains the source code files that are common to all platforms supported by PDCurses. This core logic is shared across different platform-specific implementations.
Overview of llpkgc
masterllpkgc is a utility library used within this repository. It is maintained in an upstream repository and is not a native part of the CMake core logic.
Upstream Repository: https://gitlab.kitware.com/utils/llpkgc
Note for Contributors: Updates to
llpkgcshould generally be made in the upstream repository rather than within the CMake repository, unless the changes are exceptionally specific to CMake.Overview of CMake File-Based API v1
masterThe CMake File-Based API v1 allows external tools (clients) to interact with CMake by reading and writing JSON files in the build directory. The API is organized into two main subdirectories under
<build>/.cmake/api/v1/:query/: Contains request files written by the client to ask CMake for information.reply/: Contains response files written by CMake. Clients should only read these files by following references found in a reply index file.
Note: Clients must never remove files in the
reply/directory. For user-wide queries across all projects, you can add query files toapi/v1/queryinside the directory specified by theCMAKE_CONFIG_DIRenvironment variable.Overview of CMake Instrumentation
masterThe CMake Instrumentation API collects timing, target, and system diagnostic information during the
configure,generate,build,test, andinstallsteps of a CMake project.Supported Generators: This feature is only available when using:
Makefile GeneratorsNinja GeneratorsFASTBuild
Workflow:
- Data Collection: CMake writes
v1 Snippet Filesinto the project build tree during command execution (e.g., compile, link, custom commands). - Indexing: CMake collates these snippets into a
v1 Index Filebased on configured "hooks" (e.g., after every build orctestinvocation). - Callbacks: User-defined callbacks process the
v1 Index File. Once all callbacks complete, CMake automatically deletes the index and snippet files.
Overview of KWSys
masterKWSys (Kitware System Library) provides platform-independent APIs for common system features that vary across different operating systems. It is designed to be shared among multiple projects at the source level. To avoid symbol collisions, each project using KWSys should configure it to use a unique namespace. Refer to theCMakeLists.txtin the KWSys source for specific configuration details.Overview of PDCurses
masterPDCurses is an implementation of X/Open curses designed for multiple platforms. It provides a terminal handling interface for applications requiring curses-like functionality on systems that do not natively support it.Use the Kitware Information Macro Library (KWIML)
masterKWIML provides header files that use preprocessor tests to detect and provide information about the compiler and its target architecture. Because the headers contain no configuration-time test results, they can be installed into architecture-independent include directories and are safe for use in the public interfaces of packages.Configure CPack DEB Generator for Debian Packages
masterThe CPack DEB generator creates.debpackages usingCPack. While it works on any Linux host, it is recommended to have Debian-specific tools likedpkg-xxxavailable on the build system for better results. The generator uses standard!CPACK_XXXvariables but provides specific!CPACK_DEBIAN_XXXvariables for fine-grained control over Debian control fields.Categorization of CMake Target Commands
masterCMake target commands modify the properties of a target (e.g., sources, compile flags, output names, or requirements for consumers). They are categorized by their commonality and recommended usage:
- Common/Recommended:
target_compile_definitions,target_compile_features,target_link_libraries,target_sources. - Advanced/Caution:
get_target_property,set_target_properties,target_compile_options,target_link_options,target_precompile_headers. - Esoteric/Footguns (Avoid if possible):
target_include_directories,target_link_directories.
When applying these commands, use the following scope keywords:
PRIVATE: Requirements needed only to build the target itself.INTERFACE: Requirements needed only to consume the target.PUBLIC: Requirements needed for both building and consuming the target.
- Common/Recommended:
Use the CMake File-Based API to query build system information
masterCMake provides a file-based API that allows external clients to obtain semantic information about the build systems CMake generates.
To use the API, a client writes 'query files' to a specific directory within the build tree. When CMake runs the generation step in that build tree, it detects these files, processes the requests, and writes 'reply files' containing the requested information.
The API is located at
<build>/.cmake/api/at the top of the build tree.Understand CMake's C++ Modules Design
masterCMake uses an Explicit Static build design for C++ modules.
- Explicit: Build controls which modules are visible to each translation unit directly by providing exact paths to Binary Module Interface (BMI) files via a module map.
- Static: Uses a static set of build commands. Dependencies are discovered via a scanning step and then added as edges to the existing build graph, rather than creating new commands dynamically during the build.
This design aims for correct, deterministic builds, support for generated sources, static communication (using files instead of background services), and minimized build graph regeneration.
Understand the CMake test suite organization
masterThe
Tests/directory contains the CMake test suite. Tests are organized into several specialized subdirectories based on their purpose:CMakeLib/: Tests that link to theCMakeLiblibrary defined inSource/.Module/: Tests for specific CMake modules.RunCMake/: Tests that execute CMake and/or other tools to verify return codes andstdout/stderrcontent. These are primarily used for testing error cases and diagnostic output.Fuzzing/: Fuzz testing targets usinglibFuzzer, integrated with OSS-Fuzz.Find*/: Tests for specific find modules (requires corresponding packages to be installed on the machine).CMakeOnly/(Deprecated): Tests that run CMake to generate a project without building it. UseTests/RunCMake/instead.