# Unexpected behavior for INSTALL directory

**URL:** <https://discourse.cmake.org/t/unexpected-behavior-for-install-directory/3955>\
**Category:** Code\
**Created:** [August 19, 2021, 10:52am UTC](https://discourse.cmake.org/t/unexpected-behavior-for-install-directory/3955 "2021-08-19T10:52:33Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![bjornblissing](https://discourse.cmake.org/user_avatar/discourse.cmake.org/bjornblissing/32/896_2.png) [@bjornblissing](https://discourse.cmake.org/u/bjornblissing)\
**Post date:** [August 19, 2021, 10:52am UTC](https://discourse.cmake.org/t/unexpected-behavior-for-install-directory/3955/1 "2021-08-19T10:52:33Z")

</div>

I have added section in my script that handles adding third party DLL files to my install. It looks something like this:

```auto
install(DIRECTORY ${THIRDPARTY_BIN_DIR} 
DESTINATION "bin"
FILES_MATCHING PATTERN "*.dll")

```

The idea was all DLL files should be copied from the `THIRDPARTY_BIN_DIR` to the binary directory. In my case the `THIRDPARTY_BIN_DIR` is a variable found during configuration and looks something like this: `c:\thirdparty\bin`

However, when I run my script the third party DLL files do NOT end up in the `bin` folder. Instead a new folder `bin` is created inside the install `bin` folder and the files are added there. Like:  
`bin\bin\mylib.dll`

This can be solved by adding a slash character to the source directory variable:

```auto
install(DIRECTORY "${THIRDPARTY_BIN_DIR}/"
DESTINATION "bin"
FILES_MATCHING PATTERN "*.dll")

```

Is this really the intended behavior or should I file a bug report?

---

<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:** [August 19, 2021, 4:05pm UTC](https://discourse.cmake.org/t/unexpected-behavior-for-install-directory/3955/2 "2021-08-19T16:05:50Z")

</div>

Yes, the behavior is reminiscent of `rsync`'s behavior with trailing slashes. The trailing slash basically means “the contents of” versus “the directory itself”.

---

<div class="post-metadata">

**Author:** ![bjornblissing](https://discourse.cmake.org/user_avatar/discourse.cmake.org/bjornblissing/32/896_2.png) [@bjornblissing](https://discourse.cmake.org/u/bjornblissing)\
**Post date:** [August 20, 2021, 6:47am UTC](https://discourse.cmake.org/t/unexpected-behavior-for-install-directory/3955/3 "2021-08-20T06:47:28Z")

</div>

Thanks! I found the corresponding description in the official documentation as well.

However, I still think that this behavior is non-intuitive. The most common case is probably that you want to copy files from the source folder to the destination folder, especially when you specify a file matching pattern. But this is only my personal opinion and I can certainly imagine other use-cases where the current behavior can be useful.

It was just yet another time for me where CMake “bit me in the behind” with unexpected behavior. 🙂

---

<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:** [August 20, 2021, 12:02pm UTC](https://discourse.cmake.org/t/unexpected-behavior-for-install-directory/3955/4 "2021-08-20T12:02:51Z")

</div>

> [@bjornblissing](#):
>
> The most common case is probably that you want to copy files from the source folder to the destination folder, especially when you specify a file matching pattern.

While that may be true, both cases need support and, AFAIK, the “trailing slash” heuristic is the simplest available and has prior art in `rsync` (and now copied to `rclone` as well). If there’s a way that the docs could make this clearer, please feel free to contribute better wording.

> [@bjornblissing](#):
>
> It was just yet another time for me where CMake “bit me in the behind” with unexpected behavior. 🙂

Alas, CMake is old enough and has enough goobers in its history that I don’t think anyone runs out of these. The best we can do is make policies where possible and sensible and document everything (better) as they get discovered.

---

<div class="post-metadata">

**Author:** ![bjornblissing](https://discourse.cmake.org/user_avatar/discourse.cmake.org/bjornblissing/32/896_2.png) [@bjornblissing](https://discourse.cmake.org/u/bjornblissing)\
**Post date:** [August 20, 2021, 1:47pm UTC](https://discourse.cmake.org/t/unexpected-behavior-for-install-directory/3955/5 "2021-08-20T13:47:44Z")

</div>

> Alas, CMake is old enough and has enough goobers in its history that I don’t think anyone runs out of these. The best we can do is make policies where possible and sensible and document everything (better) as they get discovered.

As someone who has used CMake since 2009, I can also testify to that. However, I must commend the current developers for the huge improvement in the quality of documentation in recent years.

---

<div class="post-metadata">

**Author:** ![leha-bot](https://discourse.cmake.org/user_avatar/discourse.cmake.org/leha-bot/32/921_2.png) [@leha-bot](https://discourse.cmake.org/u/leha-bot)\
**Post date:** [August 25, 2021, 12:17pm UTC](https://discourse.cmake.org/t/unexpected-behavior-for-install-directory/3955/6 "2021-08-25T12:17:45Z")

</div>

Do you mind if I create an issue in CMake repo and try to fix it?

---

<div class="post-metadata">

**Author:** ![bjornblissing](https://discourse.cmake.org/user_avatar/discourse.cmake.org/bjornblissing/32/896_2.png) [@bjornblissing](https://discourse.cmake.org/u/bjornblissing)\
**Post date:** [August 25, 2021, 1:03pm UTC](https://discourse.cmake.org/t/unexpected-behavior-for-install-directory/3955/7 "2021-08-25T13:03:17Z")

</div>

@leha-bot Since the current behavior is documented and similar to other tools (RSync) I don’ think the current behavior should be considered a bug. Changing the behavior will probably lead to unexpected failures for others who depend on the current behavior.

---

<div class="post-metadata">

**Author:** ![leha-bot](https://discourse.cmake.org/user_avatar/discourse.cmake.org/leha-bot/32/921_2.png) [@leha-bot](https://discourse.cmake.org/u/leha-bot)\
**Post date:** [August 25, 2021, 1:05pm UTC](https://discourse.cmake.org/t/unexpected-behavior-for-install-directory/3955/8 "2021-08-25T13:05:06Z")

</div>

Aggreed, but I think that the documentation still need a fix 😊 so the bug will be about documentation fixes

---

<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:** [August 25, 2021, 1:44pm UTC](https://discourse.cmake.org/t/unexpected-behavior-for-install-directory/3955/9 "2021-08-25T13:44:01Z")

</div>

Doc fixes are always appreciated 🙂 .
