BullseyeCoverage Up Contents Search

CMake

Visual Studio

When generating Visual Studio project files, no extra steps are needed. Run CMake as usual. After generating the project files, enable coverage build and then build your project.

Example CMakeLists.txt:

cmake_minimum_required(VERSION 3.18)
project(hello)
add_executable(hello hello.cpp)

Example commands:

C:\build> cmake -G"Visual Studio 16 2019" .
-- The C compiler identification is MSVC 19.29.30037.0
-- The CXX compiler identification is MSVC 19.29.30037.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files/BullseyeCoverage/bin/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files/BullseyeCoverage/bin/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: C:/build
C:\build> cov01 -q -1
C:\build> msbuild -nologo -target:Build -verbosity:minimal hello.sln
  Checking Build System
  Building Custom Rule C:/build/CMakeLists.txt
  BullseyeCoverage Compile 9.5.0 Windows
  Copyright (c) Bullseye Testing Technology
  hello.cpp
  BullseyeCoverage Compile 9.5.0 Windows
  Copyright (c) Bullseye Testing Technology
  hello.vcxproj -> C:\build\Debug\hello.exe

Ninja

To use BullseyeCoverage with CMake generating Ninja files:

  1. Set the PATH environment variable so that it contains BullseyeCoverage/bin followed by your compiler directory.
  2. Set CMAKE_CXX_COMPILER and CMAKE_C_COMPILER to the basename of the respective compiler commands.
  3. Run cmake as usual
  4. Run cov01 -1
  5. Run ninja as usual

Example CMakeLists.txt:

cmake_minimum_required(VERSION 3.18)
project(hello)
add_executable(hello hello.cpp)

Example commands:

C:\build> cmake -G Ninja -D CMAKE_CXX_COMPILER=cl -D CMAKE_C_COMPILER=cl .
-- The C compiler identification is MSVC 19.29.30133.0
-- The CXX compiler identification is MSVC 19.29.30133.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files/BullseyeCoverage/bin/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files/BullseyeCoverage/bin/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: C:/build
C:\build> cov01 -q -1
C:\build> ninja
[1/2] Building CXX object CMakeFiles\hello.dir\hello.cpp.obj
BullseyeCoverage Compile 9.5.0 Windows
Copyright (c) Bullseye Testing Technology
[2/2] Linking CXX executable hello.exe

NMAKE Makefiles

To use BullseyeCoverage with CMake generating NMAKE makefiles:

  1. Set the PATH environment variable so that it contains BullseyeCoverage/bin followed by the Microsoft compiler directory.
  2. Run cmake as usual
  3. Run cov01 -1
  4. Run nmake as usual

Do not override the CMAKE_CXX_COMPILER or CMAKE_C_COMPILER settings.

Example CMakeLists.txt:

cmake_minimum_required(VERSION 3.18)
project(hello)
add_executable(hello hello.cpp)

Example commands:

C:\build> rem Set PATH with BullseyeCoverage first
C:\build> set PATH=c:/Program Files/BullseyeCoverage/bin;c:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30037/bin/Hostx64/x64;c:/Program Files (x86)/Windows Kits/10/bin/10.0.17763.0/x64
C:\build> rem Configure compiler as usual
C:\build> set INCLUDE=c:/Program Files (x86)/Windows Kits/10/Include/10.0.19041.0/ucrt;c:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30037/include
C:\build> set LIB=c:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30037/lib/x64;c:/Program Files (x86)/Windows Kits/10/lib/10.0.17763.0/um/x64;c:/Program Files (x86)/Windows Kits/10/lib/10.0.17763.0/ucrt/x64
C:\build> rem Run cmake as usual
C:\build> cmake -G"NMake Makefiles" .
-- The C compiler identification is MSVC 19.29.30037.0
-- The CXX compiler identification is MSVC 19.29.30037.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files/BullseyeCoverage/bin/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files/BullseyeCoverage/bin/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: C:/build
C:\build> rem Enable coverage build before building
C:\build> cov01 -q -1
C:\build> rem Build with nmake as usual
C:\build> nmake -nologo
Scanning dependencies of target hello
[ 50%] Building CXX object CMakeFiles/hello.dir/hello.cpp.obj
BullseyeCoverage Compile 9.5.0 Windows
Copyright (c) Bullseye Testing Technology
hello.cpp
[100%] Linking CXX executable hello.exe
BullseyeCoverage Compile 9.5.0 Windows
Copyright (c) Bullseye Testing Technology
BullseyeCoverage Compile 9.5.0 Windows
Copyright (c) Bullseye Testing Technology
[100%] Built target hello

Unix-like Makefiles

To use BullseyeCoverage with CMake generating Unix-like makefiles:

  1. Set CMAKE_PROGRAM_PATH so that it contains BullseyeCoverage/bin followed by your compiler directory.
  2. Set CMAKE_CXX_COMPILER and CMAKE_C_COMPILER to the basename of the respective compiler commands.
  3. Set the PATH environment variable so that it contains BullseyeCoverage/bin followed by your compiler directory.
  4. Run cmake as usual
  5. Run cov01 -1
  6. Run make as usual

Example toolchain.cmake:

LIST(PREPEND CMAKE_PROGRAM_PATH /opt/BullseyeCoverage/bin;your-compiler/bin)
set(CMAKE_CXX_COMPILER g++)
set(CMAKE_C_COMPILER gcc)

Example CMakeLists.txt:

cmake_minimum_required(VERSION 3.18)
project(hello)
add_executable(hello hello.cpp)

Example commands:

$ PATH=/opt/BullseyeCoverage/bin:/opt/compiler/bin:$PATH
$ cmake -G"Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=toolchain.cmake .
-- The C compiler identification is GNU 11.1.0
-- The CXX compiler identification is GNU 11.1.0
-- Check for working C compiler: /opt/BullseyeCoverage/bin/gcc
-- Check for working C compiler: /opt/BullseyeCoverage/bin/gcc - works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /opt/BullseyeCoverage/bin/g++
-- Check for working CXX compiler: /opt/BullseyeCoverage/bin/g++ - works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /build
$ cov01 -q -1
$ make
Scanning dependencies of target hello
[ 50%] Building CXX object CMakeFiles/hello.dir/hello.cpp.o
BullseyeCoverage Compile 9.5.0 Linux-x64
Copyright (c) Bullseye Testing Technology
[100%] Linking CXX executable hello
BullseyeCoverage Compile 9.5.0 Linux-x64
Copyright (c) Bullseye Testing Technology
[100%] Built target hello

Updated: 31 Oct 2022