Kotlin Gradle DSL cpp-library source wildcard

271 views Asked by At

Gradle offers a plugin which compiler cpp-library

build.gradle.kts

plugins {
    `cpp-library`
}
library {
    targetMachines.add(machines.windows.x86_64)
    linkage.set(listOf(Linkage.SHARED))
    source.from("src/main/cpp/*.txt")
}

I am getting below output

:compileDebugCpp NO-SOURCE

How to use the source.from to specify custom file extension like *.txt

1

There are 1 answers

0
Dickens A S On

I found the solution my self

I need to put the source in the compilation task as below

tasks.withType(CppCompile::class.java).configureEach {
    source.from(fileTree("${project.rootDir}/${project.name}/src/main/cpp").matching {
        include("*.txt")
    })
}

this allow the gradle C++ compiler task compile .txt files instead of .cpp file

So in case if I want to compiler fortran then I can put *.f or *.f90