I’m working with a C code base that supports multiple platforms by combining generic and platform specific source files. Consider the following directory structure,
thread thread/src/thread.c thread/src/mac_x86/thread_plt.c thread/src/mac_x86_64/thread_plt.c thread/src/win_x86/thread_plt.c
For the library “thread” I wish to: - always include thread.c - only include mac_x86/thread_plt.c for the Mac x86 binary variant - only include mac_x86_64/thread_plt.c for the Mac x86-64 binary variant - only include win_x86/thread_plt.c for the Windows x86 binary variant
I’ve tried extending the source set for a specific binary variant (using the binary’s target os and platform) from within the “binaries.all” closure, but the source gets added for all binary variants.
I’m working around that by limiting the platforms and architectures defined in the model to one, based on the host (or provided target if cross-compiling); but when you only define a single platform/architecture Gradle smartly writes the objects/binaries to a non-platform-specific directory, so if you then decide to cross-compile for another architecture new objects are not created because they already exist and linking fails due to object format errors.
I’ve gotten around that by defining a “dummy” architecture that never get’s built. While this works the dummy architecture clutters the model, clutters the tasks list, will confuse anyone looking at this build script and such hacks will probably not work with future versions of Gradle (nor should it).
So, is there a way to add a specific source file to a specific binary variant only? Or, is there a way to get Gradle to write the objects/binaries to a platform specific location even if only one platform/architecture is defined in the model?
Thanks!