[Native] Some questions

Hi guys,

I’m in the process of creating a script for a C/C++ project and have some questions (could’t find the answers in the documentation) :

  1. How do I set precompiled headers?
  2. How do I set the “header search path” for a binary (-I in gcc, /I in Visual Studio). I found a way to include the library but its headers aren’t included: lib library: ‘myLibraryBuiltInGradle’, linkage: ‘static’
  3. Is there a way to generate filters for a **/.cpp source set? Having a source set with **/.cpp, generates a project with all the files in the same filter (virtual folder)
  4. Can I specify the target platform via command line overriding the current OS (for example, I would like to generate a VS project in OS X).
  5. How do I set a toolchain prefix? (For example arm-linux-gnueabihf instead of configuring each tool in the toolchain)
  6. Is there a way of generating Xcode projects?
  7. How do I set/get the output files (*.a, *.so, etc)?
  8. How do I set/get the build directory?

I really want to use Gradle and skip CMake!

Thanks for your time!

It’s not in a stable release yet. http://gradle.org/docs/nightly/userguide/nativeBinaries.html#native_binaries:preCompiledHeaders

That should include ‘myLibraryBuiltInGradle’ headers. Anything that’s configured in exportedHeaders as a srcDir.

Not sure what you mean. You have a single directory with all of your sources and you’d like them to be divided up into multiple libraries? executables?

Can you use VS on OS X?

I don’t think we have a very easy way of doing that right now, you can set the executable name Gradle searches for on each tool or add the ‘-b machine’ option in withArguments.


What do you want to do with them? If you want to repackage them (e.g., put them in a particular structure for a zip), you should use a separate task vs building them into a particular path.

Thanks for your response.

That’s not working for me, but maybe I’m setting the wrong paths. Good to know that it should work. I’ll experiment a bit.

I have the following strucuture



But in the generated VS project all the cpp files appear in the same “Sources” filter. I don’t see the corresponding filters:



Of course not. But I’m interested in generating VS projects in Linux or OS X. In addition, I would like to cross compile for a different OS than the current.

Maybe I wasn’t clear. I would like to set and get the “Location of created binary” (for example, ${project.buildDir}/binaries/${component.name}StaticLibrary/${component.name}.a)

If you haven’t found them already, the samples have lots of examples of different things:

They can be helpful, especially on new things (like native support) where the documentation lags behind.

I’m not super familiar with the way we generate the VS projects, so I’ll have to look. I think we may cram everything into one filter to keep it simple. Would it be more useful if we put them in a filter with the same name as the sourceSet (maybe special casing for a single source set) or let you customize it on a sourceSet level?

You should be able to cross-compile with GCC. You’ll basically see different tasks for each platform. So if you want to build for i386, x64 and arm, you have to define each platform and say your component targets that platform. You’ll get a different task to build each variant, but you can add helper tasks to build only a subset.

We don’t have much support with anything other than VS for IDEs though.

RIght, but why do you want to put them somewhere other than the default?

You can change where the files go (and their names) by messing with either the task that produces them (e.g., LinkExecutable, LinkSharedLibrary) or their binary spec (e.g., NativeExecutableBinarySpec). You can find the binaries with binaries.withType(...)

Thanks again.

I didn’t know the native support was that new. I’m new to Gradle. It doesn’t seem new because has lots of features. The documentation is scary though… But that make sense now knowing that is a WIP.

Yes. They were my main source of information along with the DSL, the source code and this forum (incredibly helpful by the way).

The way I see people organise the projects in VS, Xcode and other IDEs that uses “filters”, “virtual folders” or “groups” are two:

  1. Recreate the source directory tree using groups (what I’m would like to do)
  2. Put all files in the same “filter”(what Gradle is doing)

Being able to customise the name of the root filter would be great too (whatever using 1) or 2)).

Can I set compiler flags for a specific file? I could use this feature as a workaround for Gradle 2.3

It would be awesome if Gradle could generate Xcode projects targeting OS X and iOS. I could implement it when the native subproject is stable.

Sneaky edit :smile:

You can set compiler flags for a binary (library, executable, etc), but not individual files right now.

A couple of workarounds I could think of…

  1. Separate out the special source files as a static library binary. Have the “main” component depend on that static library.
  2. Separate out the special source files as a source set
    a. Hook into the compile task for that source set and set the arguments
    b. Add source set dependencies if another source set requires the special one to compile

Oh sorry, I thought you received notifications about the edit! :stuck_out_tongue:

Thanks, I’m trying them.

Good weekend and thanks again.

I did, but I had to diff the posts :smile:

Registered… :blush:

Is there a timeline for being able to set compiler flags for a specific file?