Qbs: Factor out gtest dependency check

..to make it re-usable.

Change-Id: I7653ee7b3ced5fb9d2b7262aecdab12438628928
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
Christian Stenger
2022-02-21 11:10:54 +01:00
parent e59b7612b1
commit eccbc0fbcc
2 changed files with 67 additions and 44 deletions

View File

@@ -0,0 +1,65 @@
import qbs
import qbs.File
import qbs.FileInfo
Module {
property bool preferExternalLibs: true
Depends { name: "pkgconfig"; condition: preferExternalLibs; required: false }
Depends { name: "gtest"; condition: preferExternalLibs; required: false }
Depends { name: "gmock"; condition: preferExternalLibs; required: false }
Depends { name: "cpp" }
Probe {
id: gtestProbe
property string repoDir
property string gtestDir
property string gmockDir
property bool hasRepo
configure: {
repoDir = FileInfo.cleanPath(path + "/../../../tests/unit/unittest/3rdparty/googletest");
gtestDir = FileInfo.joinPaths(repoDir, "googletest");
gmockDir = FileInfo.joinPaths(repoDir, "googlemock");
hasRepo = File.exists(gtestDir);
found = hasRepo;
}
}
property bool hasRepo: gtestProbe.hasRepo
property bool externalLibsPresent: preferExternalLibs && gtest.present && gmock.present
property bool useRepo: !externalLibsPresent && hasRepo
property string gtestDir: gtestProbe.gtestDir
property string gmockDir: gtestProbe.gmockDir
Group {
name: "Files from repository"
condition: qtc_gtest_gmock.useRepo
cpp.includePaths: [
qtc_gtest_gmock.gtestDir,
qtc_gtest_gmock.gmockDir,
FileInfo.joinPaths(qtc_gtest_gmock.gtestDir, "include"),
FileInfo.joinPaths(qtc_gtest_gmock.gmockDir, "include"),
]
files: [
FileInfo.joinPaths(qtc_gtest_gmock.gtestDir, "src", "gtest-all.cc"),
FileInfo.joinPaths(qtc_gtest_gmock.gmockDir, "src", "gmock-all.cc"),
]
}
Properties {
condition: qtc_gtest_gmock.useRepo
cpp.includePaths: [
FileInfo.joinPaths(qtc_gtest_gmock.gtestDir, "include"),
FileInfo.joinPaths(qtc_gtest_gmock.gmockDir, "include"),
]
}
validate: {
if (!qtc_gtest_gmock.externalLibsPresent && !gtestProbe.found) {
console.warn("No GTest found.");
throw new Error();
}
}
}

View File

@@ -4,52 +4,10 @@ import qbs.FileInfo
Project {
name: "Unit test & helper products"
Product {
name: "qtc_gtest_gmock"
Export {
property bool useExternalLibs: preferExternalLibs && externalLibsPresent
property bool useRepo: !useExternalLibs && hasRepo
property bool preferExternalLibs: true
property bool externalLibsPresent: preferExternalLibs && gtest.present && gmock.present
property string repoDir: FileInfo.joinPaths(path, "3rdparty", "googletest")
property string gtestDir: FileInfo.joinPaths(repoDir, "googletest")
property string gmockDir: FileInfo.joinPaths(repoDir, "googlemock")
property bool hasRepo: File.exists(gtestDir)
Depends { name: "pkgconfig"; condition: preferExternalLibs; required: false }
Depends { name: "gtest"; condition: preferExternalLibs; required: false }
Depends { name: "gmock"; condition: preferExternalLibs; required: false }
Depends { name: "cpp" }
Group {
name: "Files from repository"
condition: qtc_gtest_gmock.useRepo
cpp.includePaths: [
qtc_gtest_gmock.gtestDir,
qtc_gtest_gmock.gmockDir,
FileInfo.joinPaths(qtc_gtest_gmock.gtestDir, "include"),
FileInfo.joinPaths(qtc_gtest_gmock.gmockDir, "include"),
]
files: [
FileInfo.joinPaths(qtc_gtest_gmock.gtestDir, "src", "gtest-all.cc"),
FileInfo.joinPaths(qtc_gtest_gmock.gmockDir, "src", "gmock-all.cc"),
]
}
Properties {
condition: useRepo
cpp.includePaths: [
FileInfo.joinPaths(gtestDir, "include"),
FileInfo.joinPaths(gmockDir, "include"),
]
}
}
}
QtcProduct {
name: "Unit test"
condition: qtc_gtest_gmock.hasRepo || qtc_gtest_gmock.externalLibsPresent
type: ["application", "autotest"]
consoleApplication: true
destinationDirectory: FileInfo.joinPaths(project.buildDirectory,
@@ -72,7 +30,7 @@ Project {
Depends { name: "pkgconfig"; required: false }
Depends { name: "benchmark"; required: false }
Depends { name: "qtc_gtest_gmock" }
Depends { name: "qtc_gtest_gmock"; required: false }
sqlite_sources.buildSharedLib: false