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 {
|
|
|
|
'default' task( type: Zip, "archive" ) {
|
|
|
|
components.withType( ComponentWithRuntimeFile ) {
|
|
|
|
if (isOptimized()) {
|
|
|
|
from getRuntimeFile()
|
|
|
|
into standardOperatingSystem( linkTask.get().targetPlatform.get() ) + '/' +
|
|
|
|
standardArchitecture( linkTask.get().targetPlatform.get() )
|
|
|
|
}
|
2018-05-26 05:22:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-25 17:08:05 +00:00
|
|
|
library {
|
2018-06-19 05:28:27 +00:00
|
|
|
baseName.set( "mpw" )
|
2018-06-24 20:20:42 +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 {
|
|
|
|
cppCompiler.withArguments { addAll( ["/TC", "/DMPW_SODIUM=1"] ) }
|
|
|
|
}
|
|
|
|
}
|
2018-05-26 05:22:41 +00:00
|
|
|
withType( GccCompatibleToolChain ) {
|
|
|
|
eachPlatform {
|
2018-06-03 21:58:24 +00:00
|
|
|
cppCompiler.withArguments { addAll( ["-x", "c", "-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
|
|
|
}
|
|
|
|
components.withType( CppComponent ) {
|
|
|
|
cppSource.from fileTree( dir: "src", include: "**/*.c" )
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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-05-26 05:22:41 +00:00
|
|
|
operatingSystems.set( [objects.named( OperatingSystemFamily, OperatingSystemFamily.WINDOWS ),
|
|
|
|
objects.named( OperatingSystemFamily, OperatingSystemFamily.LINUX ),
|
|
|
|
objects.named( OperatingSystemFamily, OperatingSystemFamily.MAC_OS )] )
|
2018-05-25 17:08:05 +00:00
|
|
|
|
2018-05-26 05:22:41 +00:00
|
|
|
binaries.configureEach {
|
|
|
|
// Resolve a standard name for the platform.
|
|
|
|
def platform = standardOperatingSystem( targetPlatform )
|
2018-05-25 17:08:05 +00:00
|
|
|
|
2018-06-25 06:02:51 +00:00
|
|
|
if (project.tasks.findByName('buildLibSodium') == null)
|
|
|
|
archive.dependsOn task( type: Exec, 'buildLibSodium', {
|
2018-06-25 14:34:56 +00:00
|
|
|
commandLine 'bash', "$rootDir/../lib/bin/build_libsodium-${platform}"
|
2018-06-25 06:02:51 +00:00
|
|
|
} )
|
|
|
|
// if (project.tasks.findByName('buildLibJson-c') == null)
|
|
|
|
// archive.dependsOn task( type: Exec, 'buildLibJson-c', {
|
2018-06-25 14:34:56 +00:00
|
|
|
// commandLine 'bash', "$rootDir/../lib/bin/build_libjson-c-${platform}"
|
2018-06-25 06:02:51 +00:00
|
|
|
// } )
|
|
|
|
|
2018-05-25 17:08:05 +00:00
|
|
|
project.dependencies {
|
|
|
|
// Depend on JDK for JNI support.
|
|
|
|
add( includePathConfiguration.name,
|
|
|
|
files( new File( Jvm.current().javaHome, "include" ) ) { first().eachDir { from it } } )
|
|
|
|
|
2018-06-25 06:02:51 +00:00
|
|
|
// Depend on libsodium from `lib`.
|
2018-05-25 17:08:05 +00:00
|
|
|
add( includePathConfiguration.name,
|
2018-06-24 20:20:42 +00:00
|
|
|
files( "../../../lib/libsodium/src/libsodium/include" ) )
|
2018-05-25 17:08:05 +00:00
|
|
|
add( linkLibraries.name,
|
2018-06-06 00:19:10 +00:00
|
|
|
fileTree( "../../../lib/libsodium/build-${platform}~/out/lib" ) )
|
2018-05-25 17:08:05 +00:00
|
|
|
}
|
2018-05-26 05:22:41 +00:00
|
|
|
}
|
|
|
|
}
|
2018-05-25 17:08:05 +00:00
|
|
|
|
2018-06-25 06:02:51 +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-25 16:25:38 +00:00
|
|
|
else if (os.isMacOsX())
|
2018-05-26 05:22:41 +00:00
|
|
|
return OperatingSystemFamily.MAC_OS
|
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())
|
|
|
|
return "arm"
|
|
|
|
else if (arch.name.toLowerCase( Locale.ROOT ).startsWith( "arm" ))
|
|
|
|
return "arm64"
|
|
|
|
else if (arch.isAmd64())
|
|
|
|
return "x86_64"
|
|
|
|
else if (arch.isI386())
|
|
|
|
return "x86"
|
|
|
|
|
|
|
|
// Other systems will need to be compatible with the x86 architecture.
|
|
|
|
return "x86"
|
2018-05-25 17:08:05 +00:00
|
|
|
}
|