# cmake "include()" statement does not (always) error out when the target file does not exist?

**URL:** <https://discourse.cmake.org/t/cmake-include-statement-does-not-always-error-out-when-the-target-file-does-not-exist/5237>\
**Category:** Code\
**Created:** [March 17, 2022, 3:23pm UTC](https://discourse.cmake.org/t/cmake-include-statement-does-not-always-error-out-when-the-target-file-does-not-exist/5237 "2022-03-17T15:23:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![emmenlau](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/e/8c91f0/32.png) [@emmenlau](https://discourse.cmake.org/u/emmenlau)\
**Post date:** [March 17, 2022, 3:23pm UTC](https://discourse.cmake.org/t/cmake-include-statement-does-not-always-error-out-when-the-target-file-does-not-exist/5237/1 "2022-03-17T15:23:02Z")

</div>

I just spent two hours of debugging until I found an interesting problem. In my package-configuration, I write

```bash
include("${CMAKE_CURRENT_LIST_DIR}/@MY_PROJECT_NAME@Targets.cmake")

```

Through a copy-paste-error, the variable `MY_PROJECT_NAME` was not defined, so the code resolved to

```bash
include("${CMAKE_CURRENT_LIST_DIR}/Targets.cmake")

```

This did _not_ trigger an error with cmake, even though I understand such a file should not exist. Is it possible that the `include()` statement falls through missing files without error? That seems horrible. Or am I on the wrong track here?

---

<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:** [March 19, 2022, 4:44am UTC](https://discourse.cmake.org/t/cmake-include-statement-does-not-always-error-out-when-the-target-file-does-not-exist/5237/2 "2022-03-19T04:44:52Z")

</div>

`include()` definitely at least makes noise when files don’t exist (though I remember it being an error). I think it is “just” a `SEND_ERROR` though and so doesn’t stop processing right away. Is there, perhaps, actually a `Targets.cmake` file there from other copy/paste errors?
