6

I need to pass -j argument to ninja while building Android app with gradle. (on Windows)

Why do I need this? - We have huge unified c++ files that require lots of memory to compile. Currently I have no enough memory (~10GB free) to compile them in parallel on 8 cores. Thus clang fails when memory runs out.

I see that gradle runs cmake with --build key so I've tried to add my -j1 arg there. But seems arguments field is used only for cmake generation, because it doesn't affect command line passed to cmake in build stage.

externalNativeBuild {
    cmake {
        cFlags "..."
        cppFlags "..."
        arguments "... -- -j1"
    }
}

The only way I see now it to replace ninja with some wrapper to pass -j from there. But this is the last options I would like to use. Appreciate any ideas about how to achieve this valid way.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Abuksigun
  • 63
  • 5

1 Answers1

4

You should set CMAKE_BUILD_PARALLEL_LEVEL environment variable to number of concurrent processes you want to use for the build.

It's available since cmake 3.12.4.

https://cmake.org/cmake/help/v3.12/envvar/CMAKE_BUILD_PARALLEL_LEVEL.html

zettd
  • 64
  • 4