Pseudo Targets
Let's learn about things that look like targets but aren't.
We'll cover the following
Meet the pseudo targets
The concept of a target is so useful that it would be great if some of its behaviors could be borrowed for other things too. This is, specifically, things that do not represent outputs of the buildsystem but rather inputs—external dependencies, aliases, and so on. These are the pseudo targets, or targets that don't make it to the generated buildsystem.
Imported targets
We'll now talk about how CMake manages external dependencies—other projects, libraries, and so on. IMPORTED
targets are essentially products of this process. CMake can define them as a result of the find_ package()
command.
We can adjust the target properties of such a target: compile definitions, compile options, include directories, and so on—and they will even support transitive usage requirements. However, we should treat them as immutable; don't change their sources or dependencies.
The scope of the definition of an IMPORTED
target can be global or local to the directory where it was defined (visible in subdirectories but not in parent directories).
Alias targets
Alias targets do exactly what we expect—they create another reference to a target under a different name. We can create alias targets for executables and libraries with the following commands:
Get hands-on with 1400+ tech skills courses.