[xsd-users] Outputting hxx and cxx files to different directories

Boris Kolpackov boris at codesynthesis.com
Fri Nov 5 14:46:56 EDT 2010


Hi Darren,

Darren Garvey <darren.garvey at gmail.com> writes:

> I would like to be able to get XSD to generate my source files and put them
> in the correct directories - ie. headers and source files don't live in the
> same place. I could use custom forwarding headers but would rather not have
> to.
> 
> Essentially I'm looking for a special version of --output-dir. Is something
> like this available?

No, there is no such option. It shouldn't be difficult to place the
generated files into different sub-directories using shell commands
(e.g., mv). What can be less obvious is how to make sure the generate
source file can still include the generated header. This is usually
not an issue if you compile with the -I option that points to the
directory with the headers. But often the headers are supposed to be
included with a leading directory prefix, for example:

#include <foo/bar.hxx>

To help with this issue, the XSD compiler provides a set of --include-*
options that allow you to transform include paths and style. The most
commonly used ones are --include-with-brackets and --include-prefix.
The former changes the include style from quotes ("") to brackets (<>).
The latter allows you to specify a directory prefix that should be
added to include paths (there is also --include-regex which provides
greater flexibility). So to change the include from "bar.hxx" to 
<foo/bar.hxx>, one can use the following two options:

--include-prefix foo
--include-with-brackets

Another option that is usually used together with --include-prefix is
--guard-prefix. It allows you to add a prefix to the include header
guards which should help prevent conflicts. For example:

--include-prefix FOO

Boris



More information about the xsd-users mailing list