2
0
MasterPassword/core/c/build.gradle

81 lines
2.7 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" ) {
components.withType( ComponentWithRuntimeFile ) {
if (isOptimized()) {
from getRuntimeFile()
into standardOperatingSystem( linkTask.get().targetPlatform.get() ) + '/' +
standardArchitecture( linkTask.get().targetPlatform.get() )
}
}
}
}
library {
linkage.set( [Linkage.STATIC, Linkage.SHARED] )
// Reconfigure the toolchain from C++ to C.
toolChains {
withType( GccCompatibleToolChain ) {
//TODO: Cross-compiling, blocked by: https://github.com/gradle/gradle-native/issues/169
//setTargets( "arm", "arm64", "x86-64", "x86" )
eachPlatform {
cppCompiler.withArguments { addAll( ["-x", "c", "-std=c11", "-DMPW_SODIUM=1"] ) }
}
}
}
components.withType( CppComponent ) {
cppSource.from fileTree( dir: "src", include: "**/*.c" )
}
// Cross-compile for these host platforms.
operatingSystems.set( [objects.named( OperatingSystemFamily, OperatingSystemFamily.WINDOWS ),
objects.named( OperatingSystemFamily, OperatingSystemFamily.LINUX ),
objects.named( OperatingSystemFamily, OperatingSystemFamily.MAC_OS )] )
//
binaries.configureEach {
// Resolve a standard name for the platform.
def platform = standardOperatingSystem( targetPlatform )
project.dependencies {
// Depend on JDK for JNI support.
add( includePathConfiguration.name,
files( new File( Jvm.current().javaHome, "include" ) ) { first().eachDir { from it } } )
// Depend on libsodium from `lib`; run `lib/bin/build_libsodium-${os}` first.
add( includePathConfiguration.name,
files( "../../lib/libsodium/build-${platform}~/out/include" ) )
add( linkLibraries.name,
fileTree( "../../lib/libsodium/build-${platform}~/out/lib" ) )
}
}
}
static String standardOperatingSystem(NativePlatform platform) {
OperatingSystem os = platform.getOperatingSystem()
if (os.isWindows()) {
return OperatingSystemFamily.WINDOWS
} else if (os.isLinux()) {
return OperatingSystemFamily.LINUX
} else if (os.isMacOsX()) {
return OperatingSystemFamily.MAC_OS
}
return os.name.toLowerCase()
}
static String standardArchitecture(NativePlatform platform) {
Architecture arch = platform.getArchitecture()
return arch.name.toLowerCase().replaceAll( "-", "_" )
}