# Including functions/macros with target export ?

**URL:** https://discourse.cmake.org/t/including-functions-macros-with-target-export/2440
**Category:** Usage
**Created:** [December 29, 2020, 2:35am UTC](https://discourse.cmake.org/t/including-functions-macros-with-target-export/2440 "2020-12-29T02:35:54Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Nicholas\_Yue](https://discourse.cmake.org/user_avatar/discourse.cmake.org/nicholas_yue/32/464_2.png) [@Nicholas\_Yue](https://discourse.cmake.org/u/Nicholas_Yue)
#### Post date: [December 29, 2020, 2:35am UTC](https://discourse.cmake.org/t/including-functions-macros-with-target-export/2440/1 "2020-12-29T02:35:54Z")

</div>

Hi,

I am able to get export(TARGET …) working and have generated working \*Config.cmake file

There are some cmake macros and functions that I would like to include for the convenience of the developers using the package.

How should I go about including/deploying them so that once a developer call find\_package(mypackage …), those functions/macros will be available to them ?

Cheers

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [December 29, 2020, 5:25am UTC](https://discourse.cmake.org/t/including-functions-macros-with-target-export/2440/2 "2020-12-29T05:25:42Z")

</div>

Do not get your `export(TARGET...)` command to write to `*Config.cmake` directly (or `install(TARGETS...)` for that matter). Instead, make those commands write their output to a file that your own hand-written `*Config.cmake` file will pull in with an `include()` call. Your hand-written `*Config.cmake` file can then define whatever functions and macros it needs to. For example:

```cmake
export(TARGETS ... FILE MyProjTargets.cmake ...)

```

Then your hand-written `MyProjectConfig.cmake` might do something like this:

```cmake
include(MyProjTargets.cmake)

# Define whatever functions and macros you want here too

```

In the above, I’ve provided a direct answer to your question. But the use of `export(TARGETS)` is not all that common. Are you trying to get another build to re-use your project’s build tree directly (i.e. without installing it)? If not, then `export(TARGETS)` is probably not the right way to go about whatever you’re trying to do. It is much more typically to be using `install(TARGETS ... EXPORT ...)` and then `install(EXPORT ...)`.

---

<div class="post-metadata">

### Author: ![Nicholas\_Yue](https://discourse.cmake.org/user_avatar/discourse.cmake.org/nicholas_yue/32/464_2.png) [@Nicholas\_Yue](https://discourse.cmake.org/u/Nicholas_Yue)
#### Post date: [December 29, 2020, 5:29am UTC](https://discourse.cmake.org/t/including-functions-macros-with-target-export/2440/3 "2020-12-29T05:29:37Z")

</div>

Thank you for the insight. I will apply your recommendations.
