# File dependencies not correct when depending on preprocesor macros

**URL:** <https://discourse.cmake.org/t/file-dependencies-not-correct-when-depending-on-preprocesor-macros/2925>\
**Category:** Code\
**Created:** [March 9, 2021, 9:36am UTC](https://discourse.cmake.org/t/file-dependencies-not-correct-when-depending-on-preprocesor-macros/2925 "2021-03-09T09:36:42Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![liampower](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/l/2acd7d/32.png) [@liampower](https://discourse.cmake.org/u/liampower)\
**Post date:** [March 9, 2021, 9:36am UTC](https://discourse.cmake.org/t/file-dependencies-not-correct-when-depending-on-preprocesor-macros/2925/1 "2021-03-09T09:36:42Z")

</div>

I am integrating a library that includes files based on C preprocessor macros. As an example:

#if !defined(MBEDTLS\_CONFIG\_FILE)  
#include “mbedtls/config.h”  
#else  
#include MBEDTLS\_CONFIG\_FILE  
#endif

In my CMAKE file I have added the required definition as follows:

target\_compile\_definitions(MBEDTLS  
PUBLIC  
MBEDTLS\_CONFIG\_FILE=“ua\_mbedtls\_config.h”)

On both Linux and Windows the compile definition is not applied when configuring the dependencies as touching the header file does not cause a build of the dependent source files. If I simply include the header file in the code as follows everything works as you would expect:

#include “ua\_mbedtls\_config.h”

How can I get the preprocessor macro to be applied when the header dependencies are generated? This pattern is used throughout the code base and I cannot change it.

Many thanks,

Liam.

---

<div class="post-metadata">

**Author:** ![marc.chevrier](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/ecb155/32.png) [@marc.chevrier](https://discourse.cmake.org/u/marc.chevrier)\
**Post date:** [March 9, 2021, 10:11am UTC](https://discourse.cmake.org/t/file-dependencies-not-correct-when-depending-on-preprocesor-macros/2925/2 "2021-03-09T10:11:22Z")

</div>

What is the `CMake` version and which compiler(s) do you use?

---

<div class="post-metadata">

**Author:** ![liampower](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/l/2acd7d/32.png) [@liampower](https://discourse.cmake.org/u/liampower)\
**Post date:** [March 9, 2021, 10:57am UTC](https://discourse.cmake.org/t/file-dependencies-not-correct-when-depending-on-preprocesor-macros/2925/3 "2021-03-09T10:57:43Z")

</div>

Hi Marc,

CMAKE is 3.17.5 (from CLion).

On Windows I am using MSVC 19.28.29337.0 and on Linux I am using GNU 9.3.1  
I have the same problem on both platforms.

Thanks,

Liam.

---

<div class="post-metadata">

**Author:** ![marc.chevrier](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/ecb155/32.png) [@marc.chevrier](https://discourse.cmake.org/u/marc.chevrier)\
**Post date:** [March 9, 2021, 11:04am UTC](https://discourse.cmake.org/t/file-dependencies-not-correct-when-depending-on-preprocesor-macros/2925/4 "2021-03-09T11:04:14Z")

</div>

This version of `CMake` use an internal parser to compute dependencies. This parser has some limitations. May-be this is the problem…  
Starting with version `3.20` (currently in rc3), GNU and Microsoft compilers use now the compiler itself to compute dependencies. Can you try this version to check if it solves your problem?

---

<div class="post-metadata">

**Author:** ![liampower](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/l/2acd7d/32.png) [@liampower](https://discourse.cmake.org/u/liampower)\
**Post date:** [March 9, 2021, 11:27am UTC](https://discourse.cmake.org/t/file-dependencies-not-correct-when-depending-on-preprocesor-macros/2925/5 "2021-03-09T11:27:31Z")

</div>

Sure I’ll try and let you know. Thanks

---

<div class="post-metadata">

**Author:** ![liampower](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/l/2acd7d/32.png) [@liampower](https://discourse.cmake.org/u/liampower)\
**Post date:** [March 9, 2021, 11:37am UTC](https://discourse.cmake.org/t/file-dependencies-not-correct-when-depending-on-preprocesor-macros/2925/6 "2021-03-09T11:37:31Z")

</div>

Yes that works perfectly.

Many thanks,

Liam.
