84 lines
3.2 KiB
Groovy
84 lines
3.2 KiB
Groovy
import org.gradle.internal.jvm.Jvm
|
|
|
|
|
|
plugins {
|
|
id 'base'
|
|
id 'cpp-library'
|
|
}
|
|
|
|
description = 'Master Password Algorithm Implementation'
|
|
|
|
artifacts {
|
|
'default' task( type: Zip, 'archive' ) {
|
|
// TODO: exclude lib files that are produced by the build.
|
|
from 'lib'
|
|
|
|
components.withType( ComponentWithRuntimeFile ) {
|
|
if (optimized)
|
|
from runtimeFile, {
|
|
into targetMachine.getOperatingSystemFamily().getName() + '/' + targetMachine.getArchitecture().getName().replace('-', '_')
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
library {
|
|
baseName.set( 'mpw' )
|
|
linkage.set( [Linkage.SHARED] )
|
|
source.from files( 'src' )
|
|
|
|
// JDK for JNI support.
|
|
privateHeaders.from files( new File( Jvm.current().javaHome, 'include' ) ) { first().eachDir { from it } }
|
|
|
|
// Cross-compile for these target platforms.
|
|
// TODO: Cross-compiling, blocked by: https://github.com/gradle/gradle-native/issues/1031
|
|
targetMachines.set( [
|
|
machines.linux.x86, machines.linux.x86_64,
|
|
machines.windows.x86, machines.windows.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 ) {
|
|
dependencies {
|
|
def arch = targetMachine.getArchitecture().getName().replace('-', '_')
|
|
def system = targetMachine.getOperatingSystemFamily().getName()
|
|
|
|
// libsodium
|
|
archive.dependsOn project.tasks.maybeCreate( "build_libsodium-${system}", Exec ).configure {
|
|
commandLine 'bash', "$rootDir/lib/bin/build_libsodium-${system}"
|
|
privateHeaders.from "$rootDir/lib/libsodium/build-${system}~/out/include"
|
|
implementation fileTree( "$rootDir/lib/libsodium/build-${system}~/out/lib/${arch}" )
|
|
}
|
|
clean.dependsOn project.tasks.maybeCreate( "clean_libsodium-${system}", Exec ).configure {
|
|
commandLine 'bash', "$rootDir/lib/bin/build_libsodium-${system}", 'clean'
|
|
}
|
|
|
|
// libjson-c
|
|
archive.dependsOn project.tasks.maybeCreate( "build_libjson-c-${system}", Exec ).configure {
|
|
commandLine 'bash', "$rootDir/lib/bin/build_libjson-c-${system}"
|
|
privateHeaders.from "$rootDir/lib/libjson-c/build-${system}~/out/include"
|
|
implementation fileTree( "$rootDir/lib/libjson-c/build-${system}~/out/lib/${arch}" )
|
|
}
|
|
clean.dependsOn project.tasks.maybeCreate( "clean_libjson-c-${system}", Exec ).configure {
|
|
commandLine 'bash', "$rootDir/lib/bin/build_libjson-c-${system}", 'clean'
|
|
}
|
|
}
|
|
}
|
|
}
|