2023/10/16 16:02
Importing and Exporting Guide — CMake 3.28.0-rc1 Documentation
https://cmake.org/cmake/help/latest/guide/importing-exporting/index.html#id1
1/15
Importing and Exporting Guide
Contents
Importing and Exporting Guide
Introduction
Importing Targets
Importing Executables
Importing Libraries
Exporting Targets
Creating Packages
Creating a Package Configuration File
Creating a Package Version File
Exporting Targets from the Build Tree
Building and Installing a Package
Creating Relocatable Packages
Using the Package Configuration File
Adding Components
Introduction
In this guide, we will present the concept of IMPORTED targets and demonstrate how to
import existing executable or library files from disk into a CMake project. We will then
show how CMake supports exporting targets from one CMake-based project and im‐
porting them into another. Finally, we will demonstrate how to package a project with a
configuration file to allow for easy integration into other CMake projects. This guide and
the complete example source code can be found in the Help/guide/importing-exporting direc‐
tory of the CMake source code tree.
Importing Targets
IMPORTED targets are used to convert files outside of a CMake project into logical targets
inside of the project. IMPORTED targets are created using the IMPORTED option of the
add_executable() and add_library() commands. No build files are generated for IMPORTED
targets. Once imported, IMPORTED targets may be referenced like any other target within
the project and provide a convenient, flexible reference to outside executables and
libraries.
By default, the IMPORTED target name has scope in the directory in which it is created and
below. We can use the GLOBAL option to extended visibility so that the target is accessible
globally in the build system.
Details about the IMPORTED target are specified by setting properties whose names begin
in IMPORTED_ and INTERFACE_. For example, IMPORTED_LOCATION contains the full path to the target
on disk.