Skip to content

Commit

Permalink
Merge static libs and bump version to 2.2-3 (#8)
Browse files Browse the repository at this point in the history
Co-authored-by: Gold856 <[email protected]>
  • Loading branch information
ElliotScher and Gold856 authored Dec 4, 2024
1 parent 6e43303 commit 234c509
Showing 1 changed file with 102 additions and 5 deletions.
107 changes: 102 additions & 5 deletions publish.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ publishing {
}
}

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

def getTriplet() {
def triplet
def os_name = System.getProperty("os.name")
Expand Down Expand Up @@ -84,7 +87,7 @@ ext.platformPath = getPlatformPath(triplet)
ext.platformClassifier = ext.platformPath.replaceFirst('/', '')

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

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

Expand Down Expand Up @@ -148,7 +151,100 @@ task cppHeadersZip(type: Zip) {
dependsOn buildVcpkg
}

task mergeStaticLibs(type: Exec) {
dependsOn(buildVcpkg)
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", "gflags_static", "GKlib", "glog", "lapack", "libamd", "libbtf", "libcamd", "libccolamd", "libcholmod", "libcolamd", "libcxsparse", "libklu", "libldl", "libspqr", "libumfpack", "metis", "openblas", "suitesparseconfig", "libf2c"]
def setArgs = ["/OUT:ceres${project.libVersion}.lib"]
inputFiles.each {
setArgs << it + ".lib"
}
args = setArgs
} else if (project.platformPath.startsWith('osx')) {
executable 'libtool'
workingDir buildDirectory.resolve("lib").toString()

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

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

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

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

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", "libcolamd","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) {
dependsOn(buildVcpkg)
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", "gflags_static_debug", "GKlib", "glog", "lapack", "libamdd", "libbtfd", "libcamdd", "libccolamdd", "libcholmodd", "libcolamdd", "libcxsparsed", "libklud", "libldld", "libspqrd", "libumfpackd", "metis", "openblas", "suitesparseconfigd", "libf2c"]
def setArgs = ["/OUT:ceres-debug${project.libVersion}.lib"]
inputFiles.each {
setArgs << it + ".lib"
}
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", "libspqrd", "libamdd", "libcxsparsed", "libldld", "libglog", "libgflags_debug", "libcolamdd", "libmetis", "libccolamdd", "libcamdd", "libumfpackd", "libklud", "libcholmodd", "libceres-debug", "libbtfd", "libGKlib"]

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

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

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 @@ -161,14 +257,15 @@ 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'
}
dependsOn buildVcpkg
}

task cppLibsZipStaticDebug(type: Zip) {
dependsOn mergeDebugStaticLibs
destinationDirectory = outputsFolder
archiveClassifier = outputClassifierStatic + 'debug'
archiveBaseName = zipBaseName
Expand All @@ -181,8 +278,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'
}
dependsOn buildVcpkg
Expand Down

0 comments on commit 234c509

Please sign in to comment.