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-25 19:27:04 +00:00
|
|
|
// JDK for JNI support.
|
|
|
|
privateHeaders.from files( new File( Jvm.current().javaHome, 'include' ) ) { first().eachDir { from it } }
|
2018-05-26 05:22:41 +00:00
|
|
|
|
2019-09-25 19:27:04 +00:00
|
|
|
// Cross-compile for these target platforms.
|
|
|
|
// TODO: Cross-compiling, 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-25 19:27:04 +00:00
|
|
|
tasks.withType(CppCompile).configureEach {
|
|
|
|
// Define a preprocessor macro for every binary
|
|
|
|
macros.put("MPW_SODIUM", "1")
|
|
|
|
macros.put("MPW_LOG", "mpw_log_app")
|
2018-05-25 17:08:05 +00:00
|
|
|
|
2019-09-25 19:27:04 +00:00
|
|
|
// 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 []
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-26 02:57:26 +00:00
|
|
|
binaries.configureEach( CppBinary ) {
|
|
|
|
dependencies {
|
|
|
|
def arch = targetMachine.getArchitecture().getName().replace('-', '_')
|
|
|
|
def system = targetMachine.getOperatingSystemFamily().getName()
|
2018-06-30 15:56:33 +00:00
|
|
|
|
2019-09-26 02:57:26 +00:00
|
|
|
// 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'
|
|
|
|
}
|
2018-07-18 19:46:06 +00:00
|
|
|
|
2019-09-26 02:57:26 +00:00
|
|
|
// 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"
|
|
|
|
add( linkLibraries.name, fileTree( "$rootDir/lib/libjson-c/build-${system}~/out/lib" ) )
|
2018-07-02 01:20:56 +00:00
|
|
|
}
|
2019-09-26 02:57:26 +00:00
|
|
|
clean.dependsOn project.tasks.maybeCreate( "clean_libjson-c-${system}", Exec ).configure {
|
|
|
|
commandLine 'bash', "$rootDir/lib/bin/build_libjson-c-${system}", 'clean'
|
|
|
|
}*/
|
2018-06-30 15:56:33 +00:00
|
|
|
}
|
2018-05-26 05:22:41 +00:00
|
|
|
}
|
|
|
|
}
|