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