在gradle中配置cpp源

HaM*_*ter 7 c++ build-automation gradle

我在Qt之上设置了一个项目(因此源代码是用C++编写的),我想尝试使用Gradle进行自动构建.我花了一些时间进入配置多项目构建的细节(有一个可执行文件以及两个库),现在我想告诉cpp-exe和cpp-lib插件我的源代码树是如何构成的.

我已经设置了一个应该打印所有源集的任务(至少应该有默认值?),它看起来像这样:

task projectinfo {
description = "Informations about the current project"
group = INFORMATIONS_GROUP

doFirst {
    task -> print ("""${task.project.sourceSets.all}""")
}
Run Code Online (Sandbox Code Playgroud)

如果我运行此任务,Gradle会告诉我该项目没有属性"sourceSets".该插件的文档告诉我可以自定义源位置,但不能如何自定义源位置.

所以我的问题是:如何告诉Gradle cpp插件使用哪些源文件.如果有关于该cpp插件的任何文档,除了它的API文档和Gradle用户指南之外也会有所帮助.

Big*_*ich 9

看看Adam Murdoch对Gradle的'cpp插件'的使用.我相信他是主要的Gradle提交者之一,所以他应该知道如何比任何人更好地使用它:

从native-platform/build.gradle开始

cpp {
    sourceSets {
        main {
            source.exclude 'curses.cpp'
        }
        curses {
            source.srcDirs = ['src/main/cpp']
            source.include 'curses.cpp'
            source.include 'generic.cpp'
            source.include 'generic_posix.cpp'
        }
    }
}

Then, within the 'libraries' node, refer to all/any combination of architecture and source sets:

sourceSets << cpp.sourceSets.main
sourceSets << cpp.sourceSets.curses
Run Code Online (Sandbox Code Playgroud)

我已经没有太长过目它自己,但看起来他定义了许多的OS架构的源代码包含在组合和存储这些变种变量.然后他将它们处理成平台JAR(我还没有实际运行构建,也许我应该).

另外,看看https://github.com/rklaren/GradleJNI,它使用了cpp插件,但看起来有点面向Windows.

更新 - 我还发现了https://github.com/alkemist/gradle-cpp-demo,它有一个构建可执行文件的'cpp-exe'插件的示例.