summaryrefslogtreecommitdiff
path: root/xmake/modules/package
diff options
context:
space:
mode:
authorArthur LAURENT <[email protected]>2025-05-09 14:22:32 +0200
committerArthur LAURENT <[email protected]>2025-05-09 14:22:32 +0200
commitd2510d16dbb6812e2a23721f1de4467b32099a4e (patch)
tree6ba7405e99dca1f7644dd05ae6583b6ea41bbc12 /xmake/modules/package
parent93c6fb1a2a7dbe2a320fa51ce3fd71818fb89d09 (diff)
(cmake, meson) append shared/static libraries by default when relevent
Diffstat (limited to 'xmake/modules/package')
-rw-r--r--xmake/modules/package/tools/cmake.lua17
-rw-r--r--xmake/modules/package/tools/meson.lua9
2 files changed, 24 insertions, 2 deletions
diff --git a/xmake/modules/package/tools/cmake.lua b/xmake/modules/package/tools/cmake.lua
index a674e9433..f2ffb12d8 100644
--- a/xmake/modules/package/tools/cmake.lua
+++ b/xmake/modules/package/tools/cmake.lua
@@ -427,10 +427,21 @@ function _get_configs_for_generic(package, configs, opt)
if not package:use_external_includes() then
table.insert(configs, "-DCMAKE_NO_SYSTEM_FROM_IMPORTED=ON")
end
+ local has_already_debugflag = opt._configs_str and opt._configs_str:find("CMAKE_BUILD_TYPE", 1, true)
if package:is_debug() then
- table.insert(configs, "-DCMAKE_BUILD_TYPE=Debug")
+ if not has_already_debugflag then
+ table.insert(configs, "-DCMAKE_BUILD_TYPE=Debug")
+ end
else
- table.insert(configs, "-DCMAKE_BUILD_TYPE=Release")
+ if not has_already_debugflag then
+ table.insert(configs, "-DCMAKE_BUILD_TYPE=Release")
+ end
+ end
+ if package:is_library() then
+ local has_already_libflag = opt._configs_str and opt._configs_str:find("BUILD_SHARED_LIBS", 1, true)
+ if not has_already_libflag then
+ table.insert(configs, "-DBUILD_SHARED_LIBS=".. (package:config("shared") and "ON" or "OFF"))
+ end
end
end
@@ -644,6 +655,8 @@ function _get_configs_for_cross(package, configs, opt)
opt = opt or {}
opt.cross = true
local envs = {}
+ envs.CMAKE_BUILD_TYPE = package:is_debug() and "Debug" or "Release"
+ envs.BUILD_SHARED_LIBS = package:config("shared") and "ON" or "OFF"
local sdkdir = _translate_paths(package:build_getenv("sdk"))
envs.CMAKE_C_COMPILER = _translate_bin_path(package:build_getenv("cc"))
envs.CMAKE_CXX_COMPILER = _translate_bin_path(package:build_getenv("cxx"))
diff --git a/xmake/modules/package/tools/meson.lua b/xmake/modules/package/tools/meson.lua
index d03745b41..852f7124c 100644
--- a/xmake/modules/package/tools/meson.lua
+++ b/xmake/modules/package/tools/meson.lua
@@ -330,6 +330,7 @@ function _get_configs(package, configs, opt)
-- add prefix
configs = configs or {}
+ opt._configs_str = string.serialize(configs, {indent = false, strip = true})
table.insert(configs, "--prefix=" .. (opt.prefix or package:installdir()))
table.insert(configs, "--libdir=lib")
@@ -351,6 +352,14 @@ function _get_configs(package, configs, opt)
table.insert(configs, "-Db_sanitize=address")
end
+ -- add library kind
+ if package:is_library() then
+ local has_already_libflag = opt._configs_str and opt._configs_str:find("default_library", 1, true)
+ if not has_already_libflag then
+ table.insert(configs, "-Ddefault_library=".. (package:config("shared") and "shared" or "static"))
+ end
+ end
+
-- add vs runtimes flags
if package:is_plat("windows") then
table.insert(configs, "--vsenv")