85 lines
2.9 KiB
Groovy
85 lines
2.9 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" ) {
|
|
components.withType( ComponentWithRuntimeFile ) {
|
|
if (isOptimized()) {
|
|
from getRuntimeFile()
|
|
into standardOperatingSystem( linkTask.get().targetPlatform.get() ) + '/' +
|
|
standardArchitecture( linkTask.get().targetPlatform.get() )
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
library {
|
|
baseName.set( "mpw" )
|
|
linkage.set( [ Linkage.SHARED ] )
|
|
|
|
// Reconfigure the toolchain from C++ to C.
|
|
toolChains {
|
|
withType( VisualCpp ) {
|
|
eachPlatform {
|
|
cppCompiler.withArguments { addAll( ["/TC", "/DMPW_SODIUM=1"] ) }
|
|
}
|
|
}
|
|
withType( GccCompatibleToolChain ) {
|
|
eachPlatform {
|
|
cppCompiler.withArguments { addAll( ["-x", "c", "-std=c11", "-Werror", "-DMPW_SODIUM=1"] ) }
|
|
}
|
|
}
|
|
}
|
|
components.withType( CppComponent ) {
|
|
cppSource.from fileTree( dir: "src", include: "**/*.c" )
|
|
}
|
|
|
|
// 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.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-${platform}` first.
|
|
add( includePathConfiguration.name,
|
|
files( "../../../lib/libsodium/src/libsodium/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( "-", "_" )
|
|
}
|