Exporting Without Installation
Explore how to share CMake targets from one C++ project to another without performing full installations. Learn to generate target export files with CMake's export() command to provide accurate target definitions and paths, facilitating quick project integration while avoiding side effects of including entire project files.
We'll cover the following...
How can we make the targets of the project A available to the consuming project B? Usually, we'd reach for the find_package() command, but that would mean that we'd need to create a package and install it on the system. That approach is useful, but it takes some work. Sometimes, we just need a really quick way to build a project and make its targets available for other projects.
We could save some time by including the main listfile of A: it contains all the target definitions already. Unfortunately, it also potentially contains a lot of other things: global configuration, requirements, CMake commands with side effects, additional dependencies, and perhaps targets that we don't want in B (such as unit tests). So, let's not do that.
Target export file
It's better to achieve this by ...