Hey guys!
I’m trying to make my c++ files to get incrementally recompiled on header files changes. I’ve got a plenty of those - headers from 3rd-party libs, headers from autogeneration tools (like javah) and so on.
First, I tried to avoid to manually add them to source sets by **/ *.h mask, and was wondering if gradle could use some .d files generated by gcc-like compilers if run with -MMD flag (like all build systems do - make, cmake, ninja, etc…). But it seems like it can not. Found an old topic,
[cpp-plugin] Header file change didn't cause recompile
people said there that gradle will have a better incremental compilation support implemented later, and that was 2 years ago, but it seems it still relies on manual header including to source sets.
Adding them manually has a number of problems:
- It’s not scalable for big projects, you should add dozens of possible headers locations to source sets, it’s easy to miss something.
- According to build logs, gradle makes a compiler call to every header that is explicitly added to source set. I.e. with config like this,
main(NativeExecutableSpec) {
sources.cpp {
source {
srcDir "src"
}
source {
srcDir "build/generated/jni"
include "*.h"
}
}
gradle calls
g++ @opts.txt header.h
for every header in there. Needless to say, this makes a huge build time overhead.
3. It actually… doesn’t recompile all the .cpp files that these headers are included to!
Actually, I think I’m doing something wrong here. What is the best way to get my sources recompiled on auto-generated files change, without performing a clean task?
My environment: gradle 2.9, linux host. Main goal is really to get android-experimental ndk plugin make all this stuff, but since it’s based on cpp plugin, just decided to start over here.
Best regards,
Igor