0

I'm trying to learn how to use boost build. For starters, I'd like to run the codesynthesis xsd tool on an xsd file to generate c++ code. This tool takes one file as input and generates multiple output files. I'm having some difficulty figuring out how to do this with boost build, and I can't find any examples that are terribly similar to what I want to do. Can anyone provide some insights here? I've attached my code below. Thanks!

import path ;                                                                                                                          
import type ;                                                                            
import generators ;                                                                      

type.register XSD : xsd ;                                                                

generators.register-standard xsd.compilexsd : XSD : CPP ;                                

module xsd                                                                               
{                                                                                        
    actions compilexsd                                                                   
    {                                                                                    
        xsd cxx-tree \                                                                   
            --show-sloc \                                                                
            --generate-doxygen \                                                         
            --generate-forward \                                                         
            --generate-serialization \                                                                                                     
            --output-dir [path.parent($(<))] \                                        
            $(>)                                                                      
    }                                                                                 
}  

exe app : main.cpp test.xsd ;
Brian
  • 313
  • 2
  • 12

1 Answers1

0

I hit a nearly identical problem about seven years ago while trying to generate code from a structural spec. Boost.Build allows stating direct transformations for a single file.

Eg:

 .y --> .cpp --> .obj

Yet, there is just no syntax to express a more complex dependency tree, where a single spec file produces a whole set of .cpp files. The workaround was to do the following:

  1. Define a lib which lists all generated file names (this means you will have to keep this silly list up to date manually)

  2. Define a "prebuild" rule in a subproject which is a dependency. This way the generator always runs first:

    ALWAYS prebuildcmd ;
    PREBUILD_CMD = "your-generator arg arg arg" ;
    
    rule Prebuild 
    {
        local output = [ SHELL "$(PREBUILD_CMD)" ] ;
        ECHO $(output) ;
    }
    
    Prebuild prebuildcmd ;
    

    (this means the script is not a part of normal dependencies and must be smart enough not to stamp over unchanged files)

os_
  • 122
  • 4
  • Thanks. I'll look into that. Also, XSD seems to write the output files to the top-level source directory, not to the variant output directory. And I can't seem to figure out how to change that. The path.parent() thing above is an invalid syntax, apparently. – Brian Aug 12 '14 at 13:37