# Creating a PackageConfig for a comlicated package with components

**URL:** <https://discourse.cmake.org/t/creating-a-packageconfig-for-a-comlicated-package-with-components/6609>\
**Category:** Code\
**Created:** [October 5, 2022, 11:31pm UTC](https://discourse.cmake.org/t/creating-a-packageconfig-for-a-comlicated-package-with-components/6609 "2022-10-05T23:31:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jshanab](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jshanab/32/2555_2.png) [@jshanab](https://discourse.cmake.org/u/jshanab)\
**Post date:** [October 5, 2022, 11:31pm UTC](https://discourse.cmake.org/t/creating-a-packageconfig-for-a-comlicated-package-with-components/6609/1 "2022-10-05T23:31:39Z")

</div>

I am trying to use a CMake based set of libraries or framework that does not provide a PackageConfig or Find file. Because it has multiple libraries and executables, i would like to create a single PackageConfig that can be used for all the various targets.

All the examples I have seen so far just have one file and a single call to configure\_package\_config\_file.  
I assume you can only call configure\_package\_config\_file once unless your output file is the infile.

But the design of CMake is to put the install in each target’s CMakeList.txt

How do I cleanly create all the export info and update the final ConfigFile ?

Do I create a ConfigFile for each target then somehow roll them into one in the top level CMake ?

Any good examples?

I want to be able to add to the prefix then do something like

find(GraphicsEngine 2.5.2 COMPONENTS core tools appframework REQUIRED imgui OPTIONAL)

---

<div class="post-metadata">

**Author:** ![jshanab](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jshanab/32/2555_2.png) [@jshanab](https://discourse.cmake.org/u/jshanab)\
**Post date:** [October 11, 2022, 11:53pm UTC](https://discourse.cmake.org/t/creating-a-packageconfig-for-a-comlicated-package-with-components/6609/2 "2022-10-11T23:53:07Z")

</div>

I am going to answer my own question, in part.  
The config file is designed to be opened repeatably and have multiple exported targets added to it.  
I will play some more and see how Components fit into the picture.

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [October 16, 2022, 2:28pm UTC](https://discourse.cmake.org/t/creating-a-packageconfig-for-a-comlicated-package-with-components/6609/3 "2022-10-16T14:28:53Z")

</div>

There are a few ways to do components. Qt’s way uses components to find subpackages (e.g., `find_package(Qt5 COMPONENTS Core)` does a `find_package(Qt5Core)` under the hood). There’s also [VTK’s way](https://gitlab.kitware.com/vtk/vtk/-/blob/master/CMake/vtk-config.cmake.in) though that is likely more complicated than most projects need. I think Qt’s way where you make a CMake package per component and then dispatch might be the preferred way to go here.
