[CMake] Dependencies when using macro as include filename
Michael Wild
themiwi at gmail.com
Fri Sep 16 07:49:51 EDT 2011
On 09/16/2011 01:29 PM, Max Vasin wrote:
> Hello,
> I have a number of headers (say A.h, B.h, C.h) that define some kind
> of hardware abstraction layer, which header to use is determined
> by the CMakeLists.txt and specified by the macro in config.h:
>
> config.h:
> #cmakedefine HAL_H ${HAL_H}
>
> The config.h and the HAL_H are included by the header (say P.h).
>
> P.h:
> #include "config.h"
> #include HAL_H
>
> When I modify the HAL_H only the program is not rebuilt. I do not what
> to make condition includes like
>
> P.h:
> #if NEED_A_H
> # include "A.h"
> #elseif NEED_B_H
> # include "B.h"
> // etc.
>
> because I what to have all these condition in CMakeLists.txt only and
> keep P.h simple and straightforward.
> I understand that I can generate P.h with CONFIGURE_FILE but I wonder
> if there are other solutions and which
> solution the community recommends.
>
The problem is your config.h file. #cmakedefine doesn't do what you
want. What it does is substitute either
#define HAL_H
if the variable HAL_H evaluates to a TRUE value, otherwise to
/* #define HAL_H */
What you want is
#define HAL_H ${HAL_H}
or IMHO preferably
#define HAL_H @HAL_H@
and then use configure_file(... @ONLY).
HTH
Michael
More information about the CMake
mailing list