Skip to content

Commit 7301a53

Browse files
authored
Merge pull request #6396 from Arthapz/dev
(packages) forward buildtype and library kind to underlying buildsystem (cmake, autotools)
2 parents ef67042 + fe70610 commit 7301a53

File tree

2 files changed

+51
-9
lines changed

2 files changed

+51
-9
lines changed

xmake/modules/package/tools/autoconf.lua

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,18 +86,40 @@ function _memcache()
8686
return memcache.cache("package.tools.autoconf")
8787
end
8888

89-
-- has `--with-pic`?
90-
function _has_with_pic(package)
91-
local has_with_pic = _memcache():get2(tostring(package), "with_pic")
92-
if has_with_pic == nil then
89+
-- has flag ?
90+
function _has_flag(package, flag)
91+
local flag_name = flag:gsub("-", "")
92+
local has_flag = _memcache():get2(tostring(package), flag_name)
93+
if has_flag == nil then
9394
local result = try {function() return os.iorunv("./configure", {"--help"}, {shell = true}) end}
94-
if result and result:find("--with-pic", 1, true) then
95-
has_with_pic = true
95+
if result and result:find(flag, 1, true) then
96+
has_flag = true
9697
end
97-
has_with_pic = has_with_pic or false
98-
_memcache():set2(tostring(package), "with_pic", has_with_pic)
98+
has_flag = has_flag or false
99+
_memcache():set2(tostring(package), flag_name, has_flag)
99100
end
100-
return has_with_pic
101+
return has_flag
102+
end
103+
104+
105+
-- has `--with-pic`?
106+
function _has_with_pic(package)
107+
return _has_flag(package, "--with-pic")
108+
end
109+
110+
-- has `--enable-debug`?
111+
function _has_enable_debug(package)
112+
return _has_flag(package, "--enable-debug")
113+
end
114+
115+
-- has `--enable-static` and `--enable-shared`?
116+
function _has_enable_kind(package)
117+
return _has_flag(package, "--enable-static") and _has_flag(package, "--enable-shared")
118+
end
119+
120+
-- has `--disable-static` and `--disable-shared`?
121+
function _has_disable_kind(package)
122+
return _has_flag(package, "--disable-static") and _has_flag(package, "--disable-shared")
101123
end
102124

103125
-- get configs
@@ -170,6 +192,21 @@ function _get_configs(package, configs)
170192
package:config("pic") ~= false and _has_with_pic(package) then
171193
table.insert(configs, "--with-pic")
172194
end
195+
if package:is_debug() and _has_enable_debug(package) then
196+
table.insert(configs, "--enable-debug")
197+
end
198+
if package:is_library() then
199+
if _has_enable_kind(package) then
200+
table.insert(configs, "--enable-shared=" .. (package:config("shared") and "yes" or "no"))
201+
table.insert(configs, "--enable-static=" .. (package:config("shared") and "no" or "yes"))
202+
elseif _has_disable_kind(package) then
203+
if package:config("shared") then
204+
table.insert(configs, "--disable-static")
205+
else
206+
table.insert(configs, "--disable-shared")
207+
end
208+
end
209+
end
173210
return configs
174211
end
175212

xmake/modules/package/tools/cmake.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,11 @@ function _get_configs_for_generic(package, configs, opt)
427427
if not package:use_external_includes() then
428428
table.insert(configs, "-DCMAKE_NO_SYSTEM_FROM_IMPORTED=ON")
429429
end
430+
if package:is_debug() then
431+
table.insert(configs, "-DCMAKE_BUILD_TYPE=Debug")
432+
else
433+
table.insert(configs, "-DCMAKE_BUILD_TYPE=Release")
434+
end
430435
end
431436

432437
-- get configs for windows

0 commit comments

Comments
 (0)