Native: How to add global compile flag?

I’m evaluating Gradle for C/C++ use in our enterprise business. This will be the first of probably many questions that I’ll be asking.

Can I specify a compiler flag that will be applied to all targets in the build? For instance, if my project has 150 different targets (I wish I was exaggerating), I don’t want to specify cppCompiler.args '-Wall' on every single one of them.

Yes, you can do:

model {
   components {
      binaries.withType(NativeBinary) {
         cppCompiler.args '-Wall'
      }
   }
}

Or write a RuleSource plugin that would do the same.

Thank you. That worked perfectly. Seemingly simple question but I’m brand new to Gradle and couldn’t quite figure that one out :slight_smile:

I can’t create another topic today, so I’m just going to drop this here:

[quote]As mentioned in another post, I’m evaluating Gradle’s Native capabilities for use in our enterprise business. We currently do not have a standard C/C++ build system (using Maven for Java and whatever the team wants for C/C++) and are investigating our options. Gradle seems great, and a few of my biggest concerns have already been answered in other posts. Here are my remaining ones:

  • Warnings are hidden/ignored during compilation. They can be printed with the -i flag, but this also includes a lot of other verbose output and is no longer easy to read.

  • No Eclipse project generation - with Visual Studio supported, Eclipse might be supported soon?

  • No automatic listing of target dependencies, either text or graphical

In my opinion, biggest hurdle to adoption by far is the hidden warnings. Personally, I can’t recommend a C/C++ build system which does not provide clear indication of compiler warnings.

The next step I think would be working to create an Eclipse plugin or, my preference (not necessarily my company’s), working with JetBrains to add native Gradle support to CLion.

And finally, CMake’s support for graphviz is fantastic. I know it’s probably a pipedream, but I’d love to see that (or similar) in Gradle.[/quote]

1 Like

Warnings is a big one. We would also need to see them to be able to use gradle. Warnings should also be available so we could post process them, for example fail if something is present that is not on a white list.

Buildship helps with Eclipse but is not really ready for native builds

1 Like

If you are going across multiple build.gradle files you should take a look at all projects in the DSL.

I have a small example at: