[CMake] @MY_VAR@ are replaced by empty string !

Martin Lütken mlu at danware.dk
Fri Feb 15 08:51:30 EST 2008






-----Original Message-----
From: Bill Hoffman [mailto:bill.hoffman at kitware.com]
Sent: Thu 2/14/2008 2:45 PM
To: Martin Lütken; cmake
Subject: Re: [CMake] @MY_VAR@ are replaced by empty string !
 
Martin Lütken wrote:
> 
> 
> 
> 
> 
> -----Original Message-----
> From: Bill Hoffman [mailto:bill.hoffman at kitware.com]
> Sent: Wed 2/13/2008 7:50 PM
> To: Martin Lütken
> Cc: cmake at cmake.org
> Subject: Re: [CMake] @MY_VAR@ are replaced by empty string !
> 
> Martin Lütken wrote:
>  > SHORT:
>  > It's seems impossible to contruct a string containing something like 
> this:
>  > "@MY_VAR@". The whole thing gets replaced by an empty string regardless
>  > whether
>  > the MY_VAR variable is set or not. It is possible to create a string
>  > like "@ MY_VAR@",
>  > but that is not quite the same.
>  >
>  >
>  > ACTUAL PROBLEM DESCRIPTION:
>  > I am trying to create cmake files for Gtk+ and asssociated libs among
>  > those Pango!
>  >
>  > In order to run the glib-mkenums perl script from CMake I need to be
>  > able to contruct
>  > a custom command with strings containing the above "@MY_VAR@" construct
>  > which the script
>  > uses in a similar fashion as CMake does in it's CONFIGURE_FILE command.
>  >
>  > Any suggestions? Or do I need to file a bug-report ?
>  >
> 
> Can you use COPY_ONLY?  Or do you need to configure some variables in
> the file, just not all of them?
> 
> Actually I need that as part of running a CUSTOM_COMMAND. So I need to 
> construct parameters like that
> for a perlscript that creates c-source code from a bunch of header files.
> 

I still don't get it...   You want to run a perl script from a custom 
command, that much I get...  However, I don't know why it needs to be 
configured?

-Bill


Hi again I might have figured most of it out now. I learned from another posting here that I should not quote the commands. 
That helped and after a lot of "escaping" it allmost works! Now I just seem to have a problem with the WORKING_DIRECTORY which seems to be ignored completely! I am using CMake version "2.4-patch 7".

--- My original makefile was like this: ---

( cd $(srcdir) && $(GLIB_MKENUMS) \
  --fhead "#undef GTK_DISABLE_DEPRECATED\n#define GTK_ENABLE_BROKEN\n#include \"gtk.h\"\n#include \"gtkprivate.h\"\n#include \"gtkalias.h\"\n" \
  --ftail "#define __GTK_TYPE_BUILTINS_C__\n#include \"gtkaliasdef.c\"\n" \
  --fprod "\n/* enumerations from \"@filename@\" */" \
  --vhead "GType\n at enum_name@_get_type (void)\n{\n  static GType etype = 0;\n  if (etype == 0) {\n    static const G at Type@Value values[] = {" \
  --vprod "      { @VALUENAME@, \"@VALUENAME@\", \"@valuenick@\" }," \
  --vtail "      { 0, NULL, NULL }\n    };\n    etype = g_ at type@_register_static (g_intern_static_string (\"@EnumName@\"), values);\n  }\n  return etype;\n}\n" \
  $(gtk_public_h_sources) ) gtktypebuiltins.c  


--- And I got it transformed to: ---

ADD_CUSTOM_TARGET ( gtkMkEnumsTarget ALL echo "Creating ...." )	
SET ( type  )
SET ( outFileName "gtktypebuiltins" )
ADD_CUSTOM_COMMAND(
	OUTPUTS ${CMAKE_CURRENT_BINARY_DIR}/${outFileName}.c
	SOURCE gtk.symbols
	COMMAND  ${glib-mkenums_EXECUTABLE} --fhead \"\#undef GTK_DISABLE_DEPRECATED\\n\#define GTK_ENABLE_BROKEN\\n\#include \\"gtk.h\\"\\n\#include \\"gtkprivate.h\\"\\n\#include \\"gtkalias.h\\"\\n\" --ftail \"\#define __GTK_TYPE_BUILTINS_C__\\n\#include \\"gtkaliasdef.c\\"\\n\" --fprod \"\\n/* enumerations from \\"@filename@\\" */\" --vhead \"GType\\n at enum_name@_get_type \(void\)\\n{\\n  static GType etype = 0;\\n  if \(etype == 0\) {\\n    static const G at Type@Value values[] = {\" --vprod \"      { @VALUENAME@, \\"@VALUENAME@\\", \\"@valuenick@\\" },\" --vtail \"      { 0, NULL, NULL }\\n    };\\n    etype = g_ at type@_register_static \(g_intern_static_string \(\\"@EnumName@\\"\), values\);\\n  }\\n  return etype;\\n}\\n\" ${${CBS_CURRENT}_PUBLIC_HEADER} >  ${CMAKE_CURRENT_BINARY_DIR}/${outFileName}.c
	TARGET gtkMkEnumsTarget
	WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
ADD_SOURCE_FILE ( ${CMAKE_CURRENT_BINARY_DIR}/${outFileName}.c	)
SET_SOURCE_FILES_PROPERTIES( ${CMAKE_CURRENT_BINARY_DIR}/${outFileName}.c GENERATED	)

---------- 
But the generated makefile does not switch to the requested WORKING_DIRECTORY but instead to 
the CMAKE_CURRENT_BINARY_DIR regardless of what I set as WORKING_DIRECTORY.

--- It looks something like this in the CMake generated makefile: ---

@echo "Generating gtktypebuiltins.c"
	cd /home/ml/code/cpaf/build_cbs/kdev_release/lgpl/gtk/gtk && ../../glib-main/gobject/glib-mkenums --fhead "#undef GTK_DISABLE_DEPRECATED\n#define GTK_ENABLE_BROKEN\n#include \"gtk.h\"\n#include \"gtkprivate.h\"\n#include \"gtkalias.h\"\n" --ftail "#define __GTK_TYPE_BUILTINS_C__\n#include \"gtkaliasdef.c\"\n" --fprod "\n/* enumerations from \"@filename@\" */" --vhead "GType\n at enum_name@_get_type (void)\n{\n static GType etype = 0 \n if (etype == 0) {\n static const G at Type@Value values[] = {" --vprod " { @VALUENAME@, \"@VALUENAME@\", \"@valuenick@\" }," --vtail " { 0, NULL, NULL }\n } \n etype = g_ at type@_register_static (g_intern_static_string (\"@EnumName@\"), values) \n }\n return etype \n}\n" gtk.h ( ... LOTS_OF_HEADER_FILES .... ) > /home/ml/code/cpaf/build_cbs/kdev_release/lgpl/gtk/gtk/gtktypebuiltins.c

--- problem: ---
The glib-mkenums script cannot find the header files since it's executed from the wrong working directory!

Any suggestions ?

-Martin Lutken
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/cmake/attachments/20080215/162fac22/attachment.htm


More information about the CMake mailing list