File dependencies not correct when depending on preprocesor macros

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

#include “mbedtls/config.h”

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


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,


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

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.



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?

Sure I’ll try and let you know. Thanks

Yes that works perfectly.

Many thanks,