【问题标题】:Configuring cpp sources in gradle在 gradle 中配置 cpp 源
【发布时间】:2015-03-18 20:04:42
【问题描述】:

我已经在 Qt 之上建立了一个项目(所以源代码是用 C++ 编写的),我想尝试使用 Gradle 进行自动构建。我花了一些时间来了解配置多项目构建的细节(有一个可执行文件和两个库),现在我试图告诉cpp-execpp-lib 插件我的源代码树是如何构建的。

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

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

doFirst {
    task -> print ("""${task.project.sourceSets.all}""")
}

如果我运行此任务,Gradle 会告诉我该项目没有属性“sourceSets”。 The documentation of the plugin 告诉我可以自定义源位置,但不能自定义。

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

【问题讨论】:

    标签: c++ build-automation gradle


    【解决方案1】:

    查看 Gradle 的 'cpp plugin'Adam Murdoch's usage。我相信他是主要的 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
    

    我自己没时间看,但看起来他定义了许多基于 OS 架构的源代码,包括组合并将它们存储在 variants 变量中。然后他将它们处理成平台 JAR(我实际上还没有运行构建,也许我应该)。

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

    更新 - 我还找到了https://github.com/alkemist/gradle-cpp-demo,其中有一个“cpp-exe”插件构建可执行文件的示例。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-09-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-05
      相关资源
      最近更新 更多