Skip to content

Commit 98368da

Browse files
committed
[WIP]improve xmake port, add py-bind opt
1 parent b9d37f3 commit 98368da

File tree

2 files changed

+19
-65
lines changed

2 files changed

+19
-65
lines changed
Lines changed: 11 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,16 @@
11
set_project("dynareadout")
2+
add_rules("mode.debug", "mode.release")
23

3-
option("build_test")
4-
set_default(false)
5-
set_showmenu(true)
6-
7-
option("build_cpp")
8-
set_default(true)
9-
set_showmenu(true)
10-
11-
option("build_python")
12-
set_default(false)
13-
set_showmenu(true)
14-
15-
option("profiling")
16-
set_default(false)
17-
set_showmenu(true)
18-
add_defines("PROFILING")
19-
option_end()
4+
option("build_cpp", {default = true})
5+
option("build_python", {default = false})
6+
option("profiling", {default = false, defines = "PROFILING"})
207

21-
add_rules("mode.debug", "mode.release")
228
target("dynareadout")
239
set_kind("$(kind)")
2410
set_languages("ansi")
25-
if is_plat("linux") then
26-
add_cflags("-fPIC")
27-
end
2811
add_options("profiling")
2912
add_files("src/*.c")
30-
if not get_config("profiling") then
13+
if not has_config("profiling") then
3114
remove_files("src/profiling.c")
3215
end
3316
add_headerfiles("src/*.h")
@@ -36,16 +19,13 @@ target("dynareadout")
3619
end
3720
target_end()
3821

39-
if get_config("build_cpp") or get_config("build_python") then
22+
if has_config("build_cpp", "build_python") then
4023
if is_plat("macosx") then
4124
add_requires("boost", {configs = {filesystem = true}})
4225
end
4326
target("dynareadout_cpp")
4427
set_kind("$(kind)")
4528
set_languages("cxx17")
46-
if is_plat("linux") then
47-
add_cxxflags("-fPIC")
48-
end
4929
add_deps("dynareadout")
5030
add_includedirs("src")
5131
add_files("src/cpp/*.cpp")
@@ -59,48 +39,20 @@ if get_config("build_cpp") or get_config("build_python") then
5939
target_end()
6040
end
6141

62-
if get_config("build_test") then
63-
add_requires("doctest 2.4.8")
64-
target("dynareadout_test")
65-
set_kind("binary")
66-
set_languages("cxx17")
67-
add_deps("dynareadout")
68-
if is_plat("linux") then
69-
add_cxxflags("-fPIC")
70-
end
71-
if get_config("build_cpp") then
72-
add_deps("dynareadout_cpp")
73-
add_defines("BINOUT_CPP", "D3PLOT_CPP")
74-
add_includedirs("src/cpp")
75-
end
76-
add_packages("doctest")
77-
add_includedirs("src")
78-
add_options("profiling")
79-
add_files("test/*.cpp")
80-
target_end()
81-
end
82-
83-
if get_config("build_python") then
84-
add_requires("python3", "pybind11")
42+
if has_config("build_python") then
43+
add_requires("python 3.x", "pybind11")
8544
target("pybind11_module")
86-
set_kind("shared")
8745
set_languages("cxx17")
88-
if is_plat("linux") then
89-
add_cxxflags("-fPIC")
90-
end
9146
add_deps("dynareadout_cpp")
92-
add_packages("pybind11")
47+
add_packages("python", "pybind11")
48+
add_rules("python.module")
9349
add_options("profiling")
9450
add_files("src/python/*.cpp")
9551
add_headerfiles("src/python/*.hpp")
9652
add_includedirs("src", "src/cpp")
9753
add_rpathdirs("@executable_path")
9854

9955
on_load(function (target)
100-
local ext_file = os.tmpfile()
101-
os.execv("python3-config", {"--extension-suffix"}, {stdout=ext_file})
102-
ext_name = io.readfile(ext_file)
103-
ext_name = ext_name:gsub("%s+", "")
104-
target:set("filename", "dynareadout" .. (is_mode("debug") and "_d" or "") .. ext_name)
56+
target:set("filename", "dynareadout" .. (is_mode("debug") and "_d" or ""))
10557
end)
10658
end

packages/d/dynareadout/xmake.lua

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ package("dynareadout")
66
add_urls("https://github.com/xmake-mirror/dynareadout/releases/download/$(version)/$(version).tar.gz")
77
add_versions("24.07", "11138c1236f44434adf99ad86dc3315fcba17e59dd4b0ae0e6564972e2de12c5")
88

9-
add_configs("cpp", {description = "Build the C++ bindings", default = true, type = "boolean"})
10-
add_configs("profiling", {description = "Build with profiling features", default = true, type = "boolean"})
9+
add_configs("cpp_bind", {description = "Build the C++ bindings", default = true, type = "boolean"})
10+
add_configs("profiling", {description = "Build with profiling features", default = true, type = "boolean"})
11+
add_configs("python_bind", {description = "Build the python bindings", default = true, type = "boolean"})
1112

1213
on_load(function (package)
13-
if package:config("cpp") then
14+
if package:config("cpp_bind") then
1415
package:add("links", "dynareadout_cpp", "dynareadout")
1516
else
1617
package:add("links", "dynareadout")
@@ -24,16 +25,17 @@ package("dynareadout")
2425
os.cd("lib/dynareadout")
2526
os.cp(path.join(package:scriptdir(), "port", "xmake.lua"), "xmake.lua")
2627
local configs = {}
27-
configs.build_test = "n"
28-
configs.build_cpp = package:config("cpp") and "y" or "n"
28+
configs.build_cpp = package:config("cpp_bind") and "y" or "n"
2929
configs.profiling = package:config("profiling") and "y" or "n"
30+
configs.build_python = package:config("python_bind") and "y" or "n"
3031
import("package.tools.xmake").install(package, configs)
32+
wprint("The original repository PucklaJ/dynareadout is no longer public. You are using a mirror of this repository.")
3133
end)
3234

3335
on_test(function (package)
3436
assert(package:has_cfuncs("binout_open", {includes = "binout.h", configs = {languages = "ansi"}}))
3537
assert(package:has_cfuncs("d3plot_open", {includes = "d3plot.h", configs = {languages = "ansi"}}))
36-
if package:config("cpp") then
38+
if package:config("cpp_bind") then
3739
assert(package:has_cxxtypes("dro::Binout", {includes = "binout.hpp", configs = {languages = "cxx17"}}))
3840
assert(package:has_cxxtypes("dro::D3plot", {includes = "d3plot.hpp", configs = {languages = "cxx17"}}))
3941
assert(package:has_cxxtypes("dro::Array<int32_t>", {includes = {"array.hpp", "cstdint"}, configs = {languages = "cxx17"}}))

0 commit comments

Comments
 (0)