From cc9645f11b46aaad36658d62d38a5e44a5ba5ae5 Mon Sep 17 00:00:00 2001 From: Robert Loehning Date: Wed, 29 Aug 2018 22:18:42 +0200 Subject: [PATCH] configure: Add switch for adding coverage info Change-Id: If6f3d4f29233206ef911f48e63872d28bf7b8e71 Reviewed-by: Oswald Buddenhagen --- config_help.txt | 3 +++ configure.json | 22 ++++++++++++++++++++++ configure.pri | 15 +++++++++++++++ mkspecs/common/clang.conf | 4 ++++ mkspecs/features/coverage.prf | 7 +++++++ 5 files changed, 51 insertions(+) create mode 100644 mkspecs/features/coverage.prf diff --git a/config_help.txt b/config_help.txt index 5b32eb183f9..f8da33d4ec4 100644 --- a/config_help.txt +++ b/config_help.txt @@ -135,6 +135,9 @@ Build options: for example, -sanitize address cannot be combined with -sanitize thread. + -coverage {trace-pc-guard} + Add code coverage instrumentation (Clang only) + -c++std .... Select C++ standard [c++1z/c++14/c++11] (Not supported with MSVC) diff --git a/configure.json b/configure.json index 522bd34e9b9..d6568b9a7fb 100644 --- a/configure.json +++ b/configure.json @@ -67,6 +67,7 @@ "commercial": "void", "compile-examples": { "type": "boolean", "name": "compile_examples" }, "confirm-license": "void", + "coverage": "coverage", "dbus": { "type": "optionalString", "values": [ "no", "yes", "linked", "runtime" ] }, "dbus-linked": { "type": "void", "name": "dbus", "value": "linked" }, "dbus-runtime": { "type": "void", "name": "dbus", "value": "runtime" }, @@ -791,6 +792,16 @@ "condition": "features.sanitize_address || features.sanitize_thread || features.sanitize_memory || features.sanitize_undefined", "output": [ "sanitizer", "publicConfig" ] }, + "coverage_trace_pc_guard": { + "label": "trace-pc-guard", + "autoDetect": false, + "output": [ "publicConfig" ] + }, + "coverage": { + "label": "Code Coverage Instrumentation", + "condition": "features.coverage_trace_pc_guard", + "output": [ "publicConfig" ] + }, "GNUmake": { "label": "GNU make", "autoDetect": false, @@ -1268,6 +1279,11 @@ Qt can be built in release mode with separate debug information, so "type": "error", "condition": "(features.rpath || features.rpath_dir) && var.QMAKE_LFLAGS_RPATH == ''", "message": "This platform does not support RPATH" + }, + { + "type": "error", + "condition": "features.coverage && !config.clang", + "message": "Command line option -coverage is only supported with clang compilers." } ], @@ -1401,6 +1417,12 @@ Configure with '-qreal float' to create a build that is binary-compatible with 5 "condition": "features.sanitizer", "entries": [ "sanitize_address", "sanitize_thread", "sanitize_memory", "sanitize_undefined" ] }, + { + "message": "Code Coverage Instrumentation", + "type": "firstAvailableFeature", + "args": "coverage_trace_pc_guard", + "condition": "features.coverage" + }, { "message": "Build parts", "type": "buildParts" diff --git a/configure.pri b/configure.pri index 64ed6b9ed81..3f3d2da5716 100644 --- a/configure.pri +++ b/configure.pri @@ -58,6 +58,21 @@ defineTest(qtConfCommandline_sanitize) { } } +defineTest(qtConfCommandline_coverage) { + arg = $${1} + val = $${2} + isEmpty(val): val = $$qtConfGetNextCommandlineArg() + !contains(val, "^-.*"):!isEmpty(val) { + equals(val, "trace-pc-guard") { + qtConfCommandlineSetInput("coverage_trace_pc_guard", "yes") + } else { + qtConfAddError("Invalid argument $$val to command line parameter $$arg") + } + } else { + qtConfAddError("Missing argument to command line parameter $$arg") + } +} + # callbacks defineReplace(qtConfFunc_crossCompile) { diff --git a/mkspecs/common/clang.conf b/mkspecs/common/clang.conf index 5800aaa5b46..dacd1539cf9 100644 --- a/mkspecs/common/clang.conf +++ b/mkspecs/common/clang.conf @@ -44,3 +44,7 @@ QMAKE_LFLAGS_LTCG = $$QMAKE_CFLAGS_LTCG QMAKE_AR_LTCG = llvm-ar cqs QMAKE_NM_LTCG = llvm-nm -P QMAKE_RANLIB_LTCG = true # No need to run, since llvm-ar has "s" + +QMAKE_CFLAGS_COVERAGE_TRACE_PC_GUARD = -fsanitize-coverage=trace-pc-guard +QMAKE_CXXFLAGS_COVERAGE_TRACE_PC_GUARD = -fsanitize-coverage=trace-pc-guard +QMAKE_LFLAGS_COVERAGE_TRACE_PC_GUARD = -fsanitize-coverage=trace-pc-guard diff --git a/mkspecs/features/coverage.prf b/mkspecs/features/coverage.prf new file mode 100644 index 00000000000..b8b37e1b801 --- /dev/null +++ b/mkspecs/features/coverage.prf @@ -0,0 +1,7 @@ +# Coverage flags + +coverage_trace_pc_guard { + QMAKE_CFLAGS += $$QMAKE_CFLAGS_COVERAGE_TRACE_PC_GUARD + QMAKE_CXXFLAGS += $$QMAKE_CXXFLAGS_COVERAGE_TRACE_PC_GUARD + QMAKE_LFLAGS += $$QMAKE_LFLAGS_COVERAGE_TRACE_PC_GUARD +}