2018-05-25 17:08:05 +00:00
|
|
|
import org.gradle.internal.jvm.Jvm
|
|
|
|
|
|
|
|
|
|
|
|
plugins {
|
2018-05-26 05:22:41 +00:00
|
|
|
id 'base'
|
2019-09-23 18:13:03 +00:00
|
|
|
id 'cpp-library'
|
2018-05-25 17:08:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
description = 'Master Password Algorithm Implementation'
|
|
|
|
|
2018-05-28 03:43:35 +00:00
|
|
|
artifacts {
|
2018-06-30 16:35:40 +00:00
|
|
|
'default' task( type: Zip, 'archive' ) {
|
|
|
|
// TODO: exclude lib files that are produced by the build.
|
|
|
|
from 'lib'
|
|
|
|
|
2018-05-28 03:43:35 +00:00
|
|
|
components.withType( ComponentWithRuntimeFile ) {
|
2018-07-18 19:46:06 +00:00
|
|
|
if (optimized)
|
2018-06-30 16:35:40 +00:00
|
|
|
from runtimeFile, {
|
2019-09-26 02:57:26 +00:00
|
|
|
into targetMachine.getOperatingSystemFamily().getName() + '/' + targetMachine.getArchitecture().getName().replace('-', '_')
|
2018-06-30 16:35:40 +00:00
|
|
|
}
|
2018-05-26 05:22:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-25 17:08:05 +00:00
|
|
|
library {
|
2018-06-30 16:35:40 +00:00
|
|
|
baseName.set( 'mpw' )
|
2018-06-30 15:56:33 +00:00
|
|
|
linkage.set( [Linkage.SHARED] )
|
2019-09-25 19:27:04 +00:00
|
|
|
source.from files( 'src' )
|
2018-05-25 17:08:05 +00:00
|
|
|
|
2019-09-28 02:33:38 +00:00
|
|
|
// JNI support requires JDK.
|
2019-09-25 19:27:04 +00:00
|
|
|
privateHeaders.from files( new File( Jvm.current().javaHome, 'include' ) ) { first().eachDir { from it } }
|
2018-05-26 05:22:41 +00:00
|
|
|
|
2019-09-28 02:33:38 +00:00
|
|
|
// Cross-compile for these native host platforms.
|
|
|
|
// TODO: blocked by: https://github.com/gradle/gradle-native/issues/1031
|
2019-09-23 18:13:03 +00:00
|
|
|
targetMachines.set( [
|
2019-09-25 19:27:04 +00:00
|
|
|
machines.linux.x86, machines.linux.x86_64,
|
2019-09-23 18:13:03 +00:00
|
|
|
machines.windows.x86, machines.windows.x86_64,
|
|
|
|
machines.macOS.x86_64
|
|
|
|
] )
|
2018-06-27 06:54:31 +00:00
|
|
|
|
2019-09-28 02:33:38 +00:00
|
|
|
binaries.configureEach( CppBinary ) {
|
|
|
|
def compile = compileTask.get(), link = linkTask.get()
|
|
|
|
def platform = targetMachine.getOperatingSystemFamily().getName()
|
|
|
|
def arch = targetMachine.getArchitecture().getName().replace('-', '_')
|
2018-05-25 17:08:05 +00:00
|
|
|
|
2019-09-28 02:33:38 +00:00
|
|
|
compile.macros.put("MPW_SODIUM", "1")
|
2019-09-25 19:27:04 +00:00
|
|
|
|
2019-09-26 02:57:26 +00:00
|
|
|
dependencies {
|
|
|
|
// libsodium
|
2019-09-28 02:33:38 +00:00
|
|
|
compile.dependsOn tasks.maybeCreate( "build_libsodium-${platform}", Exec ).configure {
|
|
|
|
commandLine 'bash', "$rootDir/lib/bin/build_libsodium-${platform}"
|
|
|
|
privateHeaders.from "$rootDir/lib/libsodium/build-${platform}~/out/include"
|
|
|
|
implementation fileTree( "$rootDir/lib/libsodium/build-${platform}~/out/lib/${arch}" )
|
2019-09-26 02:57:26 +00:00
|
|
|
}
|
2019-09-28 02:33:38 +00:00
|
|
|
clean.dependsOn tasks.maybeCreate( "clean_libsodium-${platform}", Exec ).configure {
|
|
|
|
commandLine 'bash', "$rootDir/lib/bin/build_libsodium-${platform}", 'clean'
|
2019-09-26 02:57:26 +00:00
|
|
|
}
|
2018-07-18 19:46:06 +00:00
|
|
|
|
2019-09-26 02:57:26 +00:00
|
|
|
// libjson-c
|
2019-09-28 02:33:38 +00:00
|
|
|
compile.dependsOn tasks.maybeCreate( "build_libjson-c-${platform}", Exec ).configure {
|
|
|
|
commandLine 'bash', "$rootDir/lib/bin/build_libjson-c-${platform}"
|
|
|
|
privateHeaders.from "$rootDir/lib/libjson-c/build-${platform}~/out/include"
|
|
|
|
implementation fileTree( "$rootDir/lib/libjson-c/build-${platform}~/out/lib/${arch}" )
|
2018-07-02 01:20:56 +00:00
|
|
|
}
|
2019-09-28 02:33:38 +00:00
|
|
|
clean.dependsOn tasks.maybeCreate( "clean_libjson-c-${platform}", Exec ).configure {
|
|
|
|
commandLine 'bash', "$rootDir/lib/bin/build_libjson-c-${platform}", 'clean'
|
2019-09-26 16:44:41 +00:00
|
|
|
}
|
2018-06-30 15:56:33 +00:00
|
|
|
}
|
2019-09-28 02:33:38 +00:00
|
|
|
|
|
|
|
// 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=']
|
|
|
|
}
|
2018-05-26 05:22:41 +00:00
|
|
|
}
|
|
|
|
}
|