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

81 lines
3.2 KiB
Groovy
Raw Permalink Normal View History

import org.gradle.internal.jvm.Jvm
plugins {
id 'base'
2019-09-23 18:13:03 +00:00
id 'cpp-library'
}
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 targetMachine.getOperatingSystemFamily().getName() + '/' + targetMachine.getArchitecture().getName().replace('-', '_')
}
}
}
}
library {
baseName.set( 'mpw' )
2018-06-30 15:56:33 +00:00
linkage.set( [Linkage.SHARED] )
2019-09-25 19:27:04 +00:00
source.from files( 'src' )
// JNI support requires JDK.
2019-09-25 19:27:04 +00:00
privateHeaders.from files( new File( Jvm.current().javaHome, 'include' ) ) { first().eachDir { from it } }
// Cross-compile for these native host platforms.
// TODO: blocked by: https://github.com/gradle/gradle-native/issues/1031
2019-09-23 18:13:03 +00:00
targetMachines.set( [
2019-09-25 19:27:04 +00:00
machines.linux.x86, machines.linux.x86_64,
2019-09-23 18:13:03 +00:00
machines.windows.x86, machines.windows.x86_64,
machines.macOS.x86_64
] )
binaries.configureEach( CppBinary ) {
def compile = compileTask.get(), link = linkTask.get()
def platform = targetMachine.getOperatingSystemFamily().getName()
def arch = targetMachine.getArchitecture().getName().replace('-', '_')
compile.macros.put("MPW_SODIUM", "1")
2019-09-25 19:27:04 +00:00
dependencies {
// libsodium
compile.dependsOn tasks.maybeCreate( "build_libsodium-${platform}", Exec ).configure {
commandLine 'bash', "$rootDir/lib/bin/build_libsodium-${platform}"
privateHeaders.from "$rootDir/lib/libsodium/build-${platform}~/out/include"
implementation fileTree( "$rootDir/lib/libsodium/build-${platform}~/out/lib/${arch}" )
}
clean.dependsOn tasks.maybeCreate( "clean_libsodium-${platform}", Exec ).configure {
commandLine 'bash', "$rootDir/lib/bin/build_libsodium-${platform}", 'clean'
}
2018-07-18 19:46:06 +00:00
// libjson-c
compile.dependsOn tasks.maybeCreate( "build_libjson-c-${platform}", Exec ).configure {
commandLine 'bash', "$rootDir/lib/bin/build_libjson-c-${platform}"
privateHeaders.from "$rootDir/lib/libjson-c/build-${platform}~/out/include"
implementation fileTree( "$rootDir/lib/libjson-c/build-${platform}~/out/lib/${arch}" )
2018-07-02 01:20:56 +00:00
}
clean.dependsOn tasks.maybeCreate( "clean_libjson-c-${platform}", Exec ).configure {
commandLine 'bash', "$rootDir/lib/bin/build_libjson-c-${platform}", 'clean'
}
2018-06-30 15:56:33 +00:00
}
// Reconfigure the toolchain from C++ to C.
compile.source.from fileTree( "src" )
if (toolChain in GccCompatibleToolChain) {
compile.compilerArgs = ['-x', 'c', '-std=c11', '-O3', '-Werror', '-Wall']
link.linkerArgs = ['-lc', '-nodefaultlibs', '-flto']
} else if (toolChain in VisualCpp) {
// TODO: Should this be shared instead of static?
2021-02-11 19:11:09 +00:00
compile.compilerArgs = ['/TC', '/MT', '/Ox', '/DSODIUM_STATIC', '/DSODIUM_EXPORT=', '/std:c11']
}
}
}