gradle-plugin: Fix CMake generation

This commit is contained in:
Ilya Matveev
2017-11-28 19:53:41 +07:00
committed by ilmat192
parent 4a8d07493c
commit b47f7dcf73
2 changed files with 16 additions and 8 deletions
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.gradle.plugin.KonanInteropLibrary
import org.jetbrains.kotlin.gradle.plugin.KonanLibrary
import org.jetbrains.kotlin.gradle.plugin.KonanProgram
import org.jetbrains.kotlin.gradle.plugin.konanArtifactsContainer
import org.jetbrains.kotlin.konan.target.Family
import org.jetbrains.kotlin.konan.target.TargetManager
import java.io.File
@@ -70,7 +71,7 @@ open class KonanGenerateCMakeTask : DefaultTask() {
appendln(
Call("cinterop")
.arg("NAME", interop.name)
.arg("DEF_FILE", task.defFile.relativePath.toString())
.arg("DEF_FILE", task.defFile.relativePath.toString().crossPlatformPath)
.arg("COMPILER_OPTS", task.cMakeCompilerOpts)
)
}
@@ -99,11 +100,15 @@ open class KonanGenerateCMakeTask : DefaultTask() {
private val File.relativePath get() = relativeTo(project.projectDir)
private val String.crossPlatformPath get() =
if (TargetManager.host.family == Family.WINDOWS) replace('\\', '/') else this
private val FileCollection.asCMakeSourceList: List<String>
get() = files.map { it.relativePath.toString() }
get() = files.map { it.relativePath.toString().crossPlatformPath }
private val KonanInteropTask.cMakeCompilerOpts: String
get() = compilerOpts.joinToString(" ")
get() = (compilerOpts + includeDirs.allHeadersDirs.map { "-I${it.absolutePath.crossPlatformPath}" })
.joinToString(" ")
private val KonanCompileTask.cMakeSources: String
get() = srcFiles.flatMap { it.asCMakeSourceList }.joinToString(" ")
@@ -112,7 +117,7 @@ open class KonanGenerateCMakeTask : DefaultTask() {
get() = mutableListOf<String>().apply {
addAll(libraries.artifacts.map { it.artifactName })
addAll(libraries.namedKlibs)
addAll(libraries.files.flatMap { it.files }.map { it.canonicalPath })
addAll(libraries.files.flatMap { it.files }.map { it.canonicalPath.crossPlatformPath })
}.joinToString(" ")
private val KonanCompileTask.cMakeLinkerOpts: String
@@ -1,9 +1,12 @@
package org.jetbrains.kotlin.gradle.plugin.test
class CMakeSpecification extends BaseKonanSpecification {
import org.jetbrains.kotlin.konan.target.Family
import org.jetbrains.kotlin.konan.target.TargetManager
class CMakeSpecification extends BaseKonanSpecification {
def 'Plugin should generate CMake from project without additional settings'() {
when:
def sdlIncludePath = (TargetManager.host.family == Family.WINDOWS) ? "C:/SDL2/include" : "/usr/include/SDL2"
def project = KonanProject.createEmpty(projectDirectory) { KonanProject it ->
it.buildFile.write("""
plugins { id 'konan' }
@@ -11,7 +14,7 @@ class CMakeSpecification extends BaseKonanSpecification {
interop('stdio')
interop('sdl') {
defFile 'src/main/c_interop/sdl.def'
includeDirs '/usr/include/SDL2'
includeDirs '$sdlIncludePath'
}
library('main_lib')
program('Main') {
@@ -40,7 +43,7 @@ class CMakeSpecification extends BaseKonanSpecification {
cinterop(
NAME sdl
DEF_FILE src/main/c_interop/sdl.def
COMPILER_OPTS -I/usr/include/SDL2)
COMPILER_OPTS -I$sdlIncludePath)
cinterop(
NAME stdio
@@ -61,7 +64,7 @@ class CMakeSpecification extends BaseKonanSpecification {
cMakeModule.exists()
cMakeLists.exists()
def actualCMakeLists = cMakeLists.text.trim()
def actualCMakeLists = cMakeLists.text.trim().replace('\r\n', '\n')
actualCMakeLists == expectedCMakeLists
}