# Duplicate base directories with file sets

**URL:** https://discourse.cmake.org/t/duplicate-base-directories-with-file-sets/5426
**Category:** Development
**Created:** [April 11, 2022, 1:19am UTC](https://discourse.cmake.org/t/duplicate-base-directories-with-file-sets/5426 "2022-04-11T01:19:23Z")
**Posts on this page:** 2
**Page:** 1

<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: [April 11, 2022, 1:19am UTC](https://discourse.cmake.org/t/duplicate-base-directories-with-file-sets/5426/1 "2022-04-11T01:19:23Z")

</div>

I just discovered by accident that `target_sources()` does not complain if you add the same `BASE_DIR` to a file set more than once. It appears this works fine with no side effects, as far as I could tell. It turns out this is quite useful, since it allows the following pattern to be used in both in-source and out-of-source builds without any special handling:

```cmake
include(GenerateExportHeader)
generate_export_header(Something
    EXPORT_FILE_NAME include/Something/something_export.h
)

target_sources(Something
    PUBLIC
        FILE_SET HEADERS
        BASE_DIRS
            include
            ${CMAKE_CURRENT_BINARY_DIR}/include
        FILES
            ${CMAKE_CURRENT_BINARY_DIR}/include/Something/something_export.h
)

```

In practice, a project might move the `generate_export_header()` parts down into a subdirectory, but I’ve put it all in the one file above just to more easily demonstrate the main relevant aspects of the pattern.

Given that it is a useful behavior to allow a base directory to be added more than once and that it is already in a release, should we formally document it as something projects can rely on? Seems we might as well.

CC: @kyle.edwards

---

<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: [April 12, 2022, 11:44am UTC](https://discourse.cmake.org/t/duplicate-base-directories-with-file-sets/5426/2 "2022-04-12T11:44:12Z")

</div>

Is it actually stored twice (having been in the code, I would guess “yes”)?

That said, I don’t see anything in the current wording suggesting that this would not work at least as a directory is not a subdirectory of itself.
