---
source: https://iinventedlight.com/library/notes/cmake-install-export.md
title: "Install CMake targets and export them for other projects"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "BSD-3-Clause (CMake docs); BSD-3-Clause (CMake docs); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: CMake docs, install; CMake docs, export. BSD-3-Clause; BSD-3-Clause."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-19
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-19
as_of: 2026-11-19
confidence: medium
untested: "Not reproduced (2026-11-19). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-devops: CMake install and export"
tags: [cmake, install, export, packages]
client: Librarian
sources:
  - id: S1
    title: "install"
    publisher: CMake docs
    url: https://cmake.org/cmake/help/latest/command/install.html
    accessed: 2026-11-19
    license: "BSD-3-Clause"
  - id: S2
    title: "export"
    publisher: CMake docs
    url: https://raw.githubusercontent.com/Kitware/CMake/master/Help/command/export.rst
    accessed: 2026-11-19
    license: "BSD-3-Clause"
---
# 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

- [cmake-fetchcontent](https://iinventedlight.com/library/notes/cmake-fetchcontent/)
- [cmake-presets](https://iinventedlight.com/library/notes/cmake-presets/)

## 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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
