they do not contain any find_package() commands). The exported files with the targets are not enough for a proper Config Module, as they do not handle The per-config files are all included from the Got installed: A main YourLibraryTargets.cmake file as well as several YourLibraryTargets-.cmakeįiles, one for each build configuration. When you run CMake now to build and install the library, you will see that several additional files This seemsĪ bit redundant in this small example, but can be really useful once you export and install more than Now use find_package(YourLibrary) and then link with YourLibrary::YourLibrary. It is good practice to use a namespace for the exported targets. If you are already installing the library, you probably have an install() command like the following in yourĭESTINATION " $ /YourLibrary/cmake" Generating and Installing Config.cmake Installing Targets Hardcoded paths to installed files and register an imported library-target with them.ĬMake alredy comes with tools to auto-generate most parts of this Config.cmake file and this post explains how to This means that a very simple Config.cmake file could just contain In “Config Mode”, CMake looks for a Config.cmake file (or -config.cmake). Wouldn’t be necessary if the library already shipped with a generic module. This leads to a lot of duplicated work which (at least if you are unlucky and CMake doesn’t already ship with one). The important part is that every project linking to a certain library will usually have to write its own Find-Module Once found, the module will add an imported library target and with that make the library available to other cmake targets Will search in the standard system paths and possibly try some magic to locate the library and its headers on your system. In “Module Mode” a Find.cmake file is searched in the module path and then run. When your CMake project has dependencies, you will usually use find_package() in your CMakeLists.txt to findįind_package can run in two modes: “Module Mode” and “Config Mode”. If you install the library in a local directory, you can even move it around and the Config.cmake file will still work. find_package(Spix) will work right away after installing Spix. Have to write their own Find*.cmake modules. Generating a Config.cmake file and installing it makes it easier for other projects (and people) to use your library, as they no longer Of my own library, the UI automation tool Spix. I learned most of what is written here while improving the CMake project In this article I describe how to setup your CMake based C++ project so that it generates and installs aĬonfig.cmake file.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |