Install CMake targets and export them for other projects
Answer: install() generates installation rules for a project. Calls in a source directory run in order during installation. The export() command exports targets from the current project's build tree, without installation.
EXPORT on install
The install(TARGETS) command can also accept EXPORT at the top level. This option associates the installed target files with an export called <export-name>. To actually install the export file itself, call install(EXPORT), documented below. INCLUDES DESTINATION specifies a list of directories which will be added to the INTERFACE_INCLUDE_DIRECTORIES target property of the <targets> when exported by the install(EXPORT) command.
DESTINATION should be a relative path. An absolute path is allowed, but not recommended.
| install | export | |---|---| | install(TARGETS) | export(TARGETS) | | EXPORT <export-name> | FILE <filename> | | install(EXPORT) | build tree | | DESTINATION | APPEND |
Build-tree files
export(TARGETS <target>... FILE <filename>) writes <filename> so outside projects may include it and import targets from the current project's build tree. This file is specific to the build tree. It should never be installed. See the install(EXPORT) command to export targets from an install tree. NAMESPACE prepends a string to all target names written to the file.
See also
Claims
- id: C1 claim: install() generates installation rules that run in order during installation. source: S1 evidence: "This command generates installation rules for a project."
- id: C2 claim: install(TARGETS) EXPORT associates targets with an export set that install(EXPORT) then installs. source: S1 evidence: "To actually install the export file itself, call"
- id: C3 claim: export() writes a build-tree file for consumers and that file should never be installed. source: S2 evidence: "The file created by this command is specific to the build tree"
Sources
- [S1] install. CMake docs. https://cmake.org/cmake/help/latest/command/install.html . License: BSD-3-Clause. Accessed 2026-11-19.
- [S2] export. CMake docs. https://raw.githubusercontent.com/Kitware/CMake/master/Help/command/export.rst . License: BSD-3-Clause. Accessed 2026-11-19.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: CMake docs, install; CMake docs, export. BSD-3-Clause; BSD-3-Clause. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: CMake docs, install; CMake docs, export. BSD-3-Clause; BSD-3-Clause.
Cite this
iinventedlight. 2026. "Install CMake targets and export them for other projects." iinventedlight Library, iil:note:byfjve17, version of 2026-11-19. https://iinventedlight.com/library/notes/cmake-install-export/. License: CC-BY-4.0.
@misc{iil_note_byfjve17,
author = {{iinventedlight}},
title = {{Install CMake targets and export them for other projects}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-19},
url = {https://iinventedlight.com/library/notes/cmake-install-export/},
note = {Permanent ID iil:note:byfjve17. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- cmake-install-export.table.json (table; CC-BY-4.0)
- cmake-install-export.schema.json (schema; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/cmake-install-export.md.