From ea1195f9fa8fe6850755f1289d82315283947cc5 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Mon, 9 Jan 2023 17:29:40 +0200 Subject: [PATCH] Added support for ccache. --- qbs/imports/VApp.qbs | 6 +++ qbs/imports/VLib.qbs | 5 ++ qbs/modules/buildconfig/buildconfig.qbs | 8 +++ qbs/modules/ccache/ccache.qbs | 65 +++++++++++++++++++++++++ 4 files changed, 84 insertions(+) create mode 100644 qbs/modules/ccache/ccache.qbs diff --git a/qbs/imports/VApp.qbs b/qbs/imports/VApp.qbs index cfbfc0306..f0353620d 100644 --- a/qbs/imports/VApp.qbs +++ b/qbs/imports/VApp.qbs @@ -24,10 +24,16 @@ CppApplication { installDebugInformation: true type: base.concat("testSuit") + Properties { + condition: qbs.targetOS.contains("unix") && buildconfig.buildWithCcache + cpp.compilerWrapper: "ccache" + } + Properties { condition: Qt.core.versionMajor >= 5 && Qt.core.versionMinor < 12 cpp.cxxLanguageVersion: "c++11" } + // Since Qt 5.12 available support for C++17 Properties { condition: Qt.core.versionMajor >= 5 && Qt.core.versionMinor >= 12 diff --git a/qbs/imports/VLib.qbs b/qbs/imports/VLib.qbs index adc133181..9e4203e7f 100644 --- a/qbs/imports/VLib.qbs +++ b/qbs/imports/VLib.qbs @@ -19,6 +19,11 @@ Library { cpp.rpaths: cpp.rpathOrigin } + Properties { + condition: qbs.targetOS.contains("unix") && buildconfig.buildWithCcache + cpp.compilerWrapper: "ccache" + } + install: !buildconfig.staticBuild installDir: buildconfig.installLibraryPath installDebugInformation: !buildconfig.staticBuild diff --git a/qbs/modules/buildconfig/buildconfig.qbs b/qbs/modules/buildconfig/buildconfig.qbs index f3b5e3325..f1a141100 100644 --- a/qbs/modules/buildconfig/buildconfig.qbs +++ b/qbs/modules/buildconfig/buildconfig.qbs @@ -20,6 +20,14 @@ Module { // distributions which provides not enough space on build servers. property bool enablePCH: true + Depends { name: "ccache"; } + + // Use this property to disable the use of ccache. + property bool enableCcache: true + readonly property bool ccachePresent: ccache.ccachePresent + readonly property bool ccachePCHSupport: ccache.pchSupport + readonly property bool buildWithCcache: enableCcache && (enablePCH && ccachePresent && ccachePCHSupport || (!enablePCH && ccachePresent)) + property string libDirName: "lib" property string appTarget diff --git a/qbs/modules/ccache/ccache.qbs b/qbs/modules/ccache/ccache.qbs new file mode 100644 index 000000000..305419d3c --- /dev/null +++ b/qbs/modules/ccache/ccache.qbs @@ -0,0 +1,65 @@ +import qbs.Process +import qbs.Utilities + +// Don't forget to edit ccache config: +// ccache --set-config=sloppiness=pch_defines,time_macros,include_file_mtime,include_file_ctime +Module { + readonly property bool ccachePresent: ccacheProbe.present + readonly property bool pchSupport: ccachePCHProbe.pchSupport + + // change to shell tool which supports key "-c" to excecute command line + property string shellTool: "bash" + + // ccache doesn't provide key to get only version number + readonly property string command: "ccache --version | head -n 1 | grep -oE '[0-9]((\.)[0-9]){0,2}'" + + Probe { + id: ccacheProbe + + property bool present + property string tool: shellTool + property string toolCommand: command + + configure: { + var detector = new Process(); + try { + if (detector.exec(tool, ["-c", toolCommand]) === 0) { + var version = detector.readStdOut().trim(); // we can read only one time + present = Utilities.versionCompare(version, "0.0.0") >= 0; + console.info("Found ccache version " + version + "."); + } + } finally { + detector.close(); + } + } + } + + Probe { + id: ccachePCHProbe + condition: ccachePresent === true + property string tool: shellTool + property string toolCommand: command + + property bool pchSupport + + configure: { + var detector = new Process(); + try { + if (detector.exec(tool, ["-c", toolCommand]) === 0) { + var version = detector.readStdOut().trim(); // we can read only one time + + pchSupport = Utilities.versionCompare(version, "3.1.0") >= 0; + if (!pchSupport && Utilities.versionCompare(version, "3.1.0") < 0){ + console.info("ccache is tool old, version >= 3.1.0 required to work with precompiled headers."); + pchSupport = false; + } + + if (pchSupport) + console.info("ccache supports compilation with precompiled headers.") + } + } finally { + detector.close(); + } + } + } +}