Skip to content
Latchkey

cmake --install: Install Built Artifacts

cmake --install <dir> copies built artifacts into an install prefix, honoring the install rules from CMakeLists.txt.

The install step is separate from build. In CI you usually stage into a scratch prefix so you can package or upload the result without touching system directories.

What it does

cmake --install runs the install rules (install(TARGETS ...), install(FILES ...)) defined in the project, copying headers, libraries, and binaries into the prefix. It supersedes the old make install for CMake 3.15+.

Common usage

Terminal
cmake --install build --prefix /usr/local
cmake --install build --prefix "$PWD/stage" --config Release
DESTDIR=/tmp/pkg cmake --install build --prefix /usr

Options

FlagWhat it does
--install <dir>The build directory to install from
--prefix <path>Override CMAKE_INSTALL_PREFIX at install time
--config <cfg>Multi-config: which configuration to install
--component <name>Install only a named install component
--stripStrip symbols from installed binaries
DESTDIR=<path> (env)Prepend a staging root to every install path

In CI

Stage into a scratch prefix (--prefix "$PWD/stage") instead of /usr so the runner never needs sudo. Combine DESTDIR with --prefix when building distro packages: DESTDIR is the packaging root, --prefix is where files live inside it.

Common errors in CI

"CMake Error: install(EXPORT ...) ... target not built" means you installed before building the exported target. "Permission denied" writing to /usr/local means the runner lacks root; stage into a writable prefix instead. "file INSTALL cannot copy file ... No such file or directory" means the target was never built for the selected --config.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →