2018-05-25 17:08:05 +00:00
|
|
|
import org.gradle.internal.jvm.Jvm
|
|
|
|
|
|
|
|
|
|
|
|
plugins {
|
|
|
|
id 'cpp-library'
|
2018-05-26 05:22:41 +00:00
|
|
|
id 'base'
|
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 ) {
|
|
|
|
if (isOptimized()) {
|
2018-06-30 16:35:40 +00:00
|
|
|
from runtimeFile, {
|
|
|
|
into standardOperatingSystem( targetPlatform ) + '/' + standardArchitecture( targetPlatform )
|
|
|
|
}
|
2018-05-28 03:43:35 +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] )
|
2018-05-25 17:08:05 +00:00
|
|
|
|
2018-05-26 05:22:41 +00:00
|
|
|
// Reconfigure the toolchain from C++ to C.
|
|
|
|
toolChains {
|
2018-06-24 20:20:42 +00:00
|
|
|
withType( VisualCpp ) {
|
|
|
|
eachPlatform {
|
2018-06-30 16:35:40 +00:00
|
|
|
cppCompiler.withArguments { addAll( ['/TC', '/MT', '/Ox', '/DMPW_SODIUM=1', '/DSODIUM_STATIC', '/DSODIUM_EXPORT='] ) }
|
2018-06-24 20:20:42 +00:00
|
|
|
}
|
|
|
|
}
|
2018-05-26 05:22:41 +00:00
|
|
|
withType( GccCompatibleToolChain ) {
|
|
|
|
eachPlatform {
|
2018-06-30 16:35:40 +00:00
|
|
|
cppCompiler.withArguments { addAll( ['-x', 'c', '-O3', '-std=c11', '-Werror', '-DMPW_SODIUM=1'] ) }
|
2018-05-26 05:22:41 +00:00
|
|
|
}
|
2018-05-25 17:08:05 +00:00
|
|
|
}
|
2018-05-26 05:22:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Cross-compile for these host platforms.
|
2018-06-10 23:11:22 +00:00
|
|
|
// TODO: Cross-compiling, blocked by: https://github.com/gradle/gradle-native/issues/169 - CppLibraryPlugin.java:163
|
2018-06-30 15:56:33 +00:00
|
|
|
operatingSystems.set( [objects.named( OperatingSystemFamily, OperatingSystemFamily.LINUX ),
|
|
|
|
objects.named( OperatingSystemFamily, OperatingSystemFamily.MAC_OS ),
|
|
|
|
objects.named( OperatingSystemFamily, OperatingSystemFamily.WINDOWS )] )
|
2018-06-27 06:54:31 +00:00
|
|
|
|
2018-06-30 15:56:33 +00:00
|
|
|
components.withType( CppComponent ) {
|
2018-06-30 16:35:40 +00:00
|
|
|
cppSource.from fileTree( 'src' )
|
2018-06-27 06:54:31 +00:00
|
|
|
|
2018-06-30 15:56:33 +00:00
|
|
|
privateHeaders {
|
|
|
|
// JDK for JNI support.
|
2018-06-30 16:35:40 +00:00
|
|
|
from files( new File( Jvm.current().javaHome, 'include' ) ) { first().eachDir { from it } }
|
2018-06-27 06:54:31 +00:00
|
|
|
}
|
2018-05-25 17:08:05 +00:00
|
|
|
|
2018-06-30 15:56:33 +00:00
|
|
|
binaries.configureEach {
|
|
|
|
def system = standardOperatingSystem( targetPlatform )
|
|
|
|
|
|
|
|
project.dependencies {
|
|
|
|
add( linkLibraries.name,
|
|
|
|
fileTree( "../../../lib/libsodium/build-${system}~/out/lib" ) )
|
|
|
|
}
|
|
|
|
|
|
|
|
archive.dependsOn project.tasks.maybeCreate( "build_libsodium-${system}", Exec.class ).configure {
|
2018-06-27 06:54:31 +00:00
|
|
|
commandLine 'bash', "$rootDir/../lib/bin/build_libsodium-${system}"
|
2018-06-30 15:56:33 +00:00
|
|
|
privateHeaders.from "$rootDir/../lib/libsodium/src/libsodium/include"
|
|
|
|
}
|
|
|
|
archive.dependsOn project.tasks.maybeCreate( "build_libjson-c-${system}", Exec.class ).configure {
|
|
|
|
commandLine 'bash', "$rootDir/../lib/bin/build_libjson-c-${system}"
|
|
|
|
privateHeaders.from "$rootDir/../lib/libjson-c/build-${system}~/out"
|
|
|
|
}
|
|
|
|
}
|
2018-05-26 05:22:41 +00:00
|
|
|
}
|
|
|
|
}
|
2018-05-25 17:08:05 +00:00
|
|
|
|
2018-05-26 05:22:41 +00:00
|
|
|
static String standardOperatingSystem(NativePlatform platform) {
|
|
|
|
OperatingSystem os = platform.getOperatingSystem()
|
2018-06-25 16:25:38 +00:00
|
|
|
if (os.isWindows())
|
2018-05-26 05:22:41 +00:00
|
|
|
return OperatingSystemFamily.WINDOWS
|
2018-06-30 15:56:33 +00:00
|
|
|
|
2018-06-25 16:25:38 +00:00
|
|
|
else if (os.isMacOsX())
|
2018-05-26 05:22:41 +00:00
|
|
|
return OperatingSystemFamily.MAC_OS
|
2018-06-30 15:56:33 +00:00
|
|
|
|
2018-06-25 16:25:38 +00:00
|
|
|
else if (os.isLinux())
|
|
|
|
return OperatingSystemFamily.LINUX
|
2018-05-26 05:22:41 +00:00
|
|
|
|
2018-06-25 16:25:38 +00:00
|
|
|
// Other systems will need to use a Linux compatibility layer for now.
|
|
|
|
return OperatingSystemFamily.LINUX
|
2018-05-26 05:22:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static String standardArchitecture(NativePlatform platform) {
|
|
|
|
Architecture arch = platform.getArchitecture()
|
2018-06-25 16:25:38 +00:00
|
|
|
if (arch.isArm())
|
2018-06-30 16:35:40 +00:00
|
|
|
return 'arm'
|
2018-06-30 15:56:33 +00:00
|
|
|
|
2018-06-30 16:35:40 +00:00
|
|
|
else if (arch.name.toLowerCase( Locale.ROOT ).startsWith( 'arm' ))
|
|
|
|
return 'arm64'
|
2018-06-30 15:56:33 +00:00
|
|
|
|
2018-06-25 16:25:38 +00:00
|
|
|
else if (arch.isAmd64())
|
2018-06-30 16:35:40 +00:00
|
|
|
return 'x86_64'
|
2018-06-30 15:56:33 +00:00
|
|
|
|
2018-06-25 16:25:38 +00:00
|
|
|
else if (arch.isI386())
|
2018-06-30 16:35:40 +00:00
|
|
|
return 'x86'
|
2018-06-25 16:25:38 +00:00
|
|
|
|
|
|
|
// Other systems will need to be compatible with the x86 architecture.
|
2018-06-30 16:35:40 +00:00
|
|
|
return 'x86'
|
2018-05-25 17:08:05 +00:00
|
|
|
}
|