Skip to content

Commit 68debc9

Browse files
authored
ftxui: Add modules support (#7301)
1 parent 3135df4 commit 68debc9

File tree

2 files changed

+175
-5
lines changed

2 files changed

+175
-5
lines changed

packages/f/ftxui/port/xmake.lua

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
set_xmakever("2.9.8")
2+
set_project("ftxui")
3+
4+
option("modules", { default = false, "enable C++20 module support"})
5+
option("microsoft_fallback_terminal", { default = true, description = "On windows, assume the \
6+
terminal used will be one of Microsoft and use a set of reasonnable fallback \
7+
to counteract its implementations problems.", type = "boolean" })
8+
9+
add_rules("mode.release", "mode.debug")
10+
11+
local libs = {
12+
screen = {files = {
13+
"src/ftxui/screen/box.cpp",
14+
"src/ftxui/screen/color.cpp",
15+
"src/ftxui/screen/color_info.cpp",
16+
"src/ftxui/screen/image.cpp",
17+
"src/ftxui/screen/screen.cpp",
18+
"src/ftxui/screen/string.cpp",
19+
"src/ftxui/screen/terminal.cpp",
20+
}},
21+
dom = {deps = {"screen"}, files = {
22+
"src/ftxui/dom/automerge.cpp",
23+
"src/ftxui/dom/selection_style.cpp",
24+
"src/ftxui/dom/blink.cpp",
25+
"src/ftxui/dom/bold.cpp",
26+
"src/ftxui/dom/border.cpp",
27+
"src/ftxui/dom/box_helper.cpp",
28+
"src/ftxui/dom/canvas.cpp",
29+
"src/ftxui/dom/clear_under.cpp",
30+
"src/ftxui/dom/color.cpp",
31+
"src/ftxui/dom/composite_decorator.cpp",
32+
"src/ftxui/dom/dbox.cpp",
33+
"src/ftxui/dom/dim.cpp",
34+
"src/ftxui/dom/flex.cpp",
35+
"src/ftxui/dom/flexbox.cpp",
36+
"src/ftxui/dom/flexbox_config.cpp",
37+
"src/ftxui/dom/flexbox_helper.cpp",
38+
"src/ftxui/dom/focus.cpp",
39+
"src/ftxui/dom/frame.cpp",
40+
"src/ftxui/dom/gauge.cpp",
41+
"src/ftxui/dom/graph.cpp",
42+
"src/ftxui/dom/gridbox.cpp",
43+
"src/ftxui/dom/hbox.cpp",
44+
"src/ftxui/dom/hyperlink.cpp",
45+
"src/ftxui/dom/inverted.cpp",
46+
"src/ftxui/dom/italic.cpp",
47+
"src/ftxui/dom/linear_gradient.cpp",
48+
"src/ftxui/dom/node.cpp",
49+
"src/ftxui/dom/node_decorator.cpp",
50+
"src/ftxui/dom/paragraph.cpp",
51+
"src/ftxui/dom/reflect.cpp",
52+
"src/ftxui/dom/scroll_indicator.cpp",
53+
"src/ftxui/dom/selection.cpp",
54+
"src/ftxui/dom/separator.cpp",
55+
"src/ftxui/dom/size.cpp",
56+
"src/ftxui/dom/spinner.cpp",
57+
"src/ftxui/dom/strikethrough.cpp",
58+
"src/ftxui/dom/table.cpp",
59+
"src/ftxui/dom/text.cpp",
60+
"src/ftxui/dom/underlined.cpp",
61+
"src/ftxui/dom/underlined_double.cpp",
62+
"src/ftxui/dom/util.cpp",
63+
"src/ftxui/dom/vbox.cpp",
64+
}},
65+
component = {deps = {"dom"}, files = {
66+
"src/ftxui/component/animation.cpp",
67+
"src/ftxui/component/button.cpp",
68+
"src/ftxui/component/catch_event.cpp",
69+
"src/ftxui/component/checkbox.cpp",
70+
"src/ftxui/component/collapsible.cpp",
71+
"src/ftxui/component/component.cpp",
72+
"src/ftxui/component/component_options.cpp",
73+
"src/ftxui/component/container.cpp",
74+
"src/ftxui/component/dropdown.cpp",
75+
"src/ftxui/component/event.cpp",
76+
"src/ftxui/component/hoverable.cpp",
77+
"src/ftxui/component/input.cpp",
78+
"src/ftxui/component/loop.cpp",
79+
"src/ftxui/component/maybe.cpp",
80+
"src/ftxui/component/menu.cpp",
81+
"src/ftxui/component/modal.cpp",
82+
"src/ftxui/component/radiobox.cpp",
83+
"src/ftxui/component/radiobox.cpp",
84+
"src/ftxui/component/renderer.cpp",
85+
"src/ftxui/component/resizable_split.cpp",
86+
"src/ftxui/component/screen_interactive.cpp",
87+
"src/ftxui/component/slider.cpp",
88+
"src/ftxui/component/terminal_input_parser.cpp",
89+
"src/ftxui/component/util.cpp",
90+
"src/ftxui/component/window.cpp",
91+
}}
92+
}
93+
94+
namespace("ftxui", function()
95+
for name, lib in table.orderpairs(libs) do
96+
local src_dir = path.join("src", "ftxui", name)
97+
local include_dir = path.join("include", "(ftxui", name)
98+
target(name)
99+
set_kind("$(kind)")
100+
if get_config("modules") then
101+
add_languages("c++20")
102+
else
103+
add_languages("c++17")
104+
end
105+
add_files(lib.files)
106+
add_cxflags("/utf-8", "/wd4244", "/wd4267", "/D_CRT_SECURE_NO_WARNINGS", {tools = {"cl"}})
107+
add_cxflags("-pipe", {tools = {"gcc", "clang"}})
108+
if is_plat("windows") then
109+
add_defines("UNICODE", "_UNICODE")
110+
end
111+
if has_config("microsoft_fallback_terminal") then
112+
add_defines("FTXUI_MICROSOFT_TERMINAL_FALLBACK")
113+
end
114+
add_headerfiles(path.join(include_dir, "**.hpp)"))
115+
add_headerfiles("include/(ftxui/util/**.hpp)")
116+
add_includedirs("include", {public = true})
117+
add_includedirs("src")
118+
if get_config("modules") then
119+
add_files(path.join(src_dir, "**.cppm"), {public = true})
120+
end
121+
set_basename("ftxui-" .. name)
122+
set_policy("build.c++.modules.std", false)
123+
if lib.deps then
124+
add_deps(table.unpack(lib.deps))
125+
end
126+
end
127+
128+
target("ftxui")
129+
if get_config("modules") then
130+
set_kind("moduleonly")
131+
add_languages("c++20")
132+
add_files(path.join("src", "ftxui", "*.cppm"))
133+
add_files(path.join("src", "ftxui", "util", "*.cppm"))
134+
else
135+
set_kind("phony")
136+
end
137+
138+
add_deps("screen", "dom", "component")
139+
end)

packages/f/ftxui/xmake.lua

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,50 @@ package("ftxui")
1414

1515
add_deps("cmake")
1616

17+
add_configs("modules", { default = false, type = "boolean" })
18+
add_configs("microsoft_fallback_terminal", { default = true, description = "On windows, assume the \
19+
terminal used will be one of Microsoft and use a set of reasonnable fallback \
20+
to counteract its implementations problems.", type = "boolean" })
21+
1722
if is_plat("windows") then
1823
add_configs("shared", {description = "Build shared library.", default = false, type = "boolean", readonly = true})
1924
elseif is_plat("linux", "bsd") then
2025
add_syslinks("pthread")
2126
end
2227

23-
add_links("ftxui-component", "ftxui-dom", "ftxui-screen")
28+
add_components("screen", "dom", "component")
29+
30+
on_load(function(package)
31+
if package:config("modules") then
32+
assert(package:gitref() or (package:version() and package:version():gt("1.0")), "modules support is not compatible with ftxui <= 1.0")
33+
end
34+
end)
35+
36+
on_component("screen", function(_, component)
37+
component:add("links","ftxui-screen")
38+
end)
39+
40+
on_component("dom", function(_, component)
41+
component:add("links", "ftxui-dom")
42+
component:add("deps", "screen")
43+
end)
44+
45+
on_component("component", function(_, component)
46+
component:add("links", "ftxui-component")
47+
component:add("deps", "dom")
48+
end)
2449

2550
on_install("linux", "windows", "macosx", "bsd", "mingw", "cross", function (package)
26-
local configs = {"-DFTXUI_BUILD_DOCS=OFF", "-DFTXUI_BUILD_EXAMPLES=OFF"}
27-
table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
28-
table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
29-
import("package.tools.cmake").install(package, configs)
51+
if package:config("modules") then
52+
os.cp(path.join(package:scriptdir(), "port", "xmake.lua"), ".")
53+
import("package.tools.xmake").install(package, {modules = package:config("modules"), microsoft_fallback_terminal = package:config("microsoft_fallback_terminal")})
54+
else
55+
local configs = {"-DFTXUI_BUILD_DOCS=OFF", "-DFTXUI_BUILD_EXAMPLES=OFF"}
56+
table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
57+
table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
58+
table.insert(configs, "-DFTXUI_MICROSOFT_TERMINAL_FALLBACK=" .. (package:config("microsoft_fallback_terminal") and "ON" or "OFF"))
59+
import("package.tools.cmake").install(package, configs)
60+
end
3061
end)
3162

3263
on_test(function (package)

0 commit comments

Comments
 (0)