cc Wrapper Sample Utility
This sample utility demonstrates how one could write a wrapper that maps a good number of flags from one compiler to the Microsoft Visual C++ compiler (cl.exe). In this sample we give some mappings from Sun Forte and from gcc.
The main goals of this sample are to be useful, readable, extensible, and usable.
The code in the sample is written in standard C++.
The sample works by reading a configuration file (the configuration file isn’t necessary though; see below for how to compile so the configuration file is not necessary) that contains the mappings. This file must be named “ccFile.cfg”. It then applies these mappings to the command line and executes cl.exe with the result of applying these mappings. Options that don’t have a mapping in the configuration are passed through.
There are four kinds of options:
1) Normal mapped options – these options are mapped to the VC option. For example cc –O2 –c test.cpp maps to cl.exe /O2 /c
2) No space options – these options are mapped to the VC option as before, but their arguments are appended immediately following the option, with no spaces. For example cc –I..\include maps to cl.exe \I..
3) Warning option – if this option is on the command line, issue a warning, apply the mapping, and proceed.
4) Fatal Error option – if this option is on the command line, issue a fatal error and then cease execution.
The syntax for the configuration file is:
<original switch> *** <vc switch> !!! (
<original switch> *** <vc switch> ### (No space option)
<original switch> *** <vc switch> ^^^ (Warning option)
<original switch> *** <vc switch> EEE (Fatal Error option)
@@@ <comment line>
~~~ (End of config file)
We should note that the configuration file given (ccFile.cfg) is an example configuration file that has flags for two different compilers in one file. Often this will be broken out to two different files, since there can only be one mapping from each switch.
If not using the configuration file:
There are two options to compile with: (1) with the CCMEMORY defined (/DCCMEMORY) or (2) without it defined (the default). If CCMEMORY is defined it doesn’t use a configuration and rather builds the set of mappings directly from the source code. See the method Input::CreatePairsFromCode().