[xsd-users] Code Generation with AutoTools

Boris Kolpackov boris at codesynthesis.com
Sun Feb 22 11:46:30 EST 2009


Hi Steve,

Steve Sloan <steve at finagle.org> writes:

> I'm starting a project using XSD, but am having some trouble generating 
> the C++ (tree) code with AutoTools.  My simplistic approach was just to 
> add the generated filenames (e.g. Schema.hxx, Schema.cxx) to the 
> "app_SOURCES" line in Makefile.am, and add a rule to run XSD to create 
> them from the .xsd file.

Take a look at Section 9.4, "Built sources" in the automake documentation:

http://sources.redhat.com/automake/automake.html#Sources

I tried both approaches described there on the hello example. Here are the 
corresponding Makefile.am files:

# Using BUILT_SOURCES.
#
bin_PROGRAMS = hello
hello_SOURCES = driver.cxx hello.cxx
hello_LDADD= -lxerces-c

BUILT_SOURCES = hello.hxx hello.cxx
CLEANFILES = hello.hxx hello.cxx

XSD := xsd
%.hxx %.cxx: %.xsd
	$(XSD) cxx-tree $(XSDFLAGS) $<


# Using explicit dependecy tracking.
#
bin_PROGRAMS = hello
hello_SOURCES = driver.cxx hello.cxx
hello_LDADD= -lxerces-c

CLEANFILES = hello.hxx hello.cxx

driver.$(OBJEXT): hello.hxx
hello.$(OBJEXT): hello.hxx

XSD := xsd
%.hxx %.cxx: %.xsd
	$(XSD) cxx-tree $(XSDFLAGS) $<

Both of them work as expected both when building in the source directory
and in a separate directory. The BUILT_SOURCES approach is easier,
especially if you have many object files that depend on many generated
header files.

Boris




More information about the xsd-users mailing list