AW: [CMake] CMake: Problem with reading files with semicolons

Philippe Poilbarbe Philippe.Poilbarbe at cls.fr
Thu Jan 26 06:28:10 EST 2006


wedekind a écrit :
> ...
> does not match any semicolons... Therefore I cannot modify C++ source-code
> files with cmake, at least not the way I have tried. Can you tell me how to
> insert a line of code (an #include in my case) into an existing source file
> with CMake?
> ...
>   
Normally this kind of thing is done via CONFIGURE_FILE as it is typically
a parameter depending on configuration (configuration: something determined
before compile time).

You can put in your C file some line like
@INCLUDE_MYFILE@
and then define INCLUDE_MYFILE variable in cmake script and configure
the C source file (or, usually a .h file which is included in your c file)

Examples are below.
Regards,
Ph.P.

============

MyCFile.c.in:
// Source file to be configured
...
@INCLUDE_MYFILE@
...


CMakeLists.txt:
IF (SOME_CONDITION)
  SET(INCLUDE_MYFILE "#include \"MyInclude.h\"")
ENDIF (SOME_CONDITION)
CONFIGURE_FILE(MyCFile.c.in MyCFile.c)

_* or *_

MyCFile.c.in:
// Source file to be configured
#cmakedefine @HAVE_H_FILE@
...
#ifdef HAVE_H_FILE
#include "MyInclude.h"
#endif
...


CMakeLists.txt:
IF (SOME_CONDITION)
  SET(HAVE_H_FILE ON)
ENDIF (SOME_CONDITION)
CONFIGURE_FILE(MyCFile.c.in MyCFile.c)





More information about the CMake mailing list