Skip to content

Commit d2510d1

Browse files
committed
(cmake, meson) append shared/static libraries by default when relevent
1 parent 93c6fb1 commit d2510d1

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

xmake/modules/package/tools/cmake.lua

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,10 +427,21 @@ 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+
local has_already_debugflag = opt._configs_str and opt._configs_str:find("CMAKE_BUILD_TYPE", 1, true)
430431
if package:is_debug() then
431-
table.insert(configs, "-DCMAKE_BUILD_TYPE=Debug")
432+
if not has_already_debugflag then
433+
table.insert(configs, "-DCMAKE_BUILD_TYPE=Debug")
434+
end
432435
else
433-
table.insert(configs, "-DCMAKE_BUILD_TYPE=Release")
436+
if not has_already_debugflag then
437+
table.insert(configs, "-DCMAKE_BUILD_TYPE=Release")
438+
end
439+
end
440+
if package:is_library() then
441+
local has_already_libflag = opt._configs_str and opt._configs_str:find("BUILD_SHARED_LIBS", 1, true)
442+
if not has_already_libflag then
443+
table.insert(configs, "-DBUILD_SHARED_LIBS=".. (package:config("shared") and "ON" or "OFF"))
444+
end
434445
end
435446
end
436447

@@ -644,6 +655,8 @@ function _get_configs_for_cross(package, configs, opt)
644655
opt = opt or {}
645656
opt.cross = true
646657
local envs = {}
658+
envs.CMAKE_BUILD_TYPE = package:is_debug() and "Debug" or "Release"
659+
envs.BUILD_SHARED_LIBS = package:config("shared") and "ON" or "OFF"
647660
local sdkdir = _translate_paths(package:build_getenv("sdk"))
648661
envs.CMAKE_C_COMPILER = _translate_bin_path(package:build_getenv("cc"))
649662
envs.CMAKE_CXX_COMPILER = _translate_bin_path(package:build_getenv("cxx"))

xmake/modules/package/tools/meson.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ function _get_configs(package, configs, opt)
330330

331331
-- add prefix
332332
configs = configs or {}
333+
opt._configs_str = string.serialize(configs, {indent = false, strip = true})
333334
table.insert(configs, "--prefix=" .. (opt.prefix or package:installdir()))
334335
table.insert(configs, "--libdir=lib")
335336

@@ -351,6 +352,14 @@ function _get_configs(package, configs, opt)
351352
table.insert(configs, "-Db_sanitize=address")
352353
end
353354

355+
-- add library kind
356+
if package:is_library() then
357+
local has_already_libflag = opt._configs_str and opt._configs_str:find("default_library", 1, true)
358+
if not has_already_libflag then
359+
table.insert(configs, "-Ddefault_library=".. (package:config("shared") and "shared" or "static"))
360+
end
361+
end
362+
354363
-- add vs runtimes flags
355364
if package:is_plat("windows") then
356365
table.insert(configs, "--vsenv")

0 commit comments

Comments
 (0)