Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge static libs and bump version 2.2-3 #8

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 109 additions & 5 deletions publish.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ publishing {
}
}

ext.version = "2.2"
ext.libVersion = "${ext.version.replace(".", "")}"

def getTriplet() {
def fileNameFinder = new FileNameFinder()
for (File folder : file("$projectDir/vcpkg_installed").listFiles()) {
Expand Down Expand Up @@ -58,7 +61,7 @@ ext.platformPath = getPlatformPath(triplet)
ext.platformClassifier = ext.platformPath.replaceFirst('/', '')

ext.repo = "thirdparty-ceres"
def pubVersion = "2.2-2"
def pubVersion = "2.2-3"

def outputsFolder = file("$project.buildDir/outputs")

Expand Down Expand Up @@ -114,7 +117,107 @@ task cppHeadersZip(type: Zip) {
includeEmptyDirs = false
}

task mergeStaticLibs(type: Exec) {
def buildDirectory = Paths.get(projectDir.canonicalPath).resolve("vcpkg_installed").resolve(triplet)

if (project.platformPath.startsWith('windows')) {
workingDir buildDirectory.resolve("lib").toString()
executable 'lib'
def inputFiles = ["ceres.lib", "gflags.lib", "GKlib.lib", "glog.lib", "lapack.lib", "libamd.lib", "libbtf.lib", "libcamd.lib", "libccolamd.lib", "libcholmod.lib", "libcolamd.lib", "libcxsparse.lib", "libklu.lib", "libldl.lib", "libspqr.lib", "libumfpack.lib", "metis.lib", "openblas.lib", "suitesparseconfig.lib"]
if (project.platformPath.contains('arm64')) {
print("ARM64 Architecture Detected")
inputFiles = ["ceres.lib", "gflags.lib", "GKlib.lib", "glog.lib", "lapack.lib", "libamd.lib", "libbtf.lib", "libcamd.lib", "libccolamd.lib", "libcholmod.lib", "libcolamd.lib", "libcxsparse.lib", "libklu.lib", "libldl.lib", "libspqr.lib", "libumfpack.lib", "metis.lib", "openblas.lib", "suitesparseconfig.lib", "libf2c.lib"]
}
def setArgs = ["/OUT:ceres${project.libVersion}.lib"]
inputFiles.each {
setArgs << it
}
args = setArgs
} else if (project.platformPath.startsWith('osx')) {
executable 'libtool'
workingDir buildDirectory.resolve("lib").toString()

def outputLibName = "libceres${project.libVersion}.a"

def inputFiles = ["libspqr.a", "libldl.a", "libceres.a", "libccolamd.a", "libklu.a", "libcxsparse.a", "libglog.a", "libsuitesparseconfig.a", "libbtf.a", "libmetis.a", "libumfpack.a", "libcholmod.a", "libcamd.a", "libgflags.a", "libamd.a", "libGKlib.a", "libcolamd.a"]

args '-static', '-o', outputLibName

inputFiles.each {
args "${buildDirectory.resolve("lib")}/$it"
}

inputs.files inputFiles.collect { buildDirectory.resolve("lib").resolve(it) }
outputs.file buildDirectory.resolve("lib/${outputLibName}")
} else {
workingDir buildDirectory.resolve("lib").toString()
executable 'ar'
args = ['-M']
def inputFiles = ["libamd", "libbtf", "libcamd", "libccolamd", "libceres", "libcholmod", "libcxsparse", "libgflags", "libGKlib", "libglog", "libklu", "liblapack", "libldl", "libmetis", "libopenblas", "libspqr", "libsuitesparseconfig", "libumfpack"]

def inputString = "create libceres${project.libVersion}.a\n"
inputFiles.each {
def inFile = 'addlib ' + it + ".a\n"
inputString += inFile
}

inputString += "save\nend\n"
standardInput = new ByteArrayInputStream(inputString.getBytes())
}
}

task mergeDebugStaticLibs(type: Exec) {
def buildDirectory = Paths.get(projectDir.canonicalPath).resolve("vcpkg_installed").resolve(triplet).resolve("debug")

if (project.platformPath.startsWith('windows')) {
workingDir buildDirectory.resolve("lib").toString()
executable 'lib'
def inputFiles = ["ceres-debug.lib", "gflags_debug.lib", "GKlib.lib", "glog.lib", "lapack.lib", "libamdd.lib", "libbtfd.lib", "libcamdd.lib", "libccolamdd.lib", "libcholmodd.lib", "libcolamdd.lib", "libcxsparsed.lib", "libklud.lib", "libldld.lib", "libspqrd.lib", "libumfpackd.lib", "metis.lib", "openblas.lib", "suitesparseconfigd.lib"]
if (project.platformPath.contains('arm64')) {
print("ARM64 Architecture Detected")
inputFiles = ["ceres-debug.lib", "gflags_debug.lib", "GKlib.lib", "glog.lib", "lapack.lib", "libamdd.lib", "libbtfd.lib", "libcamdd.lib", "libccolamdd.lib", "libcholmodd.lib", "libcolamdd.lib", "libcxsparsed.lib", "libf2c.lib", "libklud.lib", "libldld.lib", "libspqrd.lib", "libumfpackd.lib", "metis.lib", "openblas.lib", "suitesparseconfigd.lib"]
}

def setArgs = ["/OUT:ceres-debug${project.libVersion}.lib"]
inputFiles.each {
setArgs << it
}
args = setArgs
} else if (project.platformPath.startsWith('osx')) {
executable 'libtool'
workingDir buildDirectory.resolve("lib").toString()

def outputLibName = "libceres-debug${project.libVersion}.a"

def inputFiles = ["libsuitesparseconfigd.a", "libspqrd.a", "libamdd.a", "libcxsparsed.a", "libldld.a", "libglog.a", "libgflags_debug.a", "libcolamdd.a", "libmetis.a", "libccolamdd.a", "libcamdd.a", "libumfpackd.a", "libklud.a", "libcholmodd.a", "libceres-debug.a", "libbtfd.a", "libGKlib.a"]

args '-static', '-o', outputLibName

inputFiles.each {
args "${buildDirectory.resolve("lib")}/$it"
}

inputs.files inputFiles.collect { buildDirectory.resolve("lib").resolve(it) }
outputs.file buildDirectory.resolve("lib/${outputLibName}")
} else {
workingDir buildDirectory.resolve("lib").toString()
executable 'ar'
args = ['-M']
def inputFiles = ["libamdd", "libbtfd", "libcamdd", "libccolamdd", "libceres-debug", "libcholmodd", "libcolamdd", "libcxsparsed", "libgflags_debug", "libGKlib", "libglog", "libklud", "liblapack", "libldld", "libmetis", "libopenblas", "libspqrd", "libsuitesparseconfigd", "libumfpackd"]

def inputString = "create libceres-debug${project.libVersion}.a\n"
inputFiles.each {
def inFile = 'addlib ' + it + ".a\n"
inputString += inFile
}

inputString += "save\nend\n"
standardInput = new ByteArrayInputStream(inputString.getBytes())
}
}

task cppLibsZipStatic(type: Zip) {
dependsOn mergeStaticLibs
destinationDirectory = outputsFolder
archiveClassifier = outputClassifierStatic
archiveBaseName = zipBaseName
Expand All @@ -127,13 +230,14 @@ task cppLibsZipStatic(type: Zip) {
from(resolvedDir.toFile()) {
into project.platformPath + '/static'
exclude '**/pkgconfig'
include '**/*.a'
include '**/*.lib'
include "**/libceres${project.libVersion}.a"
include "**/ceres${project.libVersion}.lib"
include '**/*.pdb'
}
}

task cppLibsZipStaticDebug(type: Zip) {
dependsOn mergeDebugStaticLibs
destinationDirectory = outputsFolder
archiveClassifier = outputClassifierStatic + 'debug'
archiveBaseName = zipBaseName
Expand All @@ -146,8 +250,8 @@ task cppLibsZipStaticDebug(type: Zip) {
from(resolvedDir.toFile()) {
into project.platformPath + '/static'
exclude '**/pkgconfig'
include '**/*.a'
include '**/*.lib'
include "**/libceres-debug${project.libVersion}.a"
include "**/ceres-debug${project.libVersion}.lib"
include '**/*.pdb'
}
}
Expand Down
Loading