# CMake: how to generate self-package?

**URL:** https://discourse.cmake.org/t/cmake-how-to-generate-self-package/6571
**Category:** Code
**Created:** [September 26, 2022, 5:15am UTC](https://discourse.cmake.org/t/cmake-how-to-generate-self-package/6571 "2022-09-26T05:15:59Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![zhang-qiang-github](https://discourse.cmake.org/user_avatar/discourse.cmake.org/zhang-qiang-github/32/1913_2.png) [@zhang-qiang-github](https://discourse.cmake.org/u/zhang-qiang-github)
#### Post date: [September 26, 2022, 5:15am UTC](https://discourse.cmake.org/t/cmake-how-to-generate-self-package/6571/1 "2022-09-26T05:15:59Z")

</div>

I have implemented myself package, and I want to distribute the dll/lib.

Currently, I can generate `dll/lib` with `install`. How can I generate the variable `Self_LIBRARIES` just like `ITK_LIBRARIES`?

With `Self_LIBRARIES`, user can include all modules by `target_link_libraries(pro ${Self_LIBRARIES})`. Without it, user can only use the dll by `target_link_libraries(pro xx1module xx2module)`. It is hard for user to learn which module includes the needed function.

So, I wonder how to implement the `Self_LIBRARIES`? Any suggestion is appreciated~~~

---

<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: [September 27, 2022, 7:00pm UTC](https://discourse.cmake.org/t/cmake-how-to-generate-self-package/6571/2 "2022-09-27T19:00:32Z")

</div>

You’ll need to generate a CMake package config file and set that variable yourself in some way. See [this part](https://cmake.org/cmake/help/latest/guide/tutorial/Adding%20Export%20Configuration.html) of the tutorial to get started.

---

<div class="post-metadata">

### Author: ![zhang-qiang-github](https://discourse.cmake.org/user_avatar/discourse.cmake.org/zhang-qiang-github/32/1913_2.png) [@zhang-qiang-github](https://discourse.cmake.org/u/zhang-qiang-github)
#### Post date: [October 9, 2022, 3:37am UTC](https://discourse.cmake.org/t/cmake-how-to-generate-self-package/6571/3 "2022-10-09T03:37:21Z")

</div>

Finally, I find the solution.

Two steps is needed for my question.

1. In the `CMakeLists.txt`, I need to define the exported dll by:

```auto
set(modules 
dllA
dllB
...
)
install(TARGETS ${modules}
EXPORT STK
...
)
...

```

1. In `STKConfig.cmake.in`: `set(STK_LIBRARIES "@modules@")`

Then, after `find_package(STK)`, we can use `STK_LIBRARIES`: `target_link_libraries(Pro ${STK_LIBRARIES})`.
