2
0
MasterPassword/platform-independent/c/core/build.gradle

117 lines
4.2 KiB
Groovy
Raw Normal View History

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 ) {
2018-07-18 19:46:06 +00:00
if (optimized)
from runtimeFile, {
into standardOperatingSystem( targetPlatform ) + '/' + standardArchitecture( targetPlatform )
}
}
}
}
library {
baseName.set( 'mpw' )
2018-06-30 15:56:33 +00:00
linkage.set( [Linkage.SHARED] )
// Reconfigure the toolchain from C++ to C.
toolChains {
2018-06-24 20:20:42 +00:00
withType( VisualCpp ) {
eachPlatform {
cppCompiler.withArguments { addAll( ['/TC', '/MT', '/Ox', '/DMPW_SODIUM=1', '/DSODIUM_STATIC', '/DSODIUM_EXPORT='] ) }
2018-06-24 20:20:42 +00:00
}
}
withType( GccCompatibleToolChain ) {
eachPlatform {
2018-08-01 18:20:47 +00:00
cppCompiler.withArguments { addAll( ['-x', 'c', '-static', '-O3', '-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
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-30 15:56:33 +00:00
components.withType( CppComponent ) {
cppSource.from fileTree( 'src' )
2018-06-30 15:56:33 +00:00
privateHeaders {
// JDK for JNI support.
from files( new File( Jvm.current().javaHome, 'include' ) ) { first().eachDir { from it } }
}
2018-07-18 19:46:06 +00:00
binaries.whenElementFinalized {
2018-06-30 15:56:33 +00:00
project.dependencies {
2018-07-18 19:46:06 +00:00
def system = standardOperatingSystem( targetPlatform )
2018-06-30 15:56:33 +00:00
2018-07-18 19:46:06 +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"
add( linkLibraries.name, fileTree( "$rootDir/../lib/libsodium/build-${system}~/out/lib" ) )
}
clean.dependsOn project.tasks.maybeCreate( "clean_libsodium-${system}", Exec ).configure {
commandLine 'bash', "$rootDir/../lib/bin/build_libsodium-${system}", 'clean'
}
// 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" ) )
}
clean.dependsOn project.tasks.maybeCreate( "clean_libjson-c-${system}", Exec ).configure {
commandLine 'bash', "$rootDir/../lib/bin/build_libjson-c-${system}", 'clean'
}
2018-07-02 01:20:56 +00:00
}
2018-06-30 15:56:33 +00:00
}
}
}
static String standardOperatingSystem(NativePlatform platform) {
OperatingSystem os = platform.getOperatingSystem()
if (os.isWindows())
return OperatingSystemFamily.WINDOWS
2018-06-30 15:56:33 +00:00
else if (os.isMacOsX())
return OperatingSystemFamily.MAC_OS
2018-06-30 15:56:33 +00:00
else if (os.isLinux())
return OperatingSystemFamily.LINUX
// Other systems will need to use a Linux compatibility layer.
return OperatingSystemFamily.LINUX
}
static String standardArchitecture(NativePlatform platform) {
Architecture arch = platform.getArchitecture()
if (arch.isArm())
return 'arm'
2018-06-30 15:56:33 +00:00
else if (arch.name.toLowerCase( Locale.ROOT ).startsWith( 'arm' ))
return 'arm64'
2018-06-30 15:56:33 +00:00
else if (arch.isAmd64())
return 'x86_64'
2018-06-30 15:56:33 +00:00
else if (arch.isI386())
return 'x86'
// Other systems will need to be compatible with the x86 architecture.
return 'x86'
}