Moved clang flags out of the root build.gardle.
Collected clang args in ClangArgs.kt Switched dependencies/build.gradle to KonanTarget. Introduced KonanProperties to take care of target specific properties.
This commit is contained in:
committed by
alexander-gorshenev
parent
1d532729a8
commit
55c4966203
@@ -22,52 +22,7 @@ import org.gradle.api.tasks.InputDirectory
|
||||
import org.gradle.api.tasks.OutputFile
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
|
||||
class CompilePerTarget extends CompileCppToBitcode {
|
||||
private List<String> targetList = []
|
||||
private Map<String, List<String>> targetArgs = null
|
||||
private Map<String, List<String>> targetLinkerArgs = null
|
||||
|
||||
void targetList(List<String> list) {
|
||||
targetList.addAll(list)
|
||||
}
|
||||
|
||||
void targetArgs(Map<String, List<String>> map) {
|
||||
targetArgs = map
|
||||
}
|
||||
|
||||
private Map<String, List<String>> getTargetArgs() {
|
||||
return targetArgs
|
||||
}
|
||||
|
||||
void targetLinkerArgs(Map<String, List<String>> map) {
|
||||
targetLinkerArgs = map
|
||||
}
|
||||
|
||||
private Map<String, List<String>> getTargetLinkerArgs() {
|
||||
return targetLinkerArgs
|
||||
}
|
||||
|
||||
@TaskAction
|
||||
void compile() {
|
||||
def targetList = this.targetList
|
||||
def targetArgs = getTargetArgs()
|
||||
def targetLinkerArgs = getTargetLinkerArgs()
|
||||
def commonCompilerArgs = getCompilerArgs().clone()
|
||||
def commonLinkerArgs = getLinkerArgs().clone()
|
||||
targetList.each {
|
||||
this.compilerArgs = []
|
||||
this.linkerArgs = []
|
||||
target(it)
|
||||
compilerArgs(commonCompilerArgs)
|
||||
if (targetArgs != null)
|
||||
compilerArgs(targetArgs[it])
|
||||
linkerArgs(commonLinkerArgs)
|
||||
if (targetLinkerArgs != null)
|
||||
linkerArgs(targetLinkerArgs[it])
|
||||
super.compile()
|
||||
}
|
||||
}
|
||||
}
|
||||
import org.jetbrains.kotlin.konan.target.KonanTarget
|
||||
|
||||
class CompileCppToBitcode extends DefaultTask {
|
||||
private String name = "main"
|
||||
@@ -123,6 +78,10 @@ class CompileCppToBitcode extends DefaultTask {
|
||||
return linkerArgs
|
||||
}
|
||||
|
||||
protected String getTarget() {
|
||||
return target
|
||||
}
|
||||
|
||||
void compilerArgs(String... args) {
|
||||
compilerArgs.addAll(args)
|
||||
}
|
||||
@@ -139,6 +98,11 @@ class CompileCppToBitcode extends DefaultTask {
|
||||
linkerArgs.addAll(args)
|
||||
}
|
||||
|
||||
List<String> targetArgs(String target) {
|
||||
def result = project.rootProject.targetClangArgs(KonanTarget.valueOf(target.toUpperCase()))
|
||||
return result
|
||||
}
|
||||
|
||||
@TaskAction
|
||||
void compile() {
|
||||
// the strange code below seems to be required due to some Gradle (Groovy?) behaviour
|
||||
@@ -154,6 +118,7 @@ class CompileCppToBitcode extends DefaultTask {
|
||||
executable "clang++"
|
||||
args '-std=c++11'
|
||||
|
||||
args targetArgs(this.target)
|
||||
args compilerArgs
|
||||
|
||||
args "-I$headersDir"
|
||||
|
||||
@@ -53,12 +53,9 @@ class ExecClang {
|
||||
throw new GradleException("unsupported clang executable: $executable")
|
||||
}
|
||||
|
||||
environment["PATH"] = project.files(project.clangPath).asPath +
|
||||
environment["PATH"] = project.files(project.hostClang.hostClangPath).asPath +
|
||||
File.pathSeparator + environment["PATH"]
|
||||
|
||||
args project.clangArgs
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return project.exec(extendedAction)
|
||||
|
||||
@@ -228,7 +228,7 @@ class NamedNativeInteropConfig implements Named {
|
||||
}
|
||||
|
||||
// TODO: the interop plugin should probably be reworked to execute clang from build scripts directly
|
||||
environment['PATH'] = project.files(project.clangPath).asPath +
|
||||
environment['PATH'] = project.files(project.hostClang.hostClangPath).asPath +
|
||||
File.pathSeparator + environment['PATH']
|
||||
|
||||
args compilerOpts.collectMany { ['-copt', it] }
|
||||
|
||||
Reference in New Issue
Block a user