2

I have a simple C program (helloworld) compiling and building on my Windows 7 machine (via MinGW) using Make. I would now like to switch my build system to use Gradle (personal reasons, no disrespect to Make!) and am trying to wrap my brain around the Gradle Native Plugins (and really, the C plugin).

I have two specific concerns:

  • Does the C plugin require a certain project directory structure like most other Gradle plugins do? In the C plugin's docs, I see several instances of a source folder named src/main/headers. In Java-land, Gradle by default expects you to have, say, src/main/java and src/main/resources, to function properly etc. If the same is true of the C plugin, what is this required/recommended directory structure for a C program?
  • I understand the documentation's explanation of platforms, but flavors flew right over my head; and using platforms and flavors together is an even bigger mystery. Say I want to define one build variant to support Linux on x86 architecture, and another variant to support 64-bit Windows. What's an example of a platform/flavor combo that would achieve these variants?
smeeb
  • 27,777
  • 57
  • 250
  • 447

1 Answers1

3

The convention for native binaries in Gradle is to put headers in src/{componentName}/headers and C source files in src/{componentName}/c, where componentName would be whatever you name the component (given the question, I'm guessing that would be helloworld, but it depends on how you declare it). Flavors are for different variants of the build, like if you wanted to build versions with different features compiled. Compiling for different targets like x86 Linux and 64-bit Windows would be done just with platforms, like this:

model {
    platforms {
        linux32 {
            architecture "x86"
            operatingSystem "linux"
        }
        win64 {
            architecture "x86_64"
            operatingSystem "windows"
        }
    }
}

I'm assuming you're using Gradle 2.3, but things have changed a lot over the past couple of releases.

Ben Navetta
  • 457
  • 5
  • 8