Skip to content

Commit

Permalink
support dl & gmp
Browse files Browse the repository at this point in the history
  • Loading branch information
star-hengxing committed Dec 17, 2024
1 parent 0d64f4f commit 1b7eb84
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 8 deletions.
45 changes: 42 additions & 3 deletions packages/g/glpk/port/xmake.lua
Original file line number Diff line number Diff line change
@@ -1,12 +1,46 @@
option("dl", {default = nil, type = "string", values = {"ltdl", "dlfcn"}})
option("gmp", {default = false})
option("mysql", {default = false})
option("odbc", {default = false})

add_rules("mode.debug", "mode.release")

add_requires("zlib")

local dl = get_config("dl")
if dl == "ltdl" then
add_requires("libtool", {kind = "library"})
add_packages("libtool")
add_defines("HAVE_LTDL")
elseif dl == "dlfcn" then
if is_plat("linux", "bsd") then
add_syslinks("dl")
end
add_defines("HAVE_DLFCN")
end

if has_config("gmp") then
add_requires("gmp")
add_packages("gmp")
add_defines("HAVE_GMP")
end

if has_config("mysql") then
add_requires("mysql")
-- TODO
-- add_defines("MYSQL_DLNAME=" .. mysql shared link name)
end

includes("@builtin/check")

configvar_check_cincludes("HAVE_SYS_TIME_H", "sys/time.h")
configvar_check_cfuncs("HAVE_GETTIMEOFDAY", "gettimeofday", {includes = "time.h"})

target("glpk")
set_kind("$(kind)")
add_files("src/**.c|zlib/*.c")
add_includedirs("src", {public = true})
add_includedirs(
"src",
"src/amd",
"src/api",
"src/bflib",
Expand All @@ -25,10 +59,15 @@ target("glpk")
add_files("*.def")
end

if is_plat("windows") then
add_defines("__WOE__=1")
if is_plat("windows", "mingw", "msys") then
add_defines("__WOE__=1", "TLS=__declspec(thread)")
end

add_packages("zlib")

add_headerfiles("src/glpk.h")

target("glpsol")
set_kind("binary")
add_files("examples/glpsol.c")
add_deps("glpk")
55 changes: 50 additions & 5 deletions packages/g/glpk/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,36 @@ package("glpk")

add_versions("5.0", "4a1013eebb50f728fc601bdd833b0b2870333c3b3e5a816eeba921d95bec6f15")

add_configs("dl", {description = "Eenable shared library support", default = nil, type = "string", values = {"ltdl", "dlfcn"}})
add_configs("gmp", {description = "Enable gmp support", default = false, type = "boolean"})
add_configs("mysql", {description = "enable MathProg MySQL support", default = false, type = "boolean", readonly = true})
add_configs("odbc", {description = "enable MathProg ODBC support", default = false, type = "boolean", readonly = true})

if is_plat("linux") then
add_extsources("apt::libglpk-dev")
end

add_deps("zlib")

on_install("macosx", "linux", function (package)
local configs = {}
table.insert(configs, "--enable-shared=" .. (package:config("shared") and "yes" or "no"))
table.insert(configs, "--enable-static=" .. (package:config("shared") and "no" or "yes"))
import("package.tools.autoconf").install(package, configs)
on_load(function (package)
if package:config("gmp") then
package:add("deps", "gmp")
end
if package:config("mysql") then
package:add("deps", "mysql")
end
local dl = package:config("dl")
if dl == "ltdl" then
package:add("deps", "libtool", {kind = "library"})
elseif dl == "dlfcn" then
if package:is_plat("linux", "bsd") then
package:add("syslinks", "dl")
end
-- src/env/dlsup.c will use LoadLibrary/GetProcAddress/FreeLibrary
-- if package:is_plat("windows") then
-- package:add("deps", "dlfcn-win32")
-- end
end
end)

on_install(function (package)
Expand All @@ -32,10 +51,36 @@ package("glpk")
io.replace(def, "glp_netgen_prob\n", "", {plain = true})
end

local configs = {
dl = package:config("dl"),
gmp = package:config("gmp"),
mysql = package:config("mysql"),
odbc = package:config("odbc"),
}
os.cp(path.join(package:scriptdir(), "port", "xmake.lua"), "xmake.lua")
import("package.tools.xmake").install(package, configs)
end)

on_install("macosx", "linux", function (package)
local configs = {}
table.insert(configs, "--enable-shared=" .. (package:config("shared") and "yes" or "no"))
table.insert(configs, "--enable-static=" .. (package:config("shared") and "no" or "yes"))
table.insert(configs, "--enable-mysql=" .. (package:config("mysql") and "yes" or "no"))
table.insert(configs, "--enable-odbc=" .. (package:config("odbc") and "yes" or "no"))
local dl = package:config("dl")
if dl then
table.insert(configs, "--enable-dl=" .. dl)
else
table.insert(configs, "--disable-dl")
end
if package:config("gmp") then
table.insert(configs, "--with-gmp")
else
table.insert(configs, "--without-gmp")
end
import("package.tools.autoconf").install(package, configs)
end)

on_test(function (package)
assert(package:check_cxxsnippets({test = [[
#include <glpk.h>
Expand Down

0 comments on commit 1b7eb84

Please sign in to comment.