In this section:

Introduction

Integrating C/C++test with projects based on a GNU Make or similar build tools typically requires modifying the build scripts. In most of the cases, the command line invoked by compilation and linking rules should be altered. This may require you to modify the make variables or, in some cases, the compilation and linking rules definitions.

Integrating with Make Compilation Rule

Prefix the compiler command line with the cpptestcc command wrapper to integrate with the Make compilation rule. To determine the best approach, start with analyzing build scripts and locating the definition for the compilation rule. In some cases, there are different rules for specific files, such as rules to handle C or C++ files. The following example shows how the compilation rule(s) may be defined: 

$(PRODUCT_OBJ_ROOT)/%$(EXT_OBJ) : %$(EXT_CXX)
   	$(CXX) $(CXXFLAGS) $(CXXSTATICFLAGS) -DAPPNAME=product

In this example, the compiler is referenced with a CXX make variable. There are two options:

  • Add the prefix variable to the compilation rule, or
  • Overwrite the compiler variable

The following sections describe how to proceed with either approach.

Adding the Prefix Variable to the Compilation Rule

Modify the compilation rule by prefixing the variable that references the compiler with an additional variable:

$(PRODUCT_OBJ_ROOT)/%$(EXT_OBJ) : %$(EXT_CXX)
   $(COV_TOOL) $(CXX) $(CXXFLAGS) $(CXXSTATICFLAGS) -
DAPPNAME=product

Additionally, assign a value to the added variable (COV_TOOL) either at the time of the Make invocation (example a) or in build scripts (example b):

Example a

make COV_TOOL="cpptestcc -compiler gcc_3_4 -line-coverage -workspace /home/test/proj/cov -- "

Example b

In this option, the variable would likely be inside a condition dependent on an additional variable:

ifeq (COV_BUILD,$(BUILD_TYPE))
    COV_TOOL="cpptestcc -compiler gcc_3_4 -line-coverage 
-workspace /home/test/proj/cov -- "
endif

Overwriting the Compiler Variable

In this approach, the compiler variable is used to specify the coverage tool command line. This can be done either at the time of the Make invocation (example c) or in build scripts (example d) after the original value of the CXX variable is specified (to avoid overriding coverage tool command with the original compiler).

Example c

If your build scripts have separate compilation rules for different types of files, you may need to overwrite more than one variable, for example CC and CXX:

make CXX="cpptestcc -compiler gcc_3_4 -line-coverage -workspace /home/test/proj/cov -- g++"

Example d

In this option, the variable would likely be inside a condition dependent on an additional variable:

ifeq (COV_BUILD,$(BUILD_TYPE))
    CXX="cpptestcc -compiler gcc_3_4 -line-coverage -workspace /home/test/proj/cov -- g++"
endif

Integrating with Make Linking Rule

Modify the linking rule to include the additional library required for code instrumentation. The cpptestcc tool library can have different forms depending on specific project requirements. It can be a shared/dynamic library, static library, or an object file. In all cases, the particular linker options may have a different form, but modifying the Makefiles will be done in a very similar manner regardless of the case.

This section focuses on the general approach to modifying linker command lines in Make-like environments. For more details about using different forms of the cpptestcc tool runtime library, see Using Coverage Tool for Complex Projects

To find an appropriate place for modification, begin with analyzing build scripts and locating the definition of the linking rule. The following example shows how the linking rule may be defined:

$(PROJ_EXECUTABLE): $(PRODUCT_OBJ) 
  $(LXX)  $(PRODUCT_OBJ) $(OFLAG_EXE)$(PROJ_EXECUTABLE) $(LXXFLAGS) $(SYSLIB) $(EXECUTABLE_LIB_LXX_OPTS)

You can either add a special variable for representing the cpptestcc tool library, or append the coverage library to one of the variables already used in the linking rule. 

Adding a Variable to Represent Coverage Tool Library

The following example shows what the modified rule may look like: 

$(PROJ_EXECUTABLE): $(PRODUCT_OBJ) 
   $(LXX)  $(PRODUCT_OBJ) $(OFLAG_EXE)$(PROJ_EXECUTABLE) $(LXXFLAGS) $(SYSLIB) $(EXECUTABLE_LIB_LXX_OPTS) $(COV_LIB)

Additionally, assign a value to the added variable (COV_LIB) either at the time of the Make invocation (example e) or in build scripts (example f):

Example e 

make COV_LIB="<COV_TOOL_INSTALLATION>/runtime/lib/cpptest.a "

Example f

In this option, the variable would likely be inside a condition dependent on an additional variable:

ifeq (COV_BUILD,$(BUILD_TYPE))
    COV_LIB="<COV_TOOL_INSTALLATION>/runtime/lib/cpptest.a"
endif

Appending Coverage Library to Existing Variable in the Linking Rule

ifeq (COV_BUILD,$(BUILD_TYPE))
    LXXFLAGS+="<COV_TOOL_INSTALLATION>/bin/engine/lib/cpptest.a"
endif



  • No labels