Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configuring cpp sources in gradle

I have set up a project on top of Qt (so source is written in C++) and I wanted to try Gradle for automatic builds on that. It took me some time to get into the details of configuring a multi project build (there is an executable and two libs) and now I am trying to tell the cpp-exe and the cpp-lib plugin how my source tree is structured.

I have set up a task that should print all of the source sets (there should be at least the default ones right?) and it looks like this:

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

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

If I run this task Gradle tells me that there is no property "sourceSets" for the project. The documentation of the plugin tells me that it is possible to customize the source locations, but not how.

So my question would be: How can I tell the Gradle cpp plugin which source files to use. If there is any documentation about the cpp plugin apart from its API documentation and the Gradle user guide that would be helping too.

like image 810
HaMster Avatar asked Jul 11 '12 07:07

HaMster


1 Answers

Have a look at Adam Murdoch's usage of Gradle's 'cpp plugin'. I believe he's one of the main Gradle submitters, so he should know how to use this better than anyone:

Exert from 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

I've not had too long to look over it myself, but it looks like he defines a number of OS architecture based source code include combinations and stores these in the variants variable. He then processes them into platform JARs (I haven't actually ran the build yet, maybe I should).

Also, take a look at https://github.com/rklaren/GradleJNI, it uses the cpp plugin but looks to be a little Windows-oriented.

Update - I also found https://github.com/alkemist/gradle-cpp-demo, which has an example of the 'cpp-exe' plugin building an executable.

like image 83
Big Rich Avatar answered Sep 17 '22 23:09

Big Rich