110 lines
3.6 KiB
Groovy
110 lines
3.6 KiB
Groovy
import org.gradle.internal.jvm.Jvm
|
|
|
|
|
|
plugins {
|
|
id 'cpp-library'
|
|
id 'base'
|
|
}
|
|
|
|
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 (isOptimized()) {
|
|
from runtimeFile, {
|
|
into standardOperatingSystem( targetPlatform ) + '/' + standardArchitecture( targetPlatform )
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
library {
|
|
baseName.set( 'mpw' )
|
|
linkage.set( [Linkage.SHARED] )
|
|
|
|
// Reconfigure the toolchain from C++ to C.
|
|
toolChains {
|
|
withType( VisualCpp ) {
|
|
eachPlatform {
|
|
cppCompiler.withArguments { addAll( ['/TC', '/MT', '/Ox', '/DMPW_SODIUM=1', '/DSODIUM_STATIC', '/DSODIUM_EXPORT='] ) }
|
|
}
|
|
}
|
|
withType( GccCompatibleToolChain ) {
|
|
eachPlatform {
|
|
cppCompiler.withArguments { addAll( ['-x', 'c', '-O3', '-std=c11', '-Werror', '-DMPW_SODIUM=1'] ) }
|
|
}
|
|
}
|
|
}
|
|
|
|
// Cross-compile for these host platforms.
|
|
// TODO: Cross-compiling, blocked by: https://github.com/gradle/gradle-native/issues/169 - CppLibraryPlugin.java:163
|
|
operatingSystems.set( [objects.named( OperatingSystemFamily, OperatingSystemFamily.LINUX ),
|
|
objects.named( OperatingSystemFamily, OperatingSystemFamily.MAC_OS ),
|
|
objects.named( OperatingSystemFamily, OperatingSystemFamily.WINDOWS )] )
|
|
|
|
components.withType( CppComponent ) {
|
|
cppSource.from fileTree( 'src' )
|
|
|
|
privateHeaders {
|
|
// JDK for JNI support.
|
|
from files( new File( Jvm.current().javaHome, 'include' ) ) { first().eachDir { from it } }
|
|
}
|
|
|
|
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 {
|
|
commandLine 'bash', "$rootDir/../lib/bin/build_libsodium-${system}"
|
|
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"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
static String standardOperatingSystem(NativePlatform platform) {
|
|
OperatingSystem os = platform.getOperatingSystem()
|
|
if (os.isWindows())
|
|
return OperatingSystemFamily.WINDOWS
|
|
|
|
else if (os.isMacOsX())
|
|
return OperatingSystemFamily.MAC_OS
|
|
|
|
else if (os.isLinux())
|
|
return OperatingSystemFamily.LINUX
|
|
|
|
// Other systems will need to use a Linux compatibility layer for now.
|
|
return OperatingSystemFamily.LINUX
|
|
}
|
|
|
|
static String standardArchitecture(NativePlatform platform) {
|
|
Architecture arch = platform.getArchitecture()
|
|
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'
|
|
}
|