Refactor gradle core build configuration.
This commit is contained in:
parent
47ecf30b2d
commit
fabb9a032d
@ -27,57 +27,55 @@ library {
|
|||||||
linkage.set( [Linkage.SHARED] )
|
linkage.set( [Linkage.SHARED] )
|
||||||
source.from files( 'src' )
|
source.from files( 'src' )
|
||||||
|
|
||||||
// JDK for JNI support.
|
// JNI support requires JDK.
|
||||||
privateHeaders.from files( new File( Jvm.current().javaHome, 'include' ) ) { first().eachDir { from it } }
|
privateHeaders.from files( new File( Jvm.current().javaHome, 'include' ) ) { first().eachDir { from it } }
|
||||||
|
|
||||||
// Cross-compile for these target platforms.
|
// Cross-compile for these native host platforms.
|
||||||
// TODO: Cross-compiling, blocked by: https://github.com/gradle/gradle-native/issues/1031
|
// TODO: blocked by: https://github.com/gradle/gradle-native/issues/1031
|
||||||
targetMachines.set( [
|
targetMachines.set( [
|
||||||
machines.linux.x86, machines.linux.x86_64,
|
machines.linux.x86, machines.linux.x86_64,
|
||||||
machines.windows.x86, machines.windows.x86_64,
|
machines.windows.x86, machines.windows.x86_64,
|
||||||
machines.macOS.x86_64
|
machines.macOS.x86_64
|
||||||
] )
|
] )
|
||||||
|
|
||||||
tasks.withType(CppCompile).configureEach {
|
|
||||||
// Define a preprocessor macro for every binary
|
|
||||||
macros.put("MPW_SODIUM", "1")
|
|
||||||
macros.put("MPW_LOG", "mpw_log_app")
|
|
||||||
|
|
||||||
// Reconfigure the toolchain from C++ to C.
|
|
||||||
compilerArgs.addAll toolChain.map { toolChain ->
|
|
||||||
if (toolChain in GccCompatibleToolChain) {
|
|
||||||
return ['-x', 'c', '-O3', '-Werror']
|
|
||||||
} else if (toolChain in VisualCpp) {
|
|
||||||
return ['/TC', '/MT', '/Ox', '/DSODIUM_STATIC', '/DSODIUM_EXPORT=']
|
|
||||||
}
|
|
||||||
return []
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
binaries.configureEach( CppBinary ) {
|
binaries.configureEach( CppBinary ) {
|
||||||
dependencies {
|
def compile = compileTask.get(), link = linkTask.get()
|
||||||
def arch = targetMachine.getArchitecture().getName().replace('-', '_')
|
def platform = targetMachine.getOperatingSystemFamily().getName()
|
||||||
def system = targetMachine.getOperatingSystemFamily().getName()
|
def arch = targetMachine.getArchitecture().getName().replace('-', '_')
|
||||||
|
|
||||||
|
compile.macros.put("MPW_SODIUM", "1")
|
||||||
|
compile.macros.put("MPW_LOG", "mpw_log_app")
|
||||||
|
|
||||||
|
dependencies {
|
||||||
// libsodium
|
// libsodium
|
||||||
archive.dependsOn project.tasks.maybeCreate( "build_libsodium-${system}", Exec ).configure {
|
compile.dependsOn tasks.maybeCreate( "build_libsodium-${platform}", Exec ).configure {
|
||||||
commandLine 'bash', "$rootDir/lib/bin/build_libsodium-${system}"
|
commandLine 'bash', "$rootDir/lib/bin/build_libsodium-${platform}"
|
||||||
privateHeaders.from "$rootDir/lib/libsodium/build-${system}~/out/include"
|
privateHeaders.from "$rootDir/lib/libsodium/build-${platform}~/out/include"
|
||||||
implementation fileTree( "$rootDir/lib/libsodium/build-${system}~/out/lib/${arch}" )
|
implementation fileTree( "$rootDir/lib/libsodium/build-${platform}~/out/lib/${arch}" )
|
||||||
}
|
}
|
||||||
clean.dependsOn project.tasks.maybeCreate( "clean_libsodium-${system}", Exec ).configure {
|
clean.dependsOn tasks.maybeCreate( "clean_libsodium-${platform}", Exec ).configure {
|
||||||
commandLine 'bash', "$rootDir/lib/bin/build_libsodium-${system}", 'clean'
|
commandLine 'bash', "$rootDir/lib/bin/build_libsodium-${platform}", 'clean'
|
||||||
}
|
}
|
||||||
|
|
||||||
// libjson-c
|
// libjson-c
|
||||||
archive.dependsOn project.tasks.maybeCreate( "build_libjson-c-${system}", Exec ).configure {
|
compile.dependsOn tasks.maybeCreate( "build_libjson-c-${platform}", Exec ).configure {
|
||||||
commandLine 'bash', "$rootDir/lib/bin/build_libjson-c-${system}"
|
commandLine 'bash', "$rootDir/lib/bin/build_libjson-c-${platform}"
|
||||||
privateHeaders.from "$rootDir/lib/libjson-c/build-${system}~/out/include"
|
privateHeaders.from "$rootDir/lib/libjson-c/build-${platform}~/out/include"
|
||||||
implementation fileTree( "$rootDir/lib/libjson-c/build-${system}~/out/lib/${arch}" )
|
implementation fileTree( "$rootDir/lib/libjson-c/build-${platform}~/out/lib/${arch}" )
|
||||||
}
|
}
|
||||||
clean.dependsOn project.tasks.maybeCreate( "clean_libjson-c-${system}", Exec ).configure {
|
clean.dependsOn tasks.maybeCreate( "clean_libjson-c-${platform}", Exec ).configure {
|
||||||
commandLine 'bash', "$rootDir/lib/bin/build_libjson-c-${system}", 'clean'
|
commandLine 'bash', "$rootDir/lib/bin/build_libjson-c-${platform}", 'clean'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reconfigure the toolchain from C++ to C.
|
||||||
|
compile.source.from fileTree( "src" )
|
||||||
|
if (toolChain in GccCompatibleToolChain) {
|
||||||
|
compile.compilerArgs = ['-x', 'c', '-std=c11', '-O3', '-Werror', '-Wall']
|
||||||
|
link.linkerArgs = ['-lc', '-nodefaultlibs', '-flto']
|
||||||
|
} else if (toolChain in VisualCpp) {
|
||||||
|
// TODO: Should this be shared instead of static?
|
||||||
|
compile.compilerArgs = ['/TC', '/MT', '/Ox', '/DSODIUM_STATIC', '/DSODIUM_EXPORT=']
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user