Step 9: Using the Command Line¶
Added in version 4.4.
This step extends Step 8 by replacing the dashboard script with ctest command lines in a shell script.
#!/bin/sh
cd "$(dirname "$0")"
site=$(uname -n)
presets="$(pwd)/../Step8/CMakePresets.json"
rm -rf build
# Start a new dashboard and configure an empty build tree.
ctest -T Start -T Configure -T Submit \
--source-dir ../Project \
--build-dir build \
-D CTEST_BUILD_NAME="Step9: command line" \
-D CTEST_SITE="$site" \
-D CTEST_PRESET=coverage \
-D CTEST_PRESETS_FILE="$presets" \
-D CTEST_SUBMIT_PARTS=Configure
# Report the current Git commit.
ctest -T Update -T Submit \
--build-dir build \
-D CTEST_UPDATE_COMMAND=git \
-D CTEST_UPDATE_VERSION_ONLY=1 \
-D CTEST_SUBMIT_PARTS=Update
# Build.
ctest -T Build -T Submit \
--build-dir build \
-D CTEST_PRESET=coverage \
-D CTEST_PRESETS_FILE="$presets" \
-D CTEST_USE_LAUNCHERS=1 \
-D CTEST_SUBMIT_PARTS=Build
# Test.
ctest -T Test -T Submit \
--build-dir build \
-D CTEST_PRESET=coverage \
-D CTEST_PRESETS_FILE="$presets" \
-D CTEST_SUBMIT_PARTS=Test
# Compute coverage, and tell CDash the build is done.
ctest -T Coverage -T Submit \
--build-dir build \
-D CTEST_SUBMIT_PARTS="Coverage;Done"
Each ctest invocation runs the steps given by
ctest -T, and sets variables with
-D <var>=<value> instead of the
set() command.
The first invocation configures an empty build tree, using the
--source-dir and
--build-dir options. The later invocations run in
that build tree and add their results to the same submission.
Each invocation ends with a Submit step. The
CTEST_SUBMIT_PARTS variable limits it to the results of that
invocation, so that earlier results are not submitted again. The last
invocation also submits the Done part, which tells CDash that the build
is complete.
A dashboard script and command lines each have advantages:
A script can use the CMake language for logic, such as loops and conditions, and keeps every step in one file.
Command lines can run the steps separately, such as in different jobs of a CI pipeline, and need no
.cmakefile.
Requirements¶
GCC or Clang, which support the
--coverageflag.A
gcovtool that matches the compiler version, found in thePATH.A POSIX shell to run the script.
Running the Script¶
sh Step9/submit.sh