Menu

Command line options

pogn

Opmock 2 is controlled with a handful of command line options. Here is an example using most of the options described below:

opmock2 -i dep.h -o . -I/usr/include -I/usr/include/x86_64-linux-gnu \
-I/usr/lib/gcc/x86_64-linux-gnu/4.7/include \
-I/usr/lib/gcc/x86_64-linux-gnu/4.7/include-fixed -q -s function1,function2 -DMAC=42

-i input file

This option is used to specify the header file you want to generate code from. it can be a relative or an absolute path. This is a lowercase i : don't confuse it with the -I option for includes.

Example:

-i ../my_header.h

-o output path

This option is used to specify the output path where the code will be generated. it can be a relative or an absolute path.

Example:

-o .

-I include path

This option is used exactly like with a compiler. There should not be any space between the -I (I is an UPPERCASE letter) and the path itself. You can use it multiple times to give multiple include paths for headers to include. Your include path should contain at least the system include path for your compiler, plus any additional headers.

Example:

-I/usr/include -I/usr/include/x86_64-linux-gnu -I/usr/lib/gcc/x86_64-linux-gnu/4.7/include -I/usr/lib/gcc/x86_64-linux-gnu/4.7/include-fixed

NOTE : the way to get the system include path depends of your compiler.
With gcc, you can use the command:

gcc - -xc -v -E

And you will get something like:

gcc: warning: ‘-x c’ after last input file has no effect
Using built-in specs.
COLLECT_GCC=gcc
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 4.7.2-4' --with-bugurl=file:///usr/share/doc/gcc-4.7/README.Bugs --enable-languages=c,c++,go,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.7 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.7 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --enable-objc-gc --with-arch-32=i586 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.7.2 (Debian 4.7.2-4)
COLLECT_GCC_OPTIONS='-v' '-E' '-mtune=generic' '-march=x86-64'
/usr/lib/gcc/x86_64-linux-gnu/4.7/cc1 -E -quiet -v -imultiarch x86_64-linux-gnu - -mtune=generic -march=x86-64
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
** /usr/lib/gcc/x86_64-linux-gnu/4.7/include
/usr/local/include
/usr/lib/gcc/x86_64-linux-gnu/4.7/include-fixed
/usr/include/x86_64-linux-gnu
/usr/include**
End of search list.

The interesting part is the last lines, in bold. You have to add this path using -I options if you want to use any header from the C standard library.

-D define a macro

This option is used exactly like with a compiler. There should not be any space between the -D and the macro itself. You can use it multiple times to define multiple macros that will be expanded by the preprocessor.

Example:

-DMACRO1=1 -DFOO=hello

-q use quotes for including the original header

When opmock 2 generates a header, it has the include the original header to use the types and original prototypes defined here. However, opmock 2 does not know how this file is to be included. For example, if you include a header from the glib-2.0 library, you would include it like:

#include \<glib glib.h=""></glib>

that is, between \< and > and with a prefix "glib".

When opmock 2 generates code, it will by default include the original, mocked header like this:

#include \<glib.h></glib.h>

if you use the option -q, it will use quotes around the header instead, so the result will be:

#include "glib.h"

This option can be used in combination with the -p option.

-p define a prefix to include the original header

if you use the option -p, opmock will insert a prefix before the original header file so that it is included properly.
Example if we use -p glib:

#include \<glib/glib.h>

This option can be used in combination with the -q option.

-s skip functions code generation

Use this option if you want to skip code generation for some functions. You give the function names, without parameters or return value, separated by commas. For example:

-s function1,function2,function6

-k keep only these functions for code generation

Use this option if you want to skip all code generation, except the list of functions given with this option. You give the function names, without parameters or return value, separated by commas. For example:

-k function1,function2,function6


Related

Wiki: Home