aboutsummaryrefslogtreecommitdiffstats
path: root/share/qbs/modules/cpp/GenericGCC.qbs
diff options
context:
space:
mode:
authorJake Petroules <jake.petroules@qt.io>2017-12-07 23:28:55 -0800
committerJake Petroules <jake.petroules@qt.io>2017-12-19 21:25:20 +0000
commit5b9da6dc85c55e3a76611c3ac78c1015119c2ac2 (patch)
tree3c2dc92d2b89b1a39c1ed078d95588ba2efa2b37 /share/qbs/modules/cpp/GenericGCC.qbs
parentc356842556073a22e5b555120d6bacf88c6719bd (diff)
Validate the compiler's target platform as well as arch and endianness
This helps to block inappropriate host compilers when cross compiling. Change-Id: Ied22fce094fdb726babea4e94a7ef1d78afc9a98 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Diffstat (limited to 'share/qbs/modules/cpp/GenericGCC.qbs')
-rw-r--r--share/qbs/modules/cpp/GenericGCC.qbs66
1 files changed, 50 insertions, 16 deletions
diff --git a/share/qbs/modules/cpp/GenericGCC.qbs b/share/qbs/modules/cpp/GenericGCC.qbs
index 824bdd18d..7773e3d5d 100644
--- a/share/qbs/modules/cpp/GenericGCC.qbs
+++ b/share/qbs/modules/cpp/GenericGCC.qbs
@@ -278,29 +278,62 @@ CppModule {
+ "cpp.compilerName instead.");
}
- var validator = new ModUtils.PropertyValidator("cpp");
- validator.setRequiredProperty("architecture", architecture,
- "you might want to re-run 'qbs-setup-toolchains'");
+ var isWrongTriple = false;
+
if (gccProbe.architecture) {
- validator.addCustomValidator("architecture", architecture, function (value) {
- return Utilities.canonicalArchitecture(architecture) === Utilities.canonicalArchitecture(gccProbe.architecture);
- }, "'" + architecture + "' differs from the architecture produced by this compiler (" +
- gccProbe.architecture +")");
- } else {
+ if (Utilities.canonicalArchitecture(architecture)
+ !== Utilities.canonicalArchitecture(gccProbe.architecture))
+ isWrongTriple = true;
+ } else if (architecture) {
// This is a warning and not an error on the rare chance some new architecture comes
// about which qbs does not know about the macros of. But it *might* still work.
- if (architecture)
- console.warn("Unknown architecture '" + architecture + "' " +
- "may not be supported by this compiler.");
+ console.warn("Unknown architecture '" + architecture + "' " +
+ "may not be supported by this compiler.");
}
if (gccProbe.endianness) {
- validator.addCustomValidator("endianness", endianness, function (value) {
- return endianness === gccProbe.endianness;
- }, "'" + endianness + "' differs from the endianness produced by this compiler (" +
- gccProbe.endianness + ")");
+ if (endianness !== gccProbe.endianness)
+ isWrongTriple = true;
} else if (endianness) {
- console.warn("Could not detect endianness ('" + endianness + "' given)");
+ console.warn("Could not detect endianness ('"
+ + endianness + "' given)");
+ }
+
+ if (gccProbe.targetPlatform) {
+ // Can't differentiate Darwin OSes at the compiler level alone
+ if (gccProbe.targetPlatform === "darwin"
+ ? !qbs.targetOS.contains("darwin")
+ : qbs.targetPlatform !== gccProbe.targetPlatform)
+ isWrongTriple = true;
+ } else if (qbs.targetPlatform) {
+ console.warn("Could not detect target platform ('"
+ + qbs.targetPlatform + "' given)");
+ }
+
+ if (isWrongTriple) {
+ var realTriple = [
+ Utilities.canonicalArchitecture(gccProbe.architecture),
+ gccProbe.targetPlatform,
+ gccProbe.endianness ? gccProbe.endianness + "-endian" : undefined
+ ].join("-");
+ var givenTriple = [
+ Utilities.canonicalArchitecture(architecture),
+ qbs.targetPlatform,
+ endianness ? endianness + "-endian" : undefined
+ ].join("-");
+ var msg = "The selected compiler '" + compilerPath + "' produces code for '" +
+ realTriple + "', but '" + givenTriple + "' was given, which is incompatible.";
+ if (validateTargetTriple) {
+ msg += " If you are absolutely certain that your configuration is correct " +
+ "(check the values of the qbs.architecture, qbs.targetPlatform, " +
+ "and qbs.endianness properties) and that this message has been " +
+ "emitted in error, set the cpp.validateTargetTriple property to " +
+ "false. However, you should consider submitting a bug report in any " +
+ "case.";
+ throw ModUtils.ModuleError(msg);
+ } else {
+ console.warn(msg);
+ }
}
var validateFlagsFunction = function (value) {
@@ -314,6 +347,7 @@ CppModule {
return true;
}
+ var validator = new ModUtils.PropertyValidator("cpp");
var msg = "'-target', '-triple', '-arch' and '-march' cannot appear in flags; set qbs.architecture instead";
validator.addCustomValidator("assemblerFlags", assemblerFlags, validateFlagsFunction, msg);
validator.addCustomValidator("cppFlags", cppFlags, validateFlagsFunction, msg);