Hello all,
Just started using gradle - famous tool. I would like to replace some Makefile with. Has anybody an idea how to specify native toolchain to enable cross compilation?
I’m trying version 2.2.1
model {
buildTypes {
debug
release
}
toolChains {
gcc(Gcc) {
}
mingw(Gcc) {
path "~/tools/mxe/usr/bin/"
target("windows32", new MingwAction(new MingwGccPlatformToolChain()))
}
}
platforms {
linux32 {
architecture "i386"
operatingSystem "linux"
}
linux64 {
architecture "x86_64"
operatingSystem "linux"
}
windows32 {
architecture "i386"
operatingSystem "windows"
}
}
}
///....
binaries.all {
// Define a preprocessor macro for every binary
//
cppCompiler.define "NDEBUG"
// Define toolchain-specific compiler and linker options
if (toolChain in gcc) {
cppCompiler.args "-O3", "-fno-strict-aliasing", "-Wno-maybe-uninitialized", "-Wno-reorder", "-funroll-loops", "-fno-trapping-math", "-fno-signaling-nans", "-fno-rounding-math", "-fno-signed-zeros", "-mfpmath=sse", "-msse", "-fopenmp"
linker.args "-s", "-fopenmp"
}
}
///....
import org.gradle.nativeplatform.toolchain.internal.gcc.TargetPlatformConfiguration
import org.gradle.nativeplatform.toolchain.internal.gcc.DefaultGccPlatformToolChain
import org.gradle.nativeplatform.toolchain.internal.tools.DefaultGccCommandLineToolConfiguration
import org.gradle.nativeplatform.platform.internal.NativePlatformInternal
import org.gradle.nativeplatform.toolchain.internal.ToolType
class MingwOnLinuxTool extends DefaultGccCommandLineToolConfiguration {
private static ToolType toolType = ToolType.CPP_COMPILER || ToolType.C_COMPILER;
public MingwOnLinuxTool() {
super(ToolType.CPP_COMPILER,"i686-pc-mingw32.static-g++");
}
}
import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform;
import org.gradle.nativeplatform.platform.internal.DefaultOperatingSystem;
import org.gradle.internal.os.OperatingSystem;
class MingwGccPlatformToolChain extends DefaultGccPlatformToolChain {
private static DefaultNativePlatform platform = new DefaultNativePlatform("windows");
static {
platform.operatingSystem(new DefaultOperatingSystem("windows32", OperatingSystem.WINDOWS));
}
public MingwGccPlatformToolChain() {
super(platform);
add(new DefaultGccCommandLineToolConfiguration(ToolType.CPP_COMPILER,"i686-pc-mingw32.static-g++"));
add(new DefaultGccCommandLineToolConfiguration(ToolType.C_COMPILER,"i686-pc-mingw32.static-gcc"));
add(new DefaultGccCommandLineToolConfiguration(ToolType.ASSEMBLER,"i686-pc-mingw32.static-as"));
add(new DefaultGccCommandLineToolConfiguration(ToolType.WINDOW_RESOURCES_COMPILER,"i686-pc-mingw32.static-windres"));
add(new DefaultGccCommandLineToolConfiguration(ToolType.LINKER,"i686-pc-mingw32.static-ld"));
add(new DefaultGccCommandLineToolConfiguration(ToolType.STATIC_LIB_ARCHIVER,"i686-pc-mingw32.static-ar"));
}
}
import org.gradle.api.Action
import org.gradle.nativeplatform.toolchain.internal.tools.GccCommandLineToolConfigurationInternal;
class MingwAction<MingwOnLinuxTool> implements Action {
private MingwOnLinuxTool tool;
public MingwAction(MingwOnLinuxTool tool) {
this.tool = tool;
}
public void execute(MingwOnLinuxTool tool1) {
tool.compilerProbeArgs("-m64");
Action<List<String>> m64args = new Action<List<String>>() {
public void execute(List<String> args) {
args.add("-m64");
}
};
GccCommandLineToolConfigurationInternal gcc = tool.getCppCompiler();//.withArguments(m64args);
Action<List<String>> act = gcc.getArgAction();
for (Object item: act) {
System.out.println(item.toString());
}
tool.getcCompiler().withArguments(m64args);
//
tool.getObjcCompiler().withArguments(m64args);
//
tool.getObjcppCompiler().withArguments(m64args);
tool.getLinker().withArguments(m64args);
tool.getAssembler().withArguments(new Action<List<String>>() {
public void execute(List<String> args) {
// TODO - this should be 'if toolchain is XCode'
if (operatingSystem.isMacOsX()) {
args.addAll(asList("-arch", "x86_64"));
} else {
args.add("--64");
}
}
});
}
}
What am I missing? Thank you