diff --git a/plugins/gradle/native/tooling/src/builder/CppModelBuilder.java b/plugins/gradle/native/tooling/src/builder/CppModelBuilder.java index fbb48b94ecda..a8c3586227e3 100644 --- a/plugins/gradle/native/tooling/src/builder/CppModelBuilder.java +++ b/plugins/gradle/native/tooling/src/builder/CppModelBuilder.java @@ -57,6 +57,9 @@ import java.util.*; * @author Vladislav.Soroka */ public class CppModelBuilder implements ModelBuilderService { + private static final boolean IS_48_OR_BETTER = GradleVersion.current().getBaseVersion().compareTo(GradleVersion.version("4.8")) >= 0; + private static final boolean IS_47_OR_BETTER = IS_48_OR_BETTER || + GradleVersion.current().getBaseVersion().compareTo(GradleVersion.version("4.7")) >= 0; @Override public boolean canBuild(String modelName) { @@ -87,7 +90,7 @@ public class CppModelBuilder implements ModelBuilderService { } List compilerArgs = new ArrayList(); - Set compileIncludePath = cppBinary.getCompileIncludePath().getFiles(); + Set compileIncludePath = new LinkedHashSet(cppBinary.getCompileIncludePath().getFiles()); Map sources = new HashMap(); for (File file : cppBinary.getCppSource().getFiles()) { @@ -103,7 +106,17 @@ public class CppModelBuilder implements ModelBuilderService { CppCompile cppCompile = compileTask.get(); compileTaskName = cppCompile.getPath(); compilerArgs.addAll(cppCompile.getCompilerArgs().getOrElse(Collections.emptyList())); - systemIncludes.addAll(cppCompile.getIncludes().getFiles()); + + //Since Gradle 4.8, system header include directories should be accessed separately via the systemIncludes property + //see https://github.com/gradle/gradle-native/blob/master/docs/RELEASE-NOTES.md#better-control-over-system-include-path-for-native-compilation---583 + if (IS_48_OR_BETTER) { + compileIncludePath.addAll(cppCompile.getIncludes().getFiles()); + systemIncludes.addAll(cppCompile.getSystemIncludes().getFiles()); + } + else { + systemIncludes.addAll(cppCompile.getIncludes().getFiles()); + } + appendFileSettings(sources, project, cppBinary, cppCompile); } @@ -196,7 +209,7 @@ public class CppModelBuilder implements ModelBuilderService { private static File getExecutableFile(LinkExecutable linkExecutable) { File executableFile; RegularFileProperty binaryFile = null; - if (GradleVersion.current().compareTo(GradleVersion.version("4.7")) >= 0) { + if (IS_47_OR_BETTER) { binaryFile = linkExecutable.getLinkedFile(); } else { @@ -292,7 +305,7 @@ public class CppModelBuilder implements ModelBuilderService { } } - if (GradleVersion.current().getBaseVersion().compareTo(GradleVersion.version("4.6")) <= 0) { + if (!IS_47_OR_BETTER) { project.getLogger().error( "[sync error] Unable to resolve compiler executable. " + "The project uses '" + GradleVersion.current() + "' try to update the gradle version");