Browse Source

update suitesparse and ceres-solver (#3126)

* fix openblas

* update suitesparse

* update ceres-solver

* fix gmp for macos arm
Hoildkv 1 year ago
parent
commit
60c8bda25c

+ 10 - 3
packages/c/ceres-solver/xmake.lua

@@ -2,10 +2,12 @@ package("ceres-solver")
 
 
     set_homepage("http://ceres-solver.org/")
     set_homepage("http://ceres-solver.org/")
     set_description("Ceres Solver is an open source C++ library for modeling and solving large, complicated optimization problems.")
     set_description("Ceres Solver is an open source C++ library for modeling and solving large, complicated optimization problems.")
+    set_license("BSD-3-Clause")
     
     
     add_urls("http://ceres-solver.org/ceres-solver-$(version).tar.gz")
     add_urls("http://ceres-solver.org/ceres-solver-$(version).tar.gz")
     add_versions("2.0.0", "10298a1d75ca884aa0507d1abb0e0f04800a92871cd400d4c361b56a777a7603")
     add_versions("2.0.0", "10298a1d75ca884aa0507d1abb0e0f04800a92871cd400d4c361b56a777a7603")
     add_versions("2.1.0", "f7d74eecde0aed75bfc51ec48c91d01fe16a6bf16bce1987a7073286701e2fc6")
     add_versions("2.1.0", "f7d74eecde0aed75bfc51ec48c91d01fe16a6bf16bce1987a7073286701e2fc6")
+    add_versions("2.2.0", "48b2302a7986ece172898477c3bcd6deb8fb5cf19b3327bc49969aad4cede82d")
 
 
     add_configs("blas",        {description = "Choose BLAS library to use.", default = "openblas", type = "string", values = {"mkl", "openblas"}})
     add_configs("blas",        {description = "Choose BLAS library to use.", default = "openblas", type = "string", values = {"mkl", "openblas"}})
     add_configs("suitesparse", {description = "Enable SuiteSparse.", default = true, type = "boolean"})
     add_configs("suitesparse", {description = "Enable SuiteSparse.", default = true, type = "boolean"})
@@ -14,10 +16,11 @@ package("ceres-solver")
     on_load("windows", "linux", "macosx", function (package)
     on_load("windows", "linux", "macosx", function (package)
         if package:config("suitesparse") then
         if package:config("suitesparse") then
             package:add("deps", "suitesparse", {configs = {blas = package:config("blas")}})
             package:add("deps", "suitesparse", {configs = {blas = package:config("blas")}})
+            package:add("deps", "openmp")
         end
         end
     end)
     end)
 
 
-    on_install("windows", "linux", "macosx", function (package)
+    on_install("windows|x64", "linux", "macosx", function (package)
         local configs = {"-DBUILD_TESTING=OFF", "-DBUILD_DOCUMENTATION=OFF", "-DBUILD_EXAMPLES=OFF", "-DBUILD_BENCHMARKS=OFF"}
         local configs = {"-DBUILD_TESTING=OFF", "-DBUILD_DOCUMENTATION=OFF", "-DBUILD_EXAMPLES=OFF", "-DBUILD_BENCHMARKS=OFF"}
         table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
         table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
         table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
         table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
@@ -26,9 +29,13 @@ package("ceres-solver")
         end
         end
         table.insert(configs, "-DSUITESPARSE=" .. (package:config("suitesparse") and "ON" or "OFF"))
         table.insert(configs, "-DSUITESPARSE=" .. (package:config("suitesparse") and "ON" or "OFF"))
         table.insert(configs, "-DCXSPARSE=" .. (package:config("suitesparse") and "ON" or "OFF"))
         table.insert(configs, "-DCXSPARSE=" .. (package:config("suitesparse") and "ON" or "OFF"))
-        import("package.tools.cmake").install(package, configs)
+        if package:config("suitesparse") then
+            import("package.tools.cmake").install(package, configs, {packagedeps = {"openmp", "libomp"}})
+        else
+            import("package.tools.cmake").install(package, configs)
+        end
     end)
     end)
 
 
     on_test(function (package)
     on_test(function (package)
-        assert(package:has_cxxtypes("ceres::Problem", {configs = {languages = "c++14"}, includes = "ceres/ceres.h"}))
+        assert(package:has_cxxtypes("ceres::Problem", {configs = {languages = "c++17"}, includes = "ceres/ceres.h"}))
     end)
     end)

+ 17 - 2
packages/g/gmp/xmake.lua

@@ -9,7 +9,7 @@ package("gmp")
     add_urls("https://gmplib.org/download/gmp/gmp-$(version).tar.xz")
     add_urls("https://gmplib.org/download/gmp/gmp-$(version).tar.xz")
     add_versions("6.2.1", "fd4829912cddd12f84181c3451cc752be224643e87fac497b69edddadc49b4f2")
     add_versions("6.2.1", "fd4829912cddd12f84181c3451cc752be224643e87fac497b69edddadc49b4f2")
     add_versions("6.3.0", "a3c2b80201b89e68616f4ad30bc66aee4927c3ce50e33929ca819d5c43538898")
     add_versions("6.3.0", "a3c2b80201b89e68616f4ad30bc66aee4927c3ce50e33929ca819d5c43538898")
-    
+
     if is_plat("mingw") and is_subhost("msys") then
     if is_plat("mingw") and is_subhost("msys") then
         add_extsources("pacman::gmp")
         add_extsources("pacman::gmp")
     elseif is_plat("linux") then
     elseif is_plat("linux") then
@@ -18,6 +18,12 @@ package("gmp")
         add_extsources("brew::gmp")
         add_extsources("brew::gmp")
     end
     end
 
 
+    on_fetch(function (package, opt)
+        if opt.system then
+            return package:find_package("system::gmp", {includes = "gmp.h"})
+        end
+    end)
+
     add_deps("m4")
     add_deps("m4")
 
 
     on_install("macosx", "linux", function (package)
     on_install("macosx", "linux", function (package)
@@ -30,7 +36,16 @@ package("gmp")
         if package:config("pic") ~= false then
         if package:config("pic") ~= false then
             table.insert(configs, "--with-pic")
             table.insert(configs, "--with-pic")
         end
         end
-        import("package.tools.autoconf").install(package, configs)
+        if package:is_plat("macosx") and package:is_arch("arm64") and os.arch() == "x86_64" then
+            import("package.tools.autoconf")
+            table.insert(configs, "--build=x86_64-apple-darwin")
+            table.insert(configs, "--host=arm64-apple-darwin")
+            local envs = autoconf.buildenvs(package, {cflags = "--target=arm64-apple-darwin"})
+            envs.CC = package:build_getenv("cc") .. " -arch arm64" -- for linker flags
+            autoconf.install(package, configs, {envs = envs})
+        else
+            import("package.tools.autoconf").install(package, configs)
+        end
     end)
     end)
 
 
     on_test(function (package)
     on_test(function (package)

+ 6 - 3
packages/o/openblas/xmake.lua

@@ -78,6 +78,12 @@ package("openblas")
         if package:is_plat("linux") then
         if package:is_plat("linux") then
             table.insert(configs, "CC=" .. package:build_getenv("cc"))
             table.insert(configs, "CC=" .. package:build_getenv("cc"))
         end
         end
+        if package:is_plat("macosx") and package:is_arch("arm64") then
+            table.insert(configs, "TARGET=VORTEX")
+            table.insert(configs, "BINARY=64")
+            table.insert(configs, "CFLAGS=-arch arm64")
+            table.insert(configs, "LDFLAGS=-arch arm64")
+        end
         if package:debug() then table.insert(configs, "DEBUG=1") end
         if package:debug() then table.insert(configs, "DEBUG=1") end
         if package:config("openmp") then table.insert(configs, "USE_OPENMP=1") end
         if package:config("openmp") then table.insert(configs, "USE_OPENMP=1") end
         if not package:config("shared") then
         if not package:config("shared") then
@@ -97,9 +103,6 @@ package("openblas")
             if package:is_arch("i386", "x86") then
             if package:is_arch("i386", "x86") then
                 table.insert(configs, "BINARY=32")
                 table.insert(configs, "BINARY=32")
             end
             end
-            if package:config("shared") then
-                package:addenv("PATH", "bin")
-            end
         else
         else
             local cflags
             local cflags
             local ldflags
             local ldflags

+ 8 - 1
packages/s/suitesparse/port/xmake.lua

@@ -162,7 +162,14 @@ target_end()
 
 
 if has_config("graphblas") then
 if has_config("graphblas") then
 target("GraphBLAS")
 target("GraphBLAS")
-    set_kind("$(kind)")
+    set_kind("static")
+    add_files("GraphBLAS/Source/*.c", "GraphBLAS/Source/Generated/*.c")
+    add_includedirs("GraphBLAS/Include", "GraphBLAS/Source", "GraphBLAS/Source/Template", "GraphBLAS/Source/Generated")
+    add_headerfiles("GraphBLAS/Include/*.h")
+target_end()
+else
+target("GraphBLAS")
+    set_kind("shared")
     add_files("GraphBLAS/Source/*.c", "GraphBLAS/Source/Generated/*.c")
     add_files("GraphBLAS/Source/*.c", "GraphBLAS/Source/Generated/*.c")
     add_includedirs("GraphBLAS/Include", "GraphBLAS/Source", "GraphBLAS/Source/Template", "GraphBLAS/Source/Generated")
     add_includedirs("GraphBLAS/Include", "GraphBLAS/Source", "GraphBLAS/Source/Template", "GraphBLAS/Source/Generated")
     add_headerfiles("GraphBLAS/Include/*.h")
     add_headerfiles("GraphBLAS/Include/*.h")

+ 66 - 15
packages/s/suitesparse/xmake.lua

@@ -8,41 +8,92 @@ package("suitesparse")
     add_versions("v5.10.1", "acb4d1045f48a237e70294b950153e48dce5b5f9ca8190e86c2b8c54ce00a7ee")
     add_versions("v5.10.1", "acb4d1045f48a237e70294b950153e48dce5b5f9ca8190e86c2b8c54ce00a7ee")
     add_versions("v5.12.0", "5fb0064a3398111976f30c5908a8c0b40df44c6dd8f0cc4bfa7b9e45d8c647de")
     add_versions("v5.12.0", "5fb0064a3398111976f30c5908a8c0b40df44c6dd8f0cc4bfa7b9e45d8c647de")
     add_versions("v5.13.0", "59c6ca2959623f0c69226cf9afb9a018d12a37fab3a8869db5f6d7f83b6b147d")
     add_versions("v5.13.0", "59c6ca2959623f0c69226cf9afb9a018d12a37fab3a8869db5f6d7f83b6b147d")
+    add_versions("v7.5.1", "dccfb5f75aa83fe2edb4eb2462fc984a086c82bad8433f63c31048d84b565d74")
 
 
     add_patches("5.x", path.join(os.scriptdir(), "patches", "5.10.1", "msvc.patch"), "8ac61e9acfaa864a2528a14d3a7e6e86f6e6877de2fe93fdc87876737af5bf31")
     add_patches("5.x", path.join(os.scriptdir(), "patches", "5.10.1", "msvc.patch"), "8ac61e9acfaa864a2528a14d3a7e6e86f6e6877de2fe93fdc87876737af5bf31")
 
 
+    add_configs("openmp", {description = "Enable OpenMP support.", default = true, type = "boolean"})
     add_configs("cuda", {description = "Enable CUDA support.", default = false, type = "boolean"})
     add_configs("cuda", {description = "Enable CUDA support.", default = false, type = "boolean"})
-    add_configs("blas", {description = "Set BLAS vendor.", default = "openblas", type = "string", values = {"mkl", "openblas"}})
-    add_configs("graphblas", {description = "Enable GraphBLAS module.", default = false, type = "boolean"})
+    add_configs("blas", {description = "Set BLAS vendor.", default = "openblas", type = "string", values = {"mkl", "openblas", "apple"}})
+    add_configs("blas_static", {description = "Use static BLAS library.", default = true, type = "boolean"})
+    add_configs("graphblas", {description = "Enable static GraphBLAS module.", default = false, type = "boolean"})
 
 
     add_deps("metis")
     add_deps("metis")
+    if not is_plat("windows") then
+        add_deps("gmp", "mpfr")
+    end
     if is_plat("linux") then
     if is_plat("linux") then
         add_syslinks("m", "rt")
         add_syslinks("m", "rt")
     end
     end
     on_load("windows", "macosx", "linux", function (package)
     on_load("windows", "macosx", "linux", function (package)
+        if package:version():ge("7.4.0") then
+            package:add("deps", "cmake")
+        end
+        if package:config("openmp") then
+            package:add("deps", "openmp")
+        end
         if package:config("cuda") then
         if package:config("cuda") then
             package:add("deps", "cuda", {system = true, configs = {utils = {"cublas"}}})
             package:add("deps", "cuda", {system = true, configs = {utils = {"cublas"}}})
             package:add("links", "GPUQREngine")
             package:add("links", "GPUQREngine")
             package:add("links", "SuiteSparse_GPURuntime")
             package:add("links", "SuiteSparse_GPURuntime")
         end
         end
-        if package:config("graphblas") then
-            package:add("links", "GraphBLAS")
+        if package:config("blas") == "apple" then
+            package:add("frameworks", "Accelerate")
+        else
+            package:add("deps", package:config("blas"))
         end
         end
-        package:add("deps", package:config("blas"))
-        for _, lib in ipairs({"SPQR", "UMFPACK", "LDL", "KLU", "CXSparse", "CHOLMOD", "COLAMD", "CCOLAMD", "CAMD", "BTF", "AMD", "suitesparseconfig"}) do
-            package:add("links", lib)
+        if package:version():ge("7.4.0") then
+            local suffix = ""
+            if package:is_plat("windows") and not package:config("shared") then
+                suffix = "_static"
+            end
+            for _, lib in ipairs({"lagraphx", "lagraph", "graphblas", "spex", "spqr", "rbio", "ParU", "umfpack", "ldl", "klu", "klu_cholmod", "cxsparse", "cholmod", "colamd", "ccolamd", "camd", "btf", "amd", "suitesparse_mongoose", "suitesparseconfig"}) do
+                package:add("links", lib .. suffix)
+            end
+        else
+            for _, lib in ipairs({"SPQR", "UMFPACK", "LDL", "KLU", "CXSparse", "CHOLMOD", "COLAMD", "CCOLAMD", "CAMD", "BTF", "AMD", "suitesparseconfig"}) do
+                package:add("links", lib)
+            end
         end
         end
     end)
     end)
 
 
-    on_install("windows", "macosx", "linux", function (package)
-        os.cp(path.join(package:scriptdir(), "port", "xmake.lua"), "xmake.lua")
-        local configs = {}
-        configs.with_blas = package:config("blas")
-        configs.with_cuda = package:config("cuda")
-        configs.graphblas = package:config("graphblas")
-        import("package.tools.xmake").install(package, configs)
+    on_install("windows|x64", "macosx", "linux", function (package)
+        if package:version():ge("7.4.0") then
+            local configs = {"-DSUITESPARSE_DEMOS=OFF"}
+            table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
+            table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
+            table.insert(configs, "-DBUILD_STATIC_LIBS=" .. (package:config("shared") and "OFF" or "ON"))
+            table.insert(configs, "-DGRAPHBLAS_BUILD_STATIC_LIBS=" .. (package:config("graphblas") and "ON" or "OFF"))
+            table.insert(configs, "-DSUITESPARSE_USE_OPENMP=" .. (package:config("openmp") and "ON" or "OFF"))
+            table.insert(configs, "-DSUITESPARSE_USE_CUDA=" .. (package:config("cuda") and "ON" or "OFF"))
+            local bla_vendor = {mkl = "Intel10_64lp", openblas = "OpenBLAS", apple = "Apple"}
+            table.insert(configs, "-DBLA_VENDOR=" .. bla_vendor[package:config("blas")])
+            table.insert(configs, "-DBLA_STATIC=" .. (package:config("blas_static") and "ON" or "OFF"))
+            if package:is_plat("windows") then
+                table.insert(configs, "-DSUITESPARSE_ENABLE_PROJECTS=suitesparse_config;mongoose;amd;btf;camd;ccolamd;colamd;cholmod;cxsparse;ldl;klu;umfpack;paru;rbio;spqr;graphblas;lagraph") -- remove spex since it does not support windows
+                local vs_sdkver = import("core.tool.toolchain").load("msvc"):config("vs_sdkver")
+                if vs_sdkver then
+                    local build_ver = string.match(vs_sdkver, "%d+%.%d+%.(%d+)%.?%d*")
+                    assert(tonumber(build_ver) >= 18362, "cpuinfo requires Windows SDK to be at least 10.0.18362.0")
+                    table.insert(configs, "-DCMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION=" .. vs_sdkver)
+                    table.insert(configs, "-DCMAKE_SYSTEM_VERSION=" .. vs_sdkver)
+                end
+            end
+            import("package.tools.cmake").install(package, configs)
+        else
+            os.cp(path.join(package:scriptdir(), "port", "xmake.lua"), "xmake.lua")
+            local configs = {}
+            configs.with_blas = package:config("blas")
+            configs.with_cuda = package:config("cuda")
+            configs.graphblas = package:config("graphblas")
+            import("package.tools.xmake").install(package, configs)
+        end
     end)
     end)
 
 
     on_test(function (package)
     on_test(function (package)
-        assert(package:has_cfuncs("SuiteSparse_start", {includes = "SuiteSparse_config.h"}))
+        if package:version():ge("7.4.0") then
+            assert(package:has_cfuncs("SuiteSparse_start", {includes = "suitesparse/SuiteSparse_config.h"}))
+        else
+            assert(package:has_cfuncs("SuiteSparse_start", {includes = "SuiteSparse_config.h"}))
+        end
     end)
     end)