title: generate C/C++ command line argument parsing code from XML (or similar)
body: <p>Is there a tool that generates C/C++ source code from XML (or something similar) to create command line argument parsing functionality?</p>
  
  <p>Now a longer explanation of the question:</p>
  
  <p>I have up til now used <a href="http://www.gnu.org/software/gengetopt/gengetopt.html" rel="nofollow">gengetopt</a> for command line argument parsing. It is a nice tool that generates C source code from its own configuration format (a text file). For instance the gengetopt configuration line</p>
  
  <pre><code>option "max-threads" m "max number of threads" int default="1" optional
  </code></pre>
  
  <p>among other things generates a variable</p>
  
  <pre><code>int max_threads_arg; 
  </code></pre>
  
  <p>that I later can use.</p>
  
  <p>But gengetopt doesn't provide me with this functionality:</p>
  
  <ul>
  <li><p>A way to generate Unix man pages from the gengetopt configuration format</p></li>
  <li><p>A way to generate DocBook or HTML documentation from the gengetopt configuration format</p></li>
  <li><p>A way to reuse C/C++ source code and to reuse gengetopt configuration lines when I have multiple programs that share some common command line options</p></li>
  </ul>
  
  <p>Of course gengetopt can provide me with a documentation text by running </p>
  
  <p><code>command --help</code> </p>
  
  <p>but I am searching for marked up documentation (e.g. HTML, DocBook, Unix man pages).</p>
  
  <p>Do you know if there is any C/C++ command line argument tool/library with a liberal open source license that would suite my needs?</p>
  
  <p>I guess that such a tool would use XML to specify the command line arguments. That would make it easy to generate documentation in different formats (e.g. man pages). The XML file should only be needed at build time to generate the C/C++ source code.</p>
  
  <p>I know it is possible to use some other command line argument parsing library to read a configuration file in XML at runtime but I am looking for a tool that generate C/C++ source code from XML (or something similar) at build time.</p>
  
  <p><strong>Update 1</strong> </p>
  
  <p>I would like to do as much as possible of the computations at compile time and as less as possible at run time. So I would like to avoid libraries that give you a map of the command line options, like for instance boost::program_options::variables_map ( <a href="http://www.boost.org/doc/libs/1_49_0/doc/html/program_options/tutorial.html" rel="nofollow">tutorial</a> ). </p>
  
  <p>I other words, I prefer <code>args_info.iterations_arg</code> to <code>vm["iterations"].as&lt;int&gt;()</code></p>
  
  <p>User <strong>tsug303</strong> suggested the library <a href="http://tclap.sourceforge.net/" rel="nofollow"><code>TCLAP</code></a>. It looks quite nice. It would fit my needs to divide the options into groups so that I could reuse code when multiple programs share some common options. Although it doesn't generate out the source code from a configuration file format in XML, I almost marked that answer as the accepted answer.</p>
  
  <p>But none of the suggested libraries fullfilled all of my requirements so I started thinking about writing my own library. A sketch: A new tool that would take as input a custom XML format and that would generate both C++ code and an XML schema. Some other C++ code is generated from the XML schema with the tool CodeSynthesis XSD. The two chunks of C++ code are combined into a library. One extra benefit is that we get an XML Schema for the command line options and that we get a way to serialize all of them into a binary format (in CDR format generated from CodeSynthesis XSD). I will see if I get the time to write such a library. Better of course is to find a libraray that has already been implemented.</p>
  
  <p>Today I read about user <strong>Nore</strong>'s <a href="https://bitbucket.org/noresources/ns-xml/wiki/program" rel="nofollow">suggested alternative</a>. It looks promising and I will be eager to try it out when the planned C++ code generation has been implemented. The suggestion from <strong>Nore</strong> looks to be the closest thing to what I have been looking for.</p>