Support for General Purpose IDEs

Microsoft Visual Studio

Coco provides wrappers for link.exe and cl.exe located on the %SQUISHCOCO%\visualstudio directory. They behave exactly like the corresponding Microsoft® compiler and linker except that the code coverage analysis becomes activated when the option --cs-on among the command arguments. The wrappers call the Microsoft tools for compilation and linking.

Note: See here for C# instrumentation

Microsoft Visual Studio .NET C and C++ Compiler

There are two ways to activate the instrumentation of a Visual Studio C/C++ project. It can be done automatically, with the Visual Studio Coco Wizard. Or one one can do it manually, as it is described in the rest of this section.

To use Coco with Visual Studio .NET:

  1. Add the location of the CoverageScanner wrappers to the first position in the VC++ Directories.
    • For Visual Studio 2005 or 2008:
      1. Start Visual Studio 2005 or 2008.
      2. Select Tools > Preferences.
      3. Select Projects > VC++ Directories.
      4. Add the entry $(SQUISHCOCO)\visualstudio as the first item in the list of directories:

        "Setting the path on Visual Studio 2005 and 2008"

    • For Visual Studio 2010:
      1. Start Visual Studio 2010.
      2. Open a C++ project.
      3. Open the project properties using the context menu of the loaded project.
      4. Select Configuration Properties > VC++ Directories.
      5. Add the entry $(SQUISHCOCO)\visualstudio as the first item in the list of executable directories:

        "Setting the path on Visual Studio 2005 and 2008"

  2. To activate code coverage analysis:
    1. Open a Visual C or C++ project.
    2. Edit the project settings by clicking Project > Properties.
    3. In Configuration Properties > C/C++ > Command Line > Additional Options, enter --cs-on:

      "C++ properties"

    4. In Configuration Properties > Linker > Command Line > Additional Options, enter --cs-libgen to specify the library to use for the generation of the CoverageScanner library.

      "Linker properties"

      For a list of recommended settings, see Library settings.

    5. For Microsoft Windows CE applications, append to the linker arguments the command line option --cs-architecture which lets you specify the target platform. For a summary of available architectures, see Architectures.

Library settings

LibraryLibrary fileCommand line option
Single ThreadedLIBC.LIB--cs-libgen=/ML
Static MultiThreadLIBCMT.LIB--cs-libgen=/MT
Dynamic Link (DLL)LIBCRT.LIB--cs-libgen=/MD
Debug Single ThreadedLIBCD.LIB--cs-libgen=/MLd
Debug Static MultiThreadLIBCMTD.LIB--cs-libgen=/MTd
Debug Dynamic Link (DLL)LIBCRTD.LIB--cs-libgen=/MDd

Architectures

Targeted architectureCommand line option
ARM Microprocessor--cs-architecture=ARM
ARM Microprocessor (Thumb code)--cs-architecture=THUMB
x86 Microprocessor--cs-architecture=IX86
MIPS16 Microprocessor--cs-architecture=MIPS16
MIPS Microprocessor--cs-architecture=MIPS
MIPS Microprocessor with FPU--cs-architecture=MIPSFPU
SH3 Microprocessor with FPU--cs-architecture=SH3
SH4 Microprocessor with FPU--cs-architecture=SH4

Microsoft Visual C++ Express

To use Coco with Microsoft Visual C++ Express:

  1. Add the location of the CoverageScanner wrappers to the first position in the VC++ Directories:
    1. Start Microsoft Visual C++ Express.
    2. Select Tools > Preferences.
    3. Select Projects > VC++ Directories.
    4. Add the entry $(SQUISHCOCO)\visualstudio as the first item in the list of directories.

      "Setting the path on Visual C++ Express"

  2. The activation of the code coverage analysis is similar to Visual Studio .NET (see Visual Studio .NET C and C++ Compiler).

Microsoft Visual Studio 6.0

To use Coco with Visual Studio 6.0:

  1. Add the location of the CoverageScanner wrappers to the first position in the executable directories:
    1. Start Visual Studio 6.0.
    2. Select Tools > Preferences > Directories.
    3. In Show directories for, select Executable files.
    4. Add the path of the directory visualstudio of the Coco installation as the first item in the list of directories. For example, if Coco is installed on c:\programme\SquishCoco, add the path c:\programme\SquishCoco\visualstudio.

      Note: Microsoft Visual Studio 6.0 does not handle system variables in the path list. So the %SQUISHCOCO% variable needs to be expanded.

      "Setting the path on Visual Studio 6.0"

  2. To activate code coverage analysis:
    1. Open a Visual C or C++ project.
    2. Edit the project settings by clicking Project > Properties.
    3. Add the option --cs-on to the additional command line arguments of the C or C++ compiler and linker.

      "Compiler properties"

    4. In the additional arguments of the linker, add --cs-libgen which specifies the name of the generated CoverageScanner library.

      "Linker properties"

      For a list of recommended settings, see Library settings.

Microsoft eMbedded Visual C++

To use Coco with Microsoft eMbedded Visual C++:

  1. Add the location of the CoverageScanner wrappers to the first position in the executable directories.
    1. Start eMbedded Visual C++.
    2. Select Tools > Preferences > Directories.
    3. In Show directories for, select Executable files.
    4. Select Platform and the targeted CPUs.
    5. Add the path of the directory WinCE of the Coco installation to the first position in the list of directories. For example: if Coco is installed on c:\programme\SquishCoco, add the path c:\programme\SquishCoco\WinCE.

      Note: Microsoft eMbedded Visual C++ does not handle system variables in the path list, so the %SQUISHCOCO% variable needs to be expanded.

      "Setting the path on eMbedded Visual C++"

  2. To activate the code coverage analysis:
    1. Open a Visual C or C++ project.
    2. Edit the project settings by clicking Project > Properties.
    3. Add the option --cs-on to the additional command line arguments of the C and C++ compiler and linker.

      "Compiler properties"

      "Linker properties"

Eclipse IDE for C/C++

In Eclipse™ IDE for C/C++, enable code coverage for a configuration by replacing the names of the compilers it uses with the names of the Coco compiler wrappers:

  1. Start Eclipse.
  2. Load the C or C++ project that should be instrumented.
  3. Open the property window Project Properties.
  4. Click C/C++ Build > Settings.
  5. Create a new configuration by clicking Manage Configurations, and select it.
  6. Click Tools Settings tab.
  7. Click GCC C++ Compiler and prepend cs to the name of the compiler.

    "Eclipse settings"

  8. Click GCC C Compiler and prepend cs to the name of the compiler.
  9. Click C++ Linker and prepend cs to the name of the linker.
  10. If it is a library project, also click GCC archiver and replace the name of the archiver command ar with csar.

Now Eclipse will use the Coco wrappers instead of the compilers when compiling.

However, the Coco wrappers are not by default in the search PATH and cannot yet be found during compilation.

To change this, a copy of the PATH variable needs to be added to the C/C++ Build > Environment section of the property window, and the path of the Coco binaries added. Under UNIX®, and with Coco installed at the default location, PATH will then have a value like /opt/SquishCoco/bin:/usr/local/bin:/usr/bin:/bin.

Almost always it will be necessary to modify the behavior of Coco by setting command line options. The easiest way to do this is by adding the variable COVERAGESCANNER_ARGS to the C/C++ Build > Environment. Its value then consists of command line options (see List of options). Code instrumentation is however already activated if this variable is not set or empty.

Note: If the value of COVERAGESCANNER_ARGS has changed, it is necessary to compile the whole project again. Otherwise, the new options have no effect.

If everything is done correctly and the project is compiled, you will see in the console window that csg++ is used instead of g++, and that a .csmes file is created next to the place of the newly-built binary. When the binary is run, a .csexe file is created in its working directory, which is typically a different directory from that of the .csmes file.

Apple Xcode

For versions up to Apple Xcode 12

To use Coco with Apple® Xcode, activate the code coverage analysis:

  1. Open a terminal window and set the CPLUSPLUS, LDPLUSPLUS, LD and CC to CoverageScanner compiler wrapper. The path of a native compiler (clang, clang++, gcc or g++) needs to be set in the PATH environment variable.
  2. Start Xcode using the open command.

    If GCC is used as compiler:

    SQUISHCOCO=/Applications/SquishCoco/wrapper
    export CC=$SQUISHCOCO/gcc
    export LD=$SQUISHCOCO/gcc
    export CPLUSPLUS=$SQUISHCOCO/g++
    export LDPLUSPLUS=$SQUISHCOCO/g++
    
    open /Developer/Applications/Xcode.app

    If clang is used as compiler:

    SQUISHCOCO=/Applications/SquishCoco/wrapper
    export CC=$SQUISHCOCO/clang
    export LD=$SQUISHCOCO/clang
    export CPLUSPLUS=$SQUISHCOCO/clang++
    export LDPLUSPLUS=$SQUISHCOCO/clang++
    export XCODE_TOOLCHAIN_DIR=/Applications/Xcode.app/Contents/Developer/Toolchains
    export XCODE_TOOLCHAIN=$XCODE_TOOLCHAIN_DIR/XcodeDefault.xctoolchain/usr/bin/
    
    export PATH=$XCODE_TOOLCHAIN:$PATH
    
    open /Applications/Xcode.app
  3. Open a Xcode C or C++ project.
  4. Edit the project settings by clicking Project > Edit Project Settings.
  5. Add the option --cs-on to the additional command line arguments of the C and C++ compiler in Other C Flags and Other C++ Flags and of the linker in Other Linker Flags.

    "Compiler and Linker flags"

  6. Disable the usage of the precompiled header. Open the settings of the active target (Project > Edit Active Target) and remove the contents of Prefix Header.

    "Disabling precompiled header"

For Apple Xcode 12 and above

To use Coco with Apple Xcode, activate the code coverage analysis:

  1. Open a Xcode C or C++ project.
  2. Edit the project settings by clicking the top level project.
  3. Press on the + button and insert the following User Defined Settings:
    • CC: /Applications/SquishCoco/wrapper/clang
    • CPLUSPLUS: /Applications/SquishCoco/wrapper/clang
    • LD: /Applications/SquishCoco/wrapper/clang
    • LDPLUSPLUS: /Applications/SquishCoco/wrapper/clang++
  4. Add the option --cs-on to the additional command line arguments of the C and C++ compiler in Other C Flags and Other C++ Flags and of the linker in Other Linker Flags. It is also recommended to set the path to the clang toolchain by adding the switch --cs-native-toolchain. Here is a complete example:
    --cs-on
    --cs-native-toolchain=/Applications/Xcode.app/Contents/Developer/Toolchains
                          /XcodeDefault.xctoolchain/usr/bin/
  5. Disable the usage of the precompiled header. Open the settings of the active target (Project > Edit Active Target) and remove the contents of Prefix Header.

Coco v7.2.0 ©2024 The Qt Company Ltd.
Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.