diff options
| author | ruki <[email protected]> | 2024-01-26 23:01:44 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-01-26 23:01:44 +0800 |
| commit | fd85ae0a81de712ca3837b262e936fd67b8f483f (patch) | |
| tree | 97894c8d36a17ca6437aedd10400b8f24574d783 | |
| parent | 042362f4c3f1dab8b6b5a32fcbbae20e66e224de (diff) | |
| parent | 2a43a89241ff5044661fa7449d6455386cd3a449 (diff) | |
Merge pull request #4630 from xmake-io/runtimes
Improve runtimes to support libc++/libstdc++
50 files changed, 827 insertions, 219 deletions
diff --git a/tests/projects/package/components/xmake.lua b/tests/projects/package/components/xmake.lua index 6185f5178..14dbe472d 100644 --- a/tests/projects/package/components/xmake.lua +++ b/tests/projects/package/components/xmake.lua @@ -175,7 +175,7 @@ package("sfml") table.insert(configs, "-DBUILD_SHARED_LIBS=ON") else table.insert(configs, "-DBUILD_SHARED_LIBS=OFF") - if package:is_plat("windows") and package:config("vs_runtime"):startswith("MT") then + if package:is_plat("windows") and package:runtimes():startswith("MT") then table.insert(configs, "-DSFML_USE_STATIC_STD_LIBS=ON") end end diff --git a/tests/projects/package/depconfigs/xmake.lua b/tests/projects/package/depconfigs/xmake.lua index 377c8899b..11623755c 100644 --- a/tests/projects/package/depconfigs/xmake.lua +++ b/tests/projects/package/depconfigs/xmake.lua @@ -1,5 +1,5 @@ -add_requires("libpng", {system = false, configs = {vs_runtime = "MD"}}) -add_requires("libtiff", {system = false, configs = {vs_runtime = "MD", zlib = true}}) +add_requires("libpng", {system = false, configs = {runtimes = "MD"}}) +add_requires("libtiff", {system = false, configs = {runtimes = "MD", zlib = true}}) add_requireconfs("libpng.zlib", {system = false, override = true, configs = {cxflags = "-DTEST1"}, version = "1.2.10"}) add_requireconfs("libtiff.*|cmake", {system = false, configs = {cxflags = "-DTEST2"}}) diff --git a/xmake/actions/config/xmake.lua b/xmake/actions/config/xmake.lua index 464afa662..4bf43c787 100644 --- a/xmake/actions/config/xmake.lua +++ b/xmake/actions/config/xmake.lua @@ -213,6 +213,15 @@ task("config") , " - xmake f --toolchain=[cross|llvm|sdcc ..] --sdk=/xxx" , " - run `xmake show -l toolchains` to get all toolchains" , values = _toolchain_values}, + {nil, "runtimes", "kv", nil, "Set the compiler runtime library." + , "e.g. " + , " - xmake f --runtimes=MTd" + , " - xmake f --runtimes=MT,c++_static" + , values = {"MT", "MTd", "MD", "MDd", -- only for msvc + "c++_static", "c++_shared", -- gcc/clang/android ndk + "stdc++_static", "stdc++_shared", -- gcc/clang + "gnustl_static", "gnustl_shared", -- only for old android ndk + "stlport_static", "stlport_shared"}}, -- only for old android ndk _language_menu_options, _platform_menu_options, {category = "Other Configuration"}, diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index d5e82b13f..5f9524019 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -1130,9 +1130,38 @@ function _instance:build_envs(lazy_loading) return build_envs end +-- get runtimes +function _instance:runtimes() + local runtimes = self:_memcache():get("runtimes") + if runtimes == nil then + runtimes = self:config("runtimes") + if runtimes then + local runtimes_current = runtimes:split(",", {plain = true}) + runtimes = table.unwrap(runtimes_current) + end + runtimes = runtimes or false + self:_memcache():set("runtimes", runtimes) + end + return runtimes or nil +end + +-- has the given runtime for the current toolchains? +function _instance:has_runtime(...) + local runtimes_set = self:_memcache():get("runtimes_set") + if runtimes_set == nil then + runtimes_set = hashset.from(table.wrap(self:runtimes())) + self:_memcache():set("runtimes_set", runtimes_set) + end + for _, v in ipairs(table.pack(...)) do + if runtimes_set:has(v) then + return true + end + end +end + -- get the given toolchain function _instance:toolchain(name) - local toolchains_map = self._TOOLCHAINS_MAP + local toolchains_map = self:_memcache():get("toolchains_map") if toolchains_map == nil then toolchains_map = {} local toolchains = self:toolchains() @@ -1141,7 +1170,7 @@ function _instance:toolchain(name) toolchains_map[toolchain_inst:name()] = toolchain_inst end end - self._TOOLCHAINS_MAP = toolchains_map + self:_memcache():set("toolchains_map", toolchains_map) end return toolchains_map[name] end @@ -1391,6 +1420,19 @@ function _instance:config(name) local configs = self:configs() if configs then value = configs[name] + -- vs_runtime is deprecated now + if name == "vs_runtime" then + local runtimes = configs.runtimes + if runtimes then + for _, item in ipairs(runtimes:split(",")) do + if item:startswith("MT") or item:startswith("MD") then + value = item + break + end + end + end + utils.warning("please use package:runtimes() or package:has_runtime() instead of package:config(\"vs_runtime\")") + end end return value end @@ -1416,6 +1458,10 @@ function _instance:configs() local value = configs_required[name] if value == nil then value = self:extraconf("configs", name, "default") + -- support for the deprecated vs_runtime in add_configs + if name == "runtimes" and value == nil then + value = self:extraconf("configs", "vs_runtime", "default") + end end configs[name] = value end @@ -1453,6 +1499,10 @@ function _instance:_configs_for_buildhash() local value = configs_required[name] if value == nil then value = self:extraconf("configs", name, "default") + -- support for the deprecated vs_runtime in add_configs + if name == "runtimes" and value == nil then + value = self:extraconf("configs", "vs_runtime", "default") + end end configs[name] = value end @@ -1465,10 +1515,19 @@ function _instance:_configs_for_buildhash() return configs and configs or nil end +-- compute the build hash +function _instance:_compute_buildhash() + self._BUILDHASH_PREPRARED = true + self:buildhash() +end + -- get the build hash function _instance:buildhash() local buildhash = self._BUILDHASH if buildhash == nil then + if not self._BUILDHASH_PREPRARED then + os.raise("package:buildhash() must be called after loading package") + end local function _get_buildhash(configs, opt) opt = opt or {} local str = self:plat() .. self:arch() @@ -1477,6 +1536,15 @@ function _instance:buildhash() str = str .. label end if configs then + + -- with old vs_runtime configs + -- https://github.com/xmake-io/xmake/issues/4477 + if opt.vs_runtime then + configs = table.clone(configs) + configs.vs_runtime = configs.runtimes + configs.runtimes = nil + end + -- since luajit v2.1, the key order of the table is random and undefined. -- We cannot directly deserialize the table, so the result may be different each time local configs_order = {} @@ -1554,6 +1622,16 @@ function _instance:buildhash() end end + -- we need to be compatible with the previous xmake version + -- with deprecated vs_runtime (< 2.8.7) + -- @see https://github.com/xmake-io/xmake/issues/4477 + if not buildhash then + buildhash = _get_buildhash(self:_configs_for_buildhash(), {vs_runtime = true}) + if not os.isdir(_get_installdir(buildhash)) then + buildhash = nil + end + end + -- get build hash for current version if not buildhash then buildhash = _get_buildhash(self:_configs_for_buildhash()) @@ -1775,6 +1853,13 @@ function _instance:find_package(name, opt) if system == nil and not name:startswith("xmake::") then system = true -- find system package by default end + local configs = table.clone(self:configs()) or {} + if opt.configs then + table.join2(configs, opt.configs) + end + if configs.runtimes then + configs.runtimes = self:runtimes() + end return self._find_package(name, { force = opt.force, installdir = self:installdir({readonly = true}), @@ -1783,7 +1868,7 @@ function _instance:find_package(name, opt) mode = self:mode(), plat = self:plat(), arch = self:arch(), - configs = table.join(self:configs(), opt.configs), + configs = configs, components = self:components_orderlist(), components_extsources = opt.components_extsources, buildhash = self:buildhash(), -- for xmake package or 3rd package manager, e.g. go:: .. @@ -2212,21 +2297,21 @@ function _instance:_generate_build_configs(configs, opt) configs = table.join(self:fetch_librarydeps(), configs) if self:is_plat("windows") then local ld = self:build_getenv("ld") - local vs_runtime = self:config("vs_runtime") - -- since we are ignoring the vs_runtime of the headeronly library, - -- we can only get the vs_runtime from the dependency library to detect the link. - if self:is_headeronly() and not vs_runtime and self:librarydeps() then + local runtimes = self:runtimes() + -- since we are ignoring the runtimes of the headeronly library, + -- we can only get the runtimes from the dependency library to detect the link. + if self:is_headeronly() and not runtimes and self:librarydeps() then for _, dep in ipairs(self:librarydeps()) do - if dep:is_plat("windows") and dep:config("vs_runtime") then - vs_runtime = dep:config("vs_runtime") + if dep:is_plat("windows") and dep:runtimes() then + runtimes = dep:runtimes() break end end end - if vs_runtime and ld and path.basename(ld:lower()) == "link" then -- for msvc? + if runtimes and ld and path.basename(ld:lower()) == "link" then -- for msvc? configs.cxflags = table.wrap(configs.cxflags) - table.insert(configs.cxflags, "/" .. vs_runtime) - if vs_runtime:startswith("MT") then + table.insert(configs.cxflags, "/" .. runtimes) + if runtimes:startswith("MT") then configs.ldflags = table.wrap(configs.ldflags) table.insert(configs.ldflags, "-nodefaultlib:msvcrt.lib") end @@ -2665,7 +2750,8 @@ function package.load_from_system(packagename) -- on install script local on_install = function (pkg) local opt = {} - opt.configs = pkg:configs() + local configs = table.clone(pkg:configs()) or {} + opt.configs = configs opt.mode = pkg:is_debug() and "debug" or "release" opt.plat = pkg:plat() opt.arch = pkg:arch() @@ -2673,6 +2759,9 @@ function package.load_from_system(packagename) opt.buildhash = pkg:buildhash() opt.cachedir = pkg:cachedir() opt.installdir = pkg:installdir() + if configs.runtimes then + configs.runtimes = pkg:runtimes() + end import("package.manager.install_package")(pkg:name(), opt) end diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua index 8a56a816e..f9a8fba77 100644 --- a/xmake/core/platform/platform.lua +++ b/xmake/core/platform/platform.lua @@ -162,7 +162,8 @@ function _instance:toolchains(opt) -- get the given toolchain local toolchain_given = config.get("toolchain") if toolchain_given then - local toolchain_inst, errors = toolchain.load(toolchain_given, {plat = self:name(), arch = self:arch()}) + local toolchain_inst, errors = toolchain.load(toolchain_given, { + plat = self:name(), arch = self:arch()}) -- attempt to load toolchain from project if not toolchain_inst and platform._project() then toolchain_inst = platform._project().toolchain(toolchain_given) @@ -181,7 +182,8 @@ function _instance:toolchains(opt) end if names then for _, name in ipairs(table.wrap(names)) do - local toolchain_inst, errors = toolchain.load(name, {plat = self:name(), arch = self:arch()}) + local toolchain_inst, errors = toolchain.load(name, { + plat = self:name(), arch = self:arch()}) -- attempt to load toolchain from project if not toolchain_inst and platform._project() then toolchain_inst = platform._project().toolchain(name) diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index f4cdafb0e..8cc2ff824 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -272,16 +272,55 @@ function _instance:_visibility(opt) return visibility end +-- update file rules +-- +-- if we add files in on_load() dynamically, we need to update file rules, +-- otherwise it will cause: unknown source file: ... +-- +function _instance:_update_filerules() + local rulenames = {} + local extensions = {} + for _, sourcefile in ipairs(table.wrap(self:get("files"))) do + local extension = path.extension((sourcefile:gsub("|.*$", ""))) + if not extensions[extension] then + local lang = language.load_ex(extension) + if lang and lang:rules() then + table.join2(rulenames, lang:rules()) + end + extensions[extension] = true + end + end + rulenames = table.unique(rulenames) + for _, rulename in ipairs(rulenames) do + local r = target._project() and target._project().rule(rulename) or rule.rule(rulename) + if r then + -- only add target rules + if r:kind() == "target" then + if not self:rule(rulename) then + self:rule_add(r) + for _, deprule in ipairs(r:orderdeps()) do + if not self:rule(deprule:name()) then + self:rule_add(deprule) + end + end + end + end + end + end +end + -- invalidate the previous cache function _instance:_invalidate(name) self._CACHEID = self._CACHEID + 1 self._POLICIES = nil + self:_memcache():clear() -- we need to flush the source files cache if target/files are modified, e.g. `target:add("files", "xxx.c")` if name == "files" then self._SOURCEFILES = nil self._FILESCONFIG = nil self._OBJECTFILES = nil self._SOURCEBATCHES = nil + self:_update_filerules() elseif name == "deps" then self._DEPS = nil self._ORDERDEPS = nil @@ -2380,6 +2419,51 @@ function _instance:pcoutputfile(langkind) end end +-- get runtimes +function _instance:runtimes() + local runtimes = self:_memcache():get("runtimes") + if runtimes == nil then + runtimes = self:get("runtimes") + if runtimes then + local runtimes_supported = hashset.new() + local toolchains = self:toolchains() or platform.load(self:plat(), self:arch()):toolchains() + if toolchains then + for _, toolchain_inst in ipairs(toolchains) do + if toolchain_inst:is_standalone() and toolchain_inst:get("runtimes") then + for _, runtime in ipairs(table.wrap(toolchain_inst:get("runtimes"))) do + runtimes_supported:insert(runtime) + end + end + end + end + local runtimes_current = {} + for _, runtime in ipairs(table.wrap(runtimes)) do + if runtimes_supported:has(runtime) then + table.insert(runtimes_current, runtime) + end + end + runtimes = table.unwrap(runtimes_current) + end + runtimes = runtimes or false + self:_memcache():set("runtimes", runtimes) + end + return runtimes or nil +end + +-- has the given runtime for the current toolchains? +function _instance:has_runtime(...) + local runtimes_set = self:_memcache():get("runtimes_set") + if runtimes_set == nil then + runtimes_set = hashset.from(table.wrap(self:runtimes())) + self:_memcache():set("runtimes_set", runtimes_set) + end + for _, v in ipairs(table.pack(...)) do + if runtimes_set:has(v) then + return true + end + end +end + -- get the given toolchain function _instance:toolchain(name) local toolchains_map = self:_memcache():get("toolchains_map") diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua index 4831bce5c..620b862d5 100644 --- a/xmake/core/tool/toolchain.lua +++ b/xmake/core/tool/toolchain.lua @@ -29,6 +29,7 @@ local utils = require("base/utils") local table = require("base/table") local global = require("base/global") local option = require("base/option") +local hashset = require("base/hashset") local scopeinfo = require("base/scopeinfo") local interpreter = require("base/interpreter") local config = require("project/config") @@ -567,6 +568,7 @@ function toolchain.apis() , "toolchain.set_bindir" , "toolchain.set_sdkdir" , "toolchain.set_archs" + , "toolchain.set_runtimes" , "toolchain.set_homepage" , "toolchain.set_description" } diff --git a/xmake/languages/c++/load.lua b/xmake/languages/c++/load.lua index 932769a7c..b38f4874b 100644 --- a/xmake/languages/c++/load.lua +++ b/xmake/languages/c++/load.lua @@ -25,7 +25,6 @@ function _get_apis() -- target.add_xxx "target.add_links" , "target.add_syslinks" - , "target.add_cflags" , "target.add_cxflags" , "target.add_cxxflags" , "target.add_ldflags" @@ -37,15 +36,11 @@ function _get_apis() , "target.add_rpathdirs" -- @note do not translate path, it's usually an absolute path or contains $ORIGIN/@loader_path , "target.add_forceincludes" -- option.add_xxx - , "option.add_cincludes" , "option.add_cxxincludes" - , "option.add_cfuncs" , "option.add_cxxfuncs" - , "option.add_ctypes" , "option.add_cxxtypes" , "option.add_links" , "option.add_syslinks" - , "option.add_cflags" , "option.add_cxflags" , "option.add_cxxflags" , "option.add_ldflags" @@ -58,7 +53,6 @@ function _get_apis() -- package.add_xxx , "package.add_links" , "package.add_syslinks" - , "package.add_cflags" , "package.add_cxflags" , "package.add_cxxflags" , "package.add_ldflags" @@ -75,7 +69,6 @@ function _get_apis() -- toolchain.add_xxx , "toolchain.add_links" , "toolchain.add_syslinks" - , "toolchain.add_cflags" , "toolchain.add_cxflags" , "toolchain.add_cxxflags" , "toolchain.add_ldflags" @@ -100,8 +93,7 @@ function _get_apis() } apis.paths = { -- target.set_xxx - "target.set_pcheader" - , "target.set_pcxxheader" + "target.set_pcxxheader" -- target.add_xxx , "target.add_headerfiles" , "target.add_linkdirs" @@ -116,8 +108,7 @@ function _get_apis() } apis.dictionary = { -- option.add_xxx - "option.add_csnippets" - , "option.add_cxxsnippets" + "option.add_cxxsnippets" } return apis end diff --git a/xmake/languages/c++/xmake.lua b/xmake/languages/c++/xmake.lua index 22a69a417..487746303 100644 --- a/xmake/languages/c++/xmake.lua +++ b/xmake/languages/c++/xmake.lua @@ -20,11 +20,11 @@ language("c++") add_rules("c++") - set_sourcekinds {cc = ".c", cxx = {".cpp", ".cc", ".cxx", ".mpp", ".mxx", ".cppm", ".ixx", ".c++"}} - set_sourceflags {cc = {"cflags", "cxflags"}, cxx = {"cxxflags", "cxflags"}} + set_sourcekinds {cxx = {".cpp", ".cc", ".cxx", ".mpp", ".mxx", ".cppm", ".ixx", ".c++"}} + set_sourceflags {cxx = {"cxxflags", "cxflags"}} set_targetkinds {binary = "ld", static = "ar", shared = "sh"} set_targetflags {binary = "ldflags", static = "arflags", shared = "shflags"} - set_langkinds {c = "cc", cxx = "cxx"} + set_langkinds {cxx = "cxx"} set_mixingkinds("cc", "cxx", "as", "mrc") on_load("load") @@ -49,7 +49,6 @@ language("c++") , "target.frameworks" , "target.exceptions" , "target.encodings" - , "target.pcheader" , "target.pcxxheader" , "target.forceincludes" , "toolchain.includedirs" @@ -118,9 +117,8 @@ language("c++") config = { {category = "Cross Complation Configuration/Compiler Configuration" } - , {nil, "cc", "kv", nil, "The C Compiler" } , {nil, "cxx", "kv", nil, "The C++ Compiler" } - , {nil, "cpp", "kv", nil, "The C Preprocessor" } + , {nil, "cpp", "kv", nil, "The C/C++ Preprocessor" } , {category = "Cross Complation Configuration/Linker Configuration" } , {nil, "ld", "kv", nil, "The Linker" } @@ -129,7 +127,6 @@ language("c++") , {nil, "ranlib", "kv", nil, "The Static Library Index Generator" } , {category = "Cross Complation Configuration/Compiler Flags Configuration" } - , {nil, "cflags", "kv", nil, "The C Compiler Flags" } , {nil, "cxflags", "kv", nil, "The C/C++ compiler Flags" } , {nil, "cxxflags", "kv", nil, "The C++ Compiler Flags" } diff --git a/xmake/languages/c/check_main.lua b/xmake/languages/c/check_main.lua new file mode 100644 index 000000000..55d00e2de --- /dev/null +++ b/xmake/languages/c/check_main.lua @@ -0,0 +1,41 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file check_main.lua +-- + + +-- check it +function main(sourcefile) + + -- load source code + local sourcecode = io.readfile(sourcefile) + + -- remove comment first + sourcecode = sourcecode:gsub("/%*.-%*/", "") + sourcecode = sourcecode:gsub("//.-\n", "\n") + + -- find int main(int argc, char** argv) {} + if sourcecode:find("%s+main%s*%(.-%)") then + return true + end + + -- no main function + return false +end + + diff --git a/xmake/languages/c/load.lua b/xmake/languages/c/load.lua new file mode 100644 index 000000000..3c470e0eb --- /dev/null +++ b/xmake/languages/c/load.lua @@ -0,0 +1,120 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file load.lua +-- + +-- get apis +function _get_apis() + local apis = {} + apis.values = { + -- target.add_xxx + "target.add_links" + , "target.add_syslinks" + , "target.add_cflags" + , "target.add_cxflags" + , "target.add_ldflags" + , "target.add_arflags" + , "target.add_shflags" + , "target.add_defines" + , "target.add_undefines" + , "target.add_frameworks" + , "target.add_rpathdirs" -- @note do not translate path, it's usually an absolute path or contains $ORIGIN/@loader_path + , "target.add_forceincludes" + -- option.add_xxx + , "option.add_cincludes" + , "option.add_cfuncs" + , "option.add_ctypes" + , "option.add_links" + , "option.add_syslinks" + , "option.add_cflags" + , "option.add_cxflags" + , "option.add_ldflags" + , "option.add_arflags" + , "option.add_shflags" + , "option.add_defines" + , "option.add_undefines" + , "option.add_frameworks" + , "option.add_rpathdirs" + -- package.add_xxx + , "package.add_links" + , "package.add_syslinks" + , "package.add_cflags" + , "package.add_cxflags" + , "package.add_ldflags" + , "package.add_arflags" + , "package.add_shflags" + , "package.add_defines" + , "package.add_undefines" + , "package.add_frameworks" + , "package.add_rpathdirs" + , "package.add_linkdirs" + , "package.add_includedirs" --@note we need not uses paths for package, see https://github.com/xmake-io/xmake/issues/717 + , "package.add_sysincludedirs" + , "package.add_frameworkdirs" + -- toolchain.add_xxx + , "toolchain.add_links" + , "toolchain.add_syslinks" + , "toolchain.add_cflags" + , "toolchain.add_cxflags" + , "toolchain.add_ldflags" + , "toolchain.add_arflags" + , "toolchain.add_shflags" + , "toolchain.add_defines" + , "toolchain.add_undefines" + , "toolchain.add_frameworks" + , "toolchain.add_rpathdirs" + , "toolchain.add_linkdirs" + , "toolchain.add_includedirs" + , "toolchain.add_sysincludedirs" + , "toolchain.add_frameworkdirs" + } + apis.groups = { + -- target.add_xxx + "target.add_linkorders" + , "target.add_linkgroups" + -- package.add_xxx + , "package.add_linkorders" + , "package.add_linkgroups" + } + apis.paths = { + -- target.set_xxx + "target.set_pcheader" + -- target.add_xxx + , "target.add_headerfiles" + , "target.add_linkdirs" + , "target.add_includedirs" + , "target.add_sysincludedirs" + , "target.add_frameworkdirs" + -- option.add_xxx + , "option.add_linkdirs" + , "option.add_includedirs" + , "option.add_sysincludedirs" + , "option.add_frameworkdirs" + } + apis.dictionary = { + -- option.add_xxx + "option.add_csnippets" + } + return apis +end + +function main() + return {apis = _get_apis()} +end + + diff --git a/xmake/languages/c/xmake.lua b/xmake/languages/c/xmake.lua new file mode 100644 index 000000000..4e1a0041b --- /dev/null +++ b/xmake/languages/c/xmake.lua @@ -0,0 +1,152 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file xmake.lua +-- + +language("c") + add_rules("c") + set_sourcekinds {cc = ".c"} + set_sourceflags {cc = {"cflags", "cxflags"}} + set_targetkinds {binary = "ld", static = "ar", shared = "sh"} + set_targetflags {binary = "ldflags", static = "arflags", shared = "shflags"} + set_langkinds {c = "cc"} + set_mixingkinds("cc", "cxx", "as", "mrc") + + on_load("load") + on_check_main("check_main") + + set_nameflags { + object = { + "config.includedirs" + , "config.frameworkdirs" + , "config.frameworks" + , "target.symbols" + , "target.warnings" + , "target.fpmodels" + , "target.optimize:check" + , "target.vectorexts:check" + , "target.languages" + , "target.runtimes" + , "target.includedirs" + , "target.defines" + , "target.undefines" + , "target.frameworkdirs" + , "target.frameworks" + , "target.exceptions" + , "target.encodings" + , "target.pcheader" + , "target.forceincludes" + , "toolchain.includedirs" + , "toolchain.defines" + , "toolchain.undefines" + , "toolchain.frameworkdirs" + , "toolchain.frameworks" + , "target.sysincludedirs" + , "toolchain.sysincludedirs" + } + , binary = { + "config.linkdirs" + , "config.frameworkdirs" + , "target.linkdirs" + , "target.frameworkdirs" + , "target.rpathdirs" + , "target.strip" + , "target.symbols" + , "target.optimize:check" + , "target.runtimes" + , "toolchain.linkdirs" + , "toolchain.rpathdirs" + , "toolchain.frameworkdirs" + , "config.links" + , "target.linkgroups" -- we must move it before target.links, because we need sort correct order for package and its deps + , "target.links" + , "toolchain.links" + , "config.frameworks" + , "target.frameworks" + , "toolchain.frameworks" + , "config.syslinks" + , "target.syslinks" + , "toolchain.syslinks" + } + , shared = { + "config.linkdirs" + , "config.frameworkdirs" + , "target.linkdirs" + , "target.frameworkdirs" + , "target.rpathdirs" + , "target.strip" + , "target.symbols" + , "target.optimize:check" + , "target.runtimes" + , "toolchain.linkdirs" + , "toolchain.rpathdirs" + , "toolchain.frameworkdirs" + , "config.links" + , "target.links" + , "target.linkgroups" + , "toolchain.links" + , "config.frameworks" + , "target.frameworks" + , "toolchain.frameworks" + , "config.syslinks" + , "target.syslinks" + , "toolchain.syslinks" + } + , static = { + "target.strip" + , "target.symbols" + } + } + + set_menu { + config = + { + {category = "Cross Complation Configuration/Compiler Configuration" } + , {nil, "cc", "kv", nil, "The C Compiler" } + , {nil, "cpp", "kv", nil, "The C/C++ Preprocessor" } + + , {category = "Cross Complation Configuration/Linker Configuration" } + , {nil, "ld", "kv", nil, "The Linker" } + , {nil, "ar", "kv", nil, "The Static Library Linker" } + , {nil, "sh", "kv", nil, "The Shared Library Linker" } + , {nil, "ranlib", "kv", nil, "The Static Library Index Generator" } + + , {category = "Cross Complation Configuration/Compiler Flags Configuration" } + , {nil, "cflags", "kv", nil, "The C Compiler Flags" } + , {nil, "cxflags", "kv", nil, "The C/C++ compiler Flags" } + + , {category = "Cross Complation Configuration/Linker Flags Configuration" } + , {nil, "ldflags", "kv", nil, "The Binary Linker Flags" } + , {nil, "arflags", "kv", nil, "The Static Library Linker Flags" } + , {nil, "shflags", "kv", nil, "The Shared Library Linker Flags" } + + , {category = "Cross Complation Configuration/Builtin Flags Configuration" } + , {nil, "links", "kv", nil, "The Link Libraries" } + , {nil, "syslinks", "kv", nil, "The System Link Libraries" } + , {nil, "linkdirs", "kv", nil, "The Link Search Directories" } + , {nil, "includedirs", "kv", nil, "The Include Search Directories" } + , {nil, "frameworks", "kv", nil, "The Frameworks" } + , {nil, "frameworkdirs", "kv", nil, "The Frameworks Search Directories" } + } + } + + + + + + diff --git a/xmake/modules/core/tools/cl.lua b/xmake/modules/core/tools/cl.lua index 2d60f2a1b..18f6ee868 100644 --- a/xmake/modules/core/tools/cl.lua +++ b/xmake/modules/core/tools/cl.lua @@ -184,10 +184,16 @@ function nf_optimize(self, level) return maps[level] end --- make vs runtime flag -function nf_runtime(self, vs_runtime) - if vs_runtime then - return "-" .. vs_runtime +-- make the runtime flag +function nf_runtime(self, runtime) + if runtime then + local maps = { + MT = "-MT", + MD = "-MD", + MTd = "-MTd", + MDd = "-MDd" + } + return maps[runtime] end end diff --git a/xmake/modules/core/tools/clang.lua b/xmake/modules/core/tools/clang.lua index 28a00d84f..313728894 100644 --- a/xmake/modules/core/tools/clang.lua +++ b/xmake/modules/core/tools/clang.lua @@ -178,18 +178,33 @@ function _has_ms_runtime_lib(self) return has_ms_runtime_lib end --- make vs runtime flag +-- has -static-libstdc++? +function _has_static_libstdcxx(self) + local has_static_libstdcxx = _g._HAS_STATIC_LIBSTDCXX + if has_static_libstdcxx == nil then + if self:has_flags("-static-libstdc++ -Werror", "ldflags", {flagskey = "clang_static_libstdcxx"}) then + has_static_libstdcxx = true + end + has_static_libstdcxx = has_static_libstdcxx or false + _g._HAS_STATIC_LIBSTDCXX = has_static_libstdcxx + end + return has_static_libstdcxx +end + + +-- make the runtime flag -- @see https://github.com/xmake-io/xmake/issues/3546 -function nf_runtime(self, vs_runtime) - if self:is_plat("windows") and vs_runtime then +function nf_runtime(self, runtime, opt) + opt = opt or {} + local kind = self:kind() + if self:is_plat("windows") and runtime then if not _has_ms_runtime_lib(self) then - if vs_runtime:startswith("MD") then - wprint("%s runtime is not available for the current Clang compiler.", vs_runtime) + if runtime:startswith("MD") then + wprint("%s runtime is not available for the current Clang compiler.", runtime) end return end local maps - local kind = self:kind() if language.sourcekinds()[kind] then maps = { MT = "-fms-runtime-lib=static", @@ -205,7 +220,32 @@ function nf_runtime(self, vs_runtime) MDd = "-nostdlib" } end - return maps and maps[vs_runtime] + return maps and maps[runtime] + elseif not self:is_plat("android") then -- we will set runtimes in android ndk toolchain + local maps + if kind == "cxx" then + maps = { + ["c++_static"] = "-stdlib=libc++", + ["c++_shared"] = "-stdlib=libc++", + ["stdc++_static"] = "-stdlib=libstdc++", + ["stdc++_shared"] = "-stdlib=libstdc++", + } + elseif kind == "ld" or kind == "sh" then + local target = opt.target + if target and target.sourcekinds and table.contains(table.wrap(target:sourcekinds()), "cxx") then + maps = { + ["c++_static"] = "-stdlib=libc++", + ["c++_shared"] = "-stdlib=libc++", + ["stdc++_static"] = "-stdlib=libstdc++", + ["stdc++_shared"] = "-stdlib=libstdc++", + } + if runtime:endswith("_static") and _has_static_libstdcxx(self) then + maps["c++_static"] = table.join(maps["c++_static"], "-static-libstdc++") + maps["stdc++_static"] = table.join(maps["stdc++_static"], "-static-libstdc++") + end + end + end + return maps and maps[runtime] end end diff --git a/xmake/modules/core/tools/link.lua b/xmake/modules/core/tools/link.lua index 9c53c2e28..a144d515e 100644 --- a/xmake/modules/core/tools/link.lua +++ b/xmake/modules/core/tools/link.lua @@ -113,9 +113,9 @@ function nf_syslink(self, lib) return nf_link(self, lib) end --- make vs runtime flag -function nf_runtime(self, vs_runtime) - if vs_runtime and vs_runtime:startswith("MT") then +-- make the runtime flag +function nf_runtime(self, runtime) + if runtime and runtime:startswith("MT") then return "-nodefaultlib:msvcrt.lib" end end diff --git a/xmake/modules/core/tools/nvcc.lua b/xmake/modules/core/tools/nvcc.lua index 604fbe505..127f51656 100644 --- a/xmake/modules/core/tools/nvcc.lua +++ b/xmake/modules/core/tools/nvcc.lua @@ -171,9 +171,15 @@ function nf_optimize(self, level) end -- make vs runtime flag -function nf_runtime(self, vs_runtime) - if self:is_plat("windows") and vs_runtime then - return '-Xcompiler "-' .. vs_runtime .. '"' +function nf_runtime(self, runtime) + if self:is_plat("windows") and runtime then + local maps = { + MT = '-Xcompiler "-MT"', + MD = '-Xcompiler "-MD"', + MTd = '-Xcompiler "-MTd"', + MDd = '-Xcompiler "-MDd"' + } + return maps[runtime] end end diff --git a/xmake/modules/package/manager/conan/v1/install_package.lua b/xmake/modules/package/manager/conan/v1/install_package.lua index e443e585b..3475a21b3 100644 --- a/xmake/modules/package/manager/conan/v1/install_package.lua +++ b/xmake/modules/package/manager/conan/v1/install_package.lua @@ -211,9 +211,9 @@ function main(conan, name, opt) table.insert(argv, "compiler=Visual Studio") table.insert(argv, "-s") table.insert(argv, "compiler.version=" .. assert(vsvers[vs], "unknown msvc version!")) - if configs.vs_runtime then + if configs.runtimes then table.insert(argv, "-s") - table.insert(argv, "compiler.runtime=" .. configs.vs_runtime) + table.insert(argv, "compiler.runtime=" .. configs.runtimes) end elseif opt.plat == "iphoneos" then local target_minver = nil diff --git a/xmake/modules/package/manager/conan/v2/install_package.lua b/xmake/modules/package/manager/conan/v2/install_package.lua index eb4299d83..5d2bdd384 100644 --- a/xmake/modules/package/manager/conan/v2/install_package.lua +++ b/xmake/modules/package/manager/conan/v2/install_package.lua @@ -167,6 +167,7 @@ function _conan_generate_compiler_profile(profile, configs, opt) local conf local plat = opt.plat local arch = opt.arch + local runtimes = configs.runtimes if plat == "windows" then -- https://github.com/conan-io/conan/blob/353c63b16c31c90d370305b5cbb5dc175cf8a443/conan/tools/microsoft/visual.py#L13 local vsvers = {["2022"] = "193", @@ -182,10 +183,9 @@ function _conan_generate_compiler_profile(profile, configs, opt) if tonumber(vs) >= 2015 then profile:print("compiler.cppstd=14") end - local vs_runtime = configs.vs_runtime - if vs_runtime then - profile:print("compiler.runtime=" .. (vs_runtime:startswith("MD") and "dynamic" or "static")) - profile:print("compiler.runtime_type=" .. (vs_runtime:endswith("d") and "Debug" or "Release")) + if runtimes then + profile:print("compiler.runtime=" .. (runtimes:startswith("MD") and "dynamic" or "static")) + profile:print("compiler.runtime_type=" .. (runtimes:endswith("d") and "Debug" or "Release")) end elseif plat == "iphoneos" then local target_minver = nil @@ -212,9 +212,8 @@ function _conan_generate_compiler_profile(profile, configs, opt) if ndk_sdkver then profile:print("os.api_level=" .. ndk_sdkver) end - local ndk_cxxstl = config.get("ndk_cxxstl") - if ndk_cxxstl then - profile:print("compiler.libcxx=" .. ndk_cxxstl) + if runtimes then + profile:print("compiler.libcxx=" .. runtimes) end local program, toolname = ndk:tool("cc") local version = _conan_get_compiler_version(toolname, program) @@ -229,11 +228,13 @@ function _conan_generate_compiler_profile(profile, configs, opt) if toolname == "gcc" or toolname == "clang" then profile:print("compiler=" .. toolname) profile:print("compiler.cppstd=gnu17") - if toolname == "clang" then - profile:print("compiler.libcxx=libc++") - else - profile:print("compiler.libcxx=libstdc++11") + local libcxx = "libstdc++11" + if runtimes and table.contains(table.wrap(runtimes), "c++_static", "c++_shared") then + libcxx = "libc++" + elseif not runtimes and toolname == "clang" then + libcxx = "libc++" end + profile:print("compiler.libcxx=" .. libcxx) local version = _conan_get_compiler_version(toolname, program) if version then profile:print("compiler.version=" .. version) diff --git a/xmake/modules/package/manager/vcpkg/configurations.lua b/xmake/modules/package/manager/vcpkg/configurations.lua index 997f8fa35..cb81e560a 100644 --- a/xmake/modules/package/manager/vcpkg/configurations.lua +++ b/xmake/modules/package/manager/vcpkg/configurations.lua @@ -52,7 +52,7 @@ function triplet(configs, plat, arch) local triplet = arch .. "-" .. plat if plat == "windows" and configs.shared ~= true then triplet = triplet .. "-static" - if configs.vs_runtime and configs.vs_runtime:startswith("MD") then + if configs.runtimes and configs.runtimes:startswith("MD") then triplet = triplet .. "-md" end elseif plat == "mingw" then diff --git a/xmake/modules/package/tools/cmake.lua b/xmake/modules/package/tools/cmake.lua index ecee111d8..525507b3c 100644 --- a/xmake/modules/package/tools/cmake.lua +++ b/xmake/modules/package/tools/cmake.lua @@ -352,24 +352,24 @@ function _get_configs_for_windows(package, configs, opt) -- we maybe need patch `cmake_policy(SET CMP0091 NEW)` to enable this argument for some packages -- @see https://cmake.org/cmake/help/latest/policy/CMP0091.html#policy:CMP0091 -- https://github.com/xmake-io/xmake-repo/pull/303 - local vs_runtime = package:config("vs_runtime") - if vs_runtime == "MT" then + if package:has_runtime("MT") then table.insert(configs, "-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded") - elseif vs_runtime == "MTd" then + elseif package:has_runtime("MTd") then table.insert(configs, "-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDebug") - elseif vs_runtime == "MD" then + elseif package:has_runtime("MD") then table.insert(configs, "-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDLL") - elseif vs_runtime == "MDd" then + elseif package:has_runtime("MDd") then table.insert(configs, "-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDebugDLL") end - if vs_runtime then + local runtimes = package:runtimes() + if runtimes then -- CMake default MSVC flags as of 3.21.2 local default_debug_flags = "/Zi /Ob0 /Od /RTC1" local default_release_flags = "/O2 /Ob2 /DNDEBUG" - table.insert(configs, '-DCMAKE_CXX_FLAGS_DEBUG=/' .. vs_runtime .. ' ' .. default_debug_flags) - table.insert(configs, '-DCMAKE_CXX_FLAGS_RELEASE=/' .. vs_runtime .. ' ' .. default_release_flags) - table.insert(configs, '-DCMAKE_C_FLAGS_DEBUG=/' .. vs_runtime .. ' ' .. default_debug_flags) - table.insert(configs, '-DCMAKE_C_FLAGS_RELEASE=/' .. vs_runtime .. ' ' .. default_release_flags) + table.insert(configs, '-DCMAKE_CXX_FLAGS_DEBUG=/' .. runtimes .. ' ' .. default_debug_flags) + table.insert(configs, '-DCMAKE_CXX_FLAGS_RELEASE=/' .. runtimes .. ' ' .. default_release_flags) + table.insert(configs, '-DCMAKE_C_FLAGS_DEBUG=/' .. runtimes .. ' ' .. default_debug_flags) + table.insert(configs, '-DCMAKE_C_FLAGS_RELEASE=/' .. runtimes .. ' ' .. default_release_flags) end if not opt._configs_str:find("CMAKE_COMPILE_PDB_OUTPUT_DIRECTORY") then table.insert(configs, "-DCMAKE_COMPILE_PDB_OUTPUT_DIRECTORY=pdb") diff --git a/xmake/modules/package/tools/meson.lua b/xmake/modules/package/tools/meson.lua index 56fc35bc4..e4d740d16 100644 --- a/xmake/modules/package/tools/meson.lua +++ b/xmake/modules/package/tools/meson.lua @@ -316,10 +316,10 @@ function _get_configs(package, configs, opt) table.insert(configs, "-Db_sanitize=address") end - -- add vs_runtime flags - local vs_runtime = package:config("vs_runtime") - if package:is_plat("windows") and vs_runtime then - table.insert(configs, "-Db_vscrt=" .. vs_runtime:lower()) + -- add runtimes flags + local runtimes = package:runtimes() + if package:is_plat("windows") and runtimes then + table.insert(configs, "-Db_vscrt=" .. runtimes:lower()) end -- add cross file diff --git a/xmake/modules/package/tools/xmake.lua b/xmake/modules/package/tools/xmake.lua index 379a46d19..27c0bd872 100644 --- a/xmake/modules/package/tools/xmake.lua +++ b/xmake/modules/package/tools/xmake.lua @@ -77,10 +77,10 @@ function _get_configs_for_windows(package, configs, opt) table.insert(configs, "--" .. name .. "=" .. tostring(value)) end end - -- pass vs_runtime from package configs - local vs_runtime = package:config("vs_runtime") - if vs_runtime then - table.insert(configs, "--vs_runtime=" .. vs_runtime) + -- pass runtimes from package configs + local runtimes = package:config("runtimes") + if runtimes then + table.insert(configs, "--runtimes=" .. runtimes) end _get_configs_for_qt(package, configs, opt) _get_configs_for_vcpkg(package, configs, opt) diff --git a/xmake/modules/private/action/require/impl/package.lua b/xmake/modules/private/action/require/impl/package.lua index 8bbeeee45..5d352ee01 100644 --- a/xmake/modules/private/action/require/impl/package.lua +++ b/xmake/modules/private/action/require/impl/package.lua @@ -28,6 +28,7 @@ import("core.cache.memcache") import("core.project.project") import("core.project.config") import("core.tool.toolchain") +import("core.platform.platform") import("core.package.package", {alias = "core_package"}) import("devel.git") import("private.action.require.impl.repository") @@ -152,6 +153,13 @@ function _load_require(require_str, requires_extra, parentinfo) require_build_configs.debug = true end + -- vs_runtime is deprecated, we should use runtimes + if require_build_configs and require_build_configs.vs_runtime then + require_build_configs.runtimes = require_build_configs.vs_runtime + require_build_configs.vs_runtime = nil + wprint("add_requires(%s): vs_runtime is deprecated, please use runtimes!", require_str) + end + -- require packge in the current host platform if require_extra.host then if is_subhost(core_package.targetplat()) and os.subarch() == core_package.targetarch() then @@ -346,6 +354,25 @@ function _add_package_configurations(package) if package:extraconf("configs", "asan", "default") == nil then package:add("configs", "asan", {builtin = true, description = "Enable the address sanitizer.", type = "boolean"}) end + if package:extraconf("configs", "runtimes", "default") == nil then + local values = {"MT", "MTd", "MD", "MDd", + "c++_static", "c++_shared", "stdc++_static", "stdc++_shared"} + package:add("configs", "runtimes", {builtin = true, description = "Set the compiler runtimes.", type = "string", values = values, restrict = function (value) + local values_set = hashset.from(values) + if type(value) ~= "string" then + return false + end + if value then + for _, item in ipairs(value:split(",", {plain = true})) do + if not values_set:has(item) then + return false + end + end + end + return true + end}) + end + -- deprecated, please use runtimes if package:extraconf("configs", "vs_runtime", "default") == nil then package:add("configs", "vs_runtime", {builtin = true, description = "Set vs compiler runtime.", values = {"MT", "MTd", "MD", "MDd"}}) end @@ -438,7 +465,11 @@ function _check_package_configurations(package) if config_type ~= nil and type(value) ~= config_type then raise("package(%s %s): invalid type(%s) for config(%s), need type(%s)!", package:displayname(), package:version_str(), type(value), name, config_type) end - if conf.values then + if conf.restrict then + if not conf.restrict(value) then + raise("package(%s %s): invalid value(%s) for config(%s)!", package:displayname(), package:version_str(), string.serialize(value, {indent = false}), name) + end + elseif conf.values then local found = false for _, config_value in ipairs(conf.values) do if tostring(value) == tostring(config_value) then @@ -450,11 +481,6 @@ function _check_package_configurations(package) raise("package(%s %s): invalid value(%s) for config(%s), please run `xmake require --info %s` to get all valid values!", package:displayname(), package:version_str(), value, name, package:name()) end end - if conf.restrict then - if not conf.restrict(value) then - raise("package(%s %s): invalid value(%s) for config(%s)!", package:displayname(), package:version_str(), value, name) - end - end else raise("package(%s %s): invalid config(%s), please run `xmake require --info %s` to get all configurations!", package:displayname(), package:version_str(), name, package:name()) end @@ -513,9 +539,12 @@ function _init_requireinfo(requireinfo, package, opt) requireinfo.configs.toolchains = requireinfo.configs.toolchains or get_config("toolchain") end end - requireinfo.configs.vs_runtime = requireinfo.configs.vs_runtime or project.get("target.runtimes") + requireinfo.configs.runtimes = requireinfo.configs.runtimes or project.get("target.runtimes") if project.policy("package.inherit_external_configs") then - requireinfo.configs.vs_runtime = requireinfo.configs.vs_runtime or get_config("vs_runtime") + requireinfo.configs.runtimes = requireinfo.configs.runtimes or get_config("runtimes") or get_config("vs_runtime") + end + if type(requireinfo.configs.runtimes) == "table" then + requireinfo.configs.runtimes = table.concat(requireinfo.configs.runtimes, ",") end if requireinfo.configs.lto == nil then requireinfo.configs.lto = project.policy("build.optimization.lto") @@ -527,7 +556,7 @@ function _init_requireinfo(requireinfo, package, opt) -- but we will ignore some configs for buildhash in the headeronly and host/binary package -- @note on_test still need these configs, @see https://github.com/xmake-io/xmake/issues/4124 if package:is_headeronly() or (package:is_binary() and not package:is_cross()) then - requireinfo.ignored_configs_for_buildhash = {"vs_runtime", "toolchains", "lto", "asan", "pic"} + requireinfo.ignored_configs_for_buildhash = {"runtimes", "toolchains", "lto", "asan", "pic"} end end @@ -542,15 +571,28 @@ function _finish_requireinfo(requireinfo, package) end requireinfo.configs = requireinfo.configs or {} if not package:is_headeronly() then - if requireinfo.configs.vs_runtime == nil and package:is_plat("windows") then - requireinfo.configs.vs_runtime = "MT" + if requireinfo.configs.runtimes == nil and package:is_plat("windows") then + requireinfo.configs.runtimes = "MT" end end -- we need to ensure readonly configs for _, name in ipairs(table.keys(requireinfo.configs)) do local current = requireinfo.configs[name] local default = package:extraconf("configs", name, "default") - if package:extraconf("configs", name, "readonly") and current ~= default then + local readonly = package:extraconf("configs", name, "readonly") + if name == "runtimes" then + -- vs_runtime is deprecated, but we need also support it now. + if default == nil then + default = package:extraconf("configs", "vs_runtime", "default") + end + if readonly == nil then + readonly = package:extraconf("configs", "vs_runtime", "readonly") + end + if default ~= nil or readonly ~= nil then + wprint("please use add_configs(\"runtimes\") instead of add_configs(\"vs_runtime\").") + end + end + if readonly and current ~= default then wprint("configs.%s is readonly in package(%s), it's always %s", name, package:name(), default) -- package:config() will use default value after loading package requireinfo.configs[name] = nil @@ -568,9 +610,9 @@ end -- merge requireinfo from `add_requireconfs()` -- --- add_requireconfs("*", {system = false, configs = {vs_runtime = "MD"}}) --- add_requireconfs("lib*", {system = false, configs = {vs_runtime = "MD"}}) --- add_requireconfs("libwebp", {system = false, configs = {vs_runtime = "MD"}}) +-- add_requireconfs("*", {system = false, configs = {runtimes = "MD"}}) +-- add_requireconfs("lib*", {system = false, configs = {runtimes = "MD"}}) +-- add_requireconfs("libwebp", {system = false, configs = {runtimes = "MD"}}) -- add_requireconfs("libpng.zlib", {system = false, override = true, configs = {cxflags = "-DTEST1"}, version = "1.2.10"}) -- add_requireconfs("libtiff.*", {system = false, configs = {cxflags = "-DTEST2"}}) -- add_requireconfs("libwebp.**|cmake|autoconf", {system = false, configs = {cxflags = "-DTEST3"}}) -- recursive deps @@ -660,15 +702,15 @@ function _get_packagelock_key(requireinfo) end -- inherit some builtin configs of parent package if these config values are not default value --- e.g. add_requires("libpng", {configs = {vs_runtime = "MD", pic = false}}) +-- e.g. add_requires("libpng", {configs = {runtimes = "MD", pic = false}}) -- function _inherit_parent_configs(requireinfo, package, parentinfo) if package:is_library() then local requireinfo_configs = requireinfo.configs or {} local parentinfo_configs = parentinfo.configs or {} if not requireinfo_configs.shared then - if requireinfo_configs.vs_runtime == nil then - requireinfo_configs.vs_runtime = parentinfo_configs.vs_runtime + if requireinfo_configs.runtimes == nil then + requireinfo_configs.runtimes = parentinfo_configs.runtimes end if requireinfo_configs.pic == nil then requireinfo_configs.pic = parentinfo_configs.pic @@ -681,7 +723,7 @@ function _inherit_parent_configs(requireinfo, package, parentinfo) requireinfo.arch = parentinfo.arch end requireinfo_configs.toolchains = requireinfo_configs.toolchains or parentinfo_configs.toolchains - requireinfo_configs.vs_runtime = requireinfo_configs.vs_runtime or parentinfo_configs.vs_runtime + requireinfo_configs.runtimes = requireinfo_configs.runtimes or parentinfo_configs.runtimes requireinfo_configs.lto = requireinfo_configs.lto or parentinfo_configs.lto requireinfo_configs.asan = requireinfo_configs.asan or parentinfo_configs.asan requireinfo.configs = requireinfo_configs @@ -764,6 +806,35 @@ function _select_artifacts(package, artifacts_manifest) end end +-- select package runtimes +function _select_package_runtimes(package) + local runtimes = package:config("runtimes") + if runtimes then + local runtimes_supported = hashset.new() + local toolchains = package:toolchains() or platform.load(package:plat(), package:arch()):toolchains() + if toolchains then + for _, toolchain_inst in ipairs(toolchains) do + if toolchain_inst:is_standalone() and toolchain_inst:get("runtimes") then + for _, runtime in ipairs(table.wrap(toolchain_inst:get("runtimes"))) do + runtimes_supported:insert(runtime) + end + end + end + end + local runtimes_current = {} + for _, runtime in ipairs(table.wrap(runtimes:split(",", {plain = true}))) do + if runtimes_supported:has(runtime) then + table.insert(runtimes_current, runtime) + end + end + -- we need update runtimes for buildhash, configs ... + local requireinfo = package:requireinfo() + if requireinfo and requireinfo.configs then + requireinfo.configs.runtimes = #runtimes_current > 0 and table.concat(runtimes_current, ",") or nil + end + end +end + -- load required packages function _load_package(packagename, requireinfo, opt) @@ -838,7 +909,7 @@ function _load_package(packagename, requireinfo, opt) -- merge requireinfo from `add_requireconfs()` _merge_requireinfo(requireinfo, opt.requirepath) - -- inherit some builtin configs of parent package, e.g. vs_runtime, pic + -- inherit some builtin configs of parent package, e.g. runtimes, pic if opt.parentinfo then _inherit_parent_configs(requireinfo, package, opt.parentinfo) end @@ -897,6 +968,13 @@ function _load_package(packagename, requireinfo, opt) -- check package configurations _check_package_configurations(package) + -- we need to select package runtimes before computing buildhash + -- @see https://github.com/xmake-io/xmake/pull/4630#issuecomment-1910216561 + _select_package_runtimes(package) + + -- pre-compute the package buildhash + package:_compute_buildhash() + -- save artifacts info, we need to add it at last before buildhash need depend on package configurations -- it will switch to install precompiled binary package from xmake-mirror/build-artifacts if from_repo and not option.get("build") and not requireinfo.build then diff --git a/xmake/modules/private/action/require/impl/remove_packages.lua b/xmake/modules/private/action/require/impl/remove_packages.lua index 1a5e99f83..3dcfeecf9 100644 --- a/xmake/modules/private/action/require/impl/remove_packages.lua +++ b/xmake/modules/private/action/require/impl/remove_packages.lua @@ -33,7 +33,7 @@ function _get_package_configs_str(manifest_file) if type(v) == "boolean" then table.insert(configs, k .. ":" .. (v and "y" or "n")) else - table.insert(configs, k .. ":" .. v) + table.insert(configs, k .. ":" .. string.serialize(v, {strip = true, indent = false})) end end local configs_str = #configs > 0 and "[" .. table.concat(configs, ", ") .. "]" or "" diff --git a/xmake/modules/private/action/trybuild/xrepo.lua b/xmake/modules/private/action/trybuild/xrepo.lua index cfb63e553..31d866d58 100644 --- a/xmake/modules/private/action/trybuild/xrepo.lua +++ b/xmake/modules/private/action/trybuild/xrepo.lua @@ -111,9 +111,10 @@ function _get_common_configs(argv) if config.get("toolchain") then table.insert(argv, "--toolchain=" .. config.get("toolchain")) end - if config.get("vs_runtime") then + local runtimes = config.get("runtimes") or config.get("vs_runtime") + if runtimes then table.insert(argv, "-f") - table.insert(argv, "vs_runtime='" .. config.get("vs_runtime") .. "'") + table.insert(argv, "runtimes='" .. runtimes .. "'") end end diff --git a/xmake/modules/private/xrepo/action/env.lua b/xmake/modules/private/xrepo/action/env.lua index 5a9347922..b2e421f24 100644 --- a/xmake/modules/private/xrepo/action/env.lua +++ b/xmake/modules/private/xrepo/action/env.lua @@ -49,7 +49,7 @@ function menu_options() {nil, "show", "k", nil, "Only show environment information." }, {'f', "configs", "kv", nil, "Set the given extra package configs.", "e.g.", - " - xrepo env -f \"vs_runtime='MD'\" zlib cmake ..", + " - xrepo env -f \"runtimes='MD'\" zlib cmake ..", " - xrepo env -f \"regex=true,thread=true\" \"zlib,boost\" cmake .."}, {nil, "add", "k", nil, "Add global environment config.", "e.g.", diff --git a/xmake/modules/private/xrepo/action/export.lua b/xmake/modules/private/xrepo/action/export.lua index 551d978a3..4c718bcb0 100644 --- a/xmake/modules/private/xrepo/action/export.lua +++ b/xmake/modules/private/xrepo/action/export.lua @@ -39,7 +39,7 @@ function menu_options() values = {"release", "debug"} }, {'f', "configs", "kv", nil, "Set the given extra package configs.", "e.g.", - " - xrepo export -f \"vs_runtime='MD'\" zlib", + " - xrepo export -f \"runtimes='MD'\" zlib", " - xrepo export -f \"regex=true,thread=true\" boost"}, {}, {nil, "includes", "kv", nil, "Includes extra lua configuration files."}, diff --git a/xmake/modules/private/xrepo/action/fetch.lua b/xmake/modules/private/xrepo/action/fetch.lua index b54294a68..4455d21e7 100644 --- a/xmake/modules/private/xrepo/action/fetch.lua +++ b/xmake/modules/private/xrepo/action/fetch.lua @@ -38,7 +38,7 @@ function menu_options() values = {"release", "debug"} }, {'f', "configs", "kv", nil, "Set the given extra package configs.", "e.g.", - " - xrepo fetch --configs=\"vs_runtime='MD'\" zlib", + " - xrepo fetch --configs=\"runtimes='MD'\" zlib", " - xrepo fetch --configs=\"regex=true,thread=true\" boost"}, {nil, "system", "k", "false", "Only fetch package on current system."}, {}, diff --git a/xmake/modules/private/xrepo/action/import.lua b/xmake/modules/private/xrepo/action/import.lua index 8c32e2c0f..7ad0a1759 100644 --- a/xmake/modules/private/xrepo/action/import.lua +++ b/xmake/modules/private/xrepo/action/import.lua @@ -39,7 +39,7 @@ function menu_options() values = {"release", "debug"} }, {'f', "configs", "kv", nil, "Set the given extra package configs.", "e.g.", - " - xrepo import -f \"vs_runtime='MD'\" zlib", + " - xrepo import -f \"runtimes='MD'\" zlib", " - xrepo import -f \"regex=true,thread=true\" boost"}, {}, {'i', "packagedir", "kv", "packages","Set the imported packages directory."}, diff --git a/xmake/modules/private/xrepo/action/info.lua b/xmake/modules/private/xrepo/action/info.lua index 3bc547b94..e89ac80af 100644 --- a/xmake/modules/private/xrepo/action/info.lua +++ b/xmake/modules/private/xrepo/action/info.lua @@ -38,7 +38,7 @@ function menu_options() values = {"release", "debug"} }, {'f', "configs", "kv", nil, "Set the given extra package configs.", "e.g.", - " - xrepo fetch --configs=\"vs_runtime='MD'\" zlib", + " - xrepo fetch --configs=\"runtimes='MD'\" zlib", " - xrepo fetch --configs=\"regex=true,thread=true\" boost"}, {}, {nil, "packages", "vs", nil, "The packages list.", diff --git a/xmake/modules/private/xrepo/action/install.lua b/xmake/modules/private/xrepo/action/install.lua index dfcaadf80..81420f51f 100644 --- a/xmake/modules/private/xrepo/action/install.lua +++ b/xmake/modules/private/xrepo/action/install.lua @@ -38,7 +38,7 @@ function menu_options() values = {"release", "debug"} }, {'f', "configs", "kv", nil, "Set the given extra package configs.", "e.g.", - " - xrepo install -f \"vs_runtime='MD'\" zlib", + " - xrepo install -f \"runtimes='MD'\" zlib", " - xrepo install -f \"regex=true,thread=true\" boost"}, {'j', "jobs", "kv", tostring(os.default_njob()), "Set the number of parallel compilation jobs."}, diff --git a/xmake/modules/private/xrepo/action/remove.lua b/xmake/modules/private/xrepo/action/remove.lua index dd850deb6..38be707fb 100644 --- a/xmake/modules/private/xrepo/action/remove.lua +++ b/xmake/modules/private/xrepo/action/remove.lua @@ -39,7 +39,7 @@ function menu_options() values = {"release", "debug"} }, {'f', "configs", "kv", nil, "Set the given extra package configs.", "e.g.", - " - xrepo remove -f \"vs_runtime='MD'\" zlib", + " - xrepo remove -f \"runtimes='MD'\" zlib", " - xrepo remove -f \"regex=true,thread=true\" boost"}, {nil, "toolchain", "kv", nil, "Set the toolchain name." }, {}, diff --git a/xmake/platforms/android/xmake.lua b/xmake/platforms/android/xmake.lua index 48f1463e1..4199dbcc6 100644 --- a/xmake/platforms/android/xmake.lua +++ b/xmake/platforms/android/xmake.lua @@ -47,7 +47,7 @@ platform("android") , {nil, "android_sdk", "kv", nil, "The Android SDK Directory" } , {nil, "build_toolver", "kv", nil, "The Build Tool Version of Android SDK" } , {nil, "ndk_stdcxx", "kv", true, "Use stdc++ library for NDK" } - , {nil, "ndk_cxxstl", "kv", nil, "The stdc++ stl library for NDK", + , {nil, "ndk_cxxstl", "kv", nil, "The stdc++ stl library for NDK, (deprecated, please use --runtimes)", " - c++_static", " - c++_shared", " - gnustl_static", diff --git a/xmake/platforms/windows/xmake.lua b/xmake/platforms/windows/xmake.lua index 84160b818..14ada8784 100644 --- a/xmake/platforms/windows/xmake.lua +++ b/xmake/platforms/windows/xmake.lua @@ -41,7 +41,7 @@ platform("windows") , " e.g. --vs_toolset=14.0" } , {nil, "vs_sdkver", "kv", nil, "The Windows SDK Version of Visual Studio" , " e.g. --vs_sdkver=10.0.15063.0" } - , {nil, "vs_runtime", "kv", nil, "The Runtime library of Visual Studio" + , {nil, "vs_runtime", "kv", nil, "The Runtime library of Visual Studio (deprecated, please use --runtimes)" , values = {"MT", "MTd", "MD", "MDd"} } , {category = "Cuda SDK Configuration" } , {nil, "cuda", "kv", "auto", "The Cuda SDK Directory" } diff --git a/xmake/plugins/project/cmake/cmakelists.lua b/xmake/plugins/project/cmake/cmakelists.lua index ddef34471..6fcf38313 100644 --- a/xmake/plugins/project/cmake/cmakelists.lua +++ b/xmake/plugins/project/cmake/cmakelists.lua @@ -753,31 +753,31 @@ function _add_target_symbols(cmakelists, target) end end --- add target vs runtime +-- add target runtimes -- -- https://github.com/xmake-io/xmake/issues/1661#issuecomment-927979489 -- https://cmake.org/cmake/help/latest/prop_tgt/MSVC_RUNTIME_LIBRARY.html -- -function _add_target_vs_runtime(cmakelists, target) +function _add_target_runtimes(cmakelists, target) local cmake_minver = _get_cmake_minver() if cmake_minver:ge("3.15.0") then - local vs_runtime = target:get("runtimes") + local runtimes = target:get("runtimes") cmakelists:print("if(MSVC)") - if vs_runtime then - if vs_runtime == "MT" then - vs_runtime = "MultiThreaded" - elseif vs_runtime == "MTd" then - vs_runtime = "MultiThreadedDebug" - elseif vs_runtime == "MD" then - vs_runtime = "MultiThreadedDLL" - elseif vs_runtime == "MDd" then - vs_runtime = "MultiThreadedDebugDLL" + if runtimes then + if runtimes == "MT" then + runtimes = "MultiThreaded" + elseif runtimes == "MTd" then + runtimes = "MultiThreadedDebug" + elseif runtimes == "MD" then + runtimes = "MultiThreadedDLL" + elseif runtimes == "MDd" then + runtimes = "MultiThreadedDebugDLL" end else - vs_runtime = "MultiThreaded$<$<CONFIG:Debug>:Debug>" + runtimes = "MultiThreaded$<$<CONFIG:Debug>:Debug>" end cmakelists:print(' set_property(TARGET %s PROPERTY', target:name()) - cmakelists:print(' MSVC_RUNTIME_LIBRARY "%s")', vs_runtime) + cmakelists:print(' MSVC_RUNTIME_LIBRARY "%s")', runtimes) cmakelists:print("endif()") end end @@ -1047,8 +1047,8 @@ function _add_target(cmakelists, target, outputdir) -- add target symbols _add_target_symbols(cmakelists, target) - -- add vs runtime for msvc - _add_target_vs_runtime(cmakelists, target) + -- add target runtimes + _add_target_runtimes(cmakelists, target) -- add target link libraries _add_target_link_libraries(cmakelists, target, outputdir) diff --git a/xmake/rules/c++/xmake.lua b/xmake/rules/c++/xmake.lua index 80d2e1417..dedb63ed5 100644 --- a/xmake/rules/c++/xmake.lua +++ b/xmake/rules/c++/xmake.lua @@ -46,10 +46,35 @@ rule("c++.build") end end) +rule("c") + + -- add build rules + add_deps("c.build") + + -- set compiler runtime, e.g. vs runtime + add_deps("utils.compiler.runtime") + + -- inherit links and linkdirs of all dependent targets by default + add_deps("utils.inherit.links") + + -- support `add_files("src/*.o")` and `add_files("src/*.a")` to merge object and archive files to target + add_deps("utils.merge.object", "utils.merge.archive") + + -- we attempt to extract symbols to the independent file and + -- strip self-target binary if `set_symbols("debug")` and `set_strip("all")` are enabled + add_deps("utils.symbols.extract") + + -- add platform rules + add_deps("platform.wasm") + add_deps("platform.windows") + + -- add linker rules + add_deps("linker") + rule("c++") -- add build rules - add_deps("c++.build", "c.build") + add_deps("c++.build") -- set compiler runtime, e.g. vs runtime add_deps("utils.compiler.runtime") diff --git a/xmake/rules/utils/compiler_runtime/xmake.lua b/xmake/rules/utils/compiler_runtime/xmake.lua index f8e3d39d0..1a50fddef 100644 --- a/xmake/rules/utils/compiler_runtime/xmake.lua +++ b/xmake/rules/utils/compiler_runtime/xmake.lua @@ -21,11 +21,24 @@ -- define rule: utils.compiler.runtime rule("utils.compiler.runtime") on_config(function (target) - - -- set vs runtime - local vs_runtime = get_config("vs_runtime") - if vs_runtime and target:is_plat("windows") and not target:get("runtimes") then - target:set("runtimes", vs_runtime) + local runtimes = get_config("runtimes") + if not runtimes and target:is_plat("windows") then + runtimes = get_config("vs_runtime") + if runtimes then + wprint("--vs_runtime=%s is deprecated, please use --runtimes=%s", runtimes, runtimes) + end + end + if not runtimes and target:is_plat("android") then + runtimes = get_config("ndk_cxxstl") + if runtimes then + wprint("--ndk_cxxstl=%s is deprecated, please use --runtimes=%s", runtimes, runtimes) + end + end + if runtimes and not target:get("runtimes") then + if type(runtimes) == "string" then + runtimes = runtimes:split(",", {plain = true}) + end + target:set("runtimes", runtimes) end end) diff --git a/xmake/toolchains/clang-cl/xmake.lua b/xmake/toolchains/clang-cl/xmake.lua index 79ca6dc6e..443eba0a2 100644 --- a/xmake/toolchains/clang-cl/xmake.lua +++ b/xmake/toolchains/clang-cl/xmake.lua @@ -30,16 +30,10 @@ -- @endcode -- toolchain("clang-cl") - - -- set homepage + set_kind("standalone") set_homepage("https://visualstudio.microsoft.com") set_description("LLVM Clang C/C++ Compiler compatible with msvc") + set_runtimes("MT", "MTd", "MD", "MDd") - -- mark as standalone toolchain - set_kind("standalone") - - -- check toolchain on_check("check") - - -- load toolchain on_load("load") diff --git a/xmake/toolchains/clang/xmake.lua b/xmake/toolchains/clang/xmake.lua index 0f9662cee..981cac82e 100644 --- a/xmake/toolchains/clang/xmake.lua +++ b/xmake/toolchains/clang/xmake.lua @@ -25,11 +25,10 @@ if version then suffix = suffix .. "-" .. version end toolchain("clang" .. suffix) - + set_kind("standalone") set_homepage("https://clang.llvm.org/") set_description("A C language family frontend for LLVM" .. (version and (" (" .. version .. ")") or "")) - - set_kind("standalone") + set_runtimes("c++_static", "c++_shared", "stdc++_static", "stdc++_shared") set_toolset("cc", "clang" .. suffix) set_toolset("cxx", "clang" .. suffix, "clang++" .. suffix) diff --git a/xmake/toolchains/gcc/xmake.lua b/xmake/toolchains/gcc/xmake.lua index 365341eda..9b01a80f5 100644 --- a/xmake/toolchains/gcc/xmake.lua +++ b/xmake/toolchains/gcc/xmake.lua @@ -25,15 +25,11 @@ if version then suffix = suffix .. "-" .. version end toolchain("gcc" .. suffix) - - -- set homepage + set_kind("standalone") set_homepage("https://gcc.gnu.org/") set_description("GNU Compiler Collection" .. (version and (" (" .. version .. ")") or "")) + set_runtimes("stdc++_static", "stdc++_shared") - -- mark as standalone toolchain - set_kind("standalone") - - -- set toolset set_toolset("cc", "gcc" .. suffix) set_toolset("cxx", "gcc" .. suffix, "g++" .. suffix) set_toolset("ld", "g++" .. suffix, "gcc" .. suffix) diff --git a/xmake/toolchains/llvm/xmake.lua b/xmake/toolchains/llvm/xmake.lua index 3525a2d6d..ef27a2073 100644 --- a/xmake/toolchains/llvm/xmake.lua +++ b/xmake/toolchains/llvm/xmake.lua @@ -18,17 +18,12 @@ -- @file xmake.lua -- --- define toolchain toolchain("llvm") - - -- set homepage + set_kind("standalone") set_homepage("https://llvm.org/") set_description("A collection of modular and reusable compiler and toolchain technologies") + set_runtimes("c++_static", "c++_shared", "stdc++_static", "stdc++_shared") - -- mark as standalone toolchain - set_kind("standalone") - - -- set toolset set_toolset("cc", "clang") set_toolset("cxx", "clang", "clang++") set_toolset("mxx", "clang", "clang++") @@ -42,10 +37,8 @@ toolchain("llvm") set_toolset("strip", "llvm-strip") set_toolset("mrc", "llvm-rc") - -- check toolchain on_check("check") - -- on load on_load(function (toolchain) -- add march flags diff --git a/xmake/toolchains/msvc/xmake.lua b/xmake/toolchains/msvc/xmake.lua index a79cb4268..9ef6babe1 100644 --- a/xmake/toolchains/msvc/xmake.lua +++ b/xmake/toolchains/msvc/xmake.lua @@ -30,16 +30,10 @@ -- @endcode -- toolchain("msvc") - - -- set homepage + set_kind("standalone") set_homepage("https://visualstudio.microsoft.com") set_description("Microsoft Visual C/C++ Compiler") + set_runtimes("MT", "MTd", "MD", "MDd") - -- mark as standalone toolchain - set_kind("standalone") - - -- check toolchain on_check("check") - - -- load toolchain on_load("load") diff --git a/xmake/toolchains/ndk/load.lua b/xmake/toolchains/ndk/load.lua index dac6388ca..896e4b837 100644 --- a/xmake/toolchains/ndk/load.lua +++ b/xmake/toolchains/ndk/load.lua @@ -19,6 +19,7 @@ -- -- imports +import("core.base.hashset") import("core.project.config") -- get triple @@ -207,8 +208,17 @@ function main(toolchain) -- get c++ stl sdk directory local cxxstl_sdkdir = nil - local ndk_cxxstl = config.get("ndk_cxxstl") + local ndk_cxxstl = config.get("runtimes") or config.get("ndk_cxxstl") if ndk_cxxstl then + if ndk_cxxstl:find(",", 1, true) then + local runtimes_supported = hashset.from(toolchain:get("runtimes")) + for _, item in ipairs(ndk_cxxstl:split(",")) do + if runtimes_supported:has(item) then + ndk_cxxstl = item + break + end + end + end -- we uses c++_static/c++_shared instead of llvmstl_static/llvmstl_shared if ndk_cxxstl:startswith("c++") or ndk_cxxstl:startswith("llvmstl") then cxxstl_sdkdir = cxxstl_sdkdir_llvmstl diff --git a/xmake/toolchains/ndk/xmake.lua b/xmake/toolchains/ndk/xmake.lua index 609efb4a2..108d52275 100644 --- a/xmake/toolchains/ndk/xmake.lua +++ b/xmake/toolchains/ndk/xmake.lua @@ -30,16 +30,10 @@ -- @endcode -- toolchain("ndk") - - -- set homepage + set_kind("standalone") set_homepage("https://developer.android.com/ndk") set_description("Android NDK") + set_runtimes("c++_static", "c++_shared", "gnustl_static", "gnustl_shared", "stlport_static", "stlport_shared") - -- mark as standalone toolchain - set_kind("standalone") - - -- check toolchain on_check("check") - - -- load toolchain on_load("load") diff --git a/xmake/toolchains/xcode/load_appletvos.lua b/xmake/toolchains/xcode/load_appletvos.lua index aad701ad5..8d723149f 100644 --- a/xmake/toolchains/xcode/load_appletvos.lua +++ b/xmake/toolchains/xcode/load_appletvos.lua @@ -18,10 +18,6 @@ -- @file load_appletvos.lua -- --- imports -import("core.project.config") - --- main entry function main(toolchain) -- init architecture @@ -38,8 +34,8 @@ function main(toolchain) -- init flags for c/c++ toolchain:add("cxflags", "-arch", arch, target_minver_flags, "-isysroot", xcode_sysroot) - toolchain:add("ldflags", "-arch", arch, "-ObjC", "-lstdc++", "-fobjc-link-runtime", target_minver_flags, "-isysroot", xcode_sysroot) - toolchain:add("shflags", "-arch", arch, "-ObjC", "-lstdc++", "-fobjc-link-runtime", target_minver_flags, "-isysroot", xcode_sysroot) + toolchain:add("ldflags", "-arch", arch, "-ObjC", "-fobjc-link-runtime", target_minver_flags, "-isysroot", xcode_sysroot) + toolchain:add("shflags", "-arch", arch, "-ObjC", "-fobjc-link-runtime", target_minver_flags, "-isysroot", xcode_sysroot) -- init flags for objc/c++ toolchain:add("mxflags", "-arch", arch, target_minver_flags, "-isysroot", xcode_sysroot) diff --git a/xmake/toolchains/xcode/load_applexros.lua b/xmake/toolchains/xcode/load_applexros.lua index 61b142374..09805cdc3 100644 --- a/xmake/toolchains/xcode/load_applexros.lua +++ b/xmake/toolchains/xcode/load_applexros.lua @@ -18,10 +18,6 @@ -- @file load_applexros.lua -- --- imports -import("core.project.config") - --- main entry function main(toolchain) local arch = toolchain:arch() diff --git a/xmake/toolchains/xcode/load_iphoneos.lua b/xmake/toolchains/xcode/load_iphoneos.lua index 77a581b0c..a36fa50b9 100644 --- a/xmake/toolchains/xcode/load_iphoneos.lua +++ b/xmake/toolchains/xcode/load_iphoneos.lua @@ -18,10 +18,6 @@ -- @file load_iphoneos.lua -- --- imports -import("core.project.config") - --- main entry function main(toolchain) -- init architecture @@ -41,8 +37,8 @@ function main(toolchain) -- init flags for c/c++ toolchain:add("cxflags", "-arch", arch, target_minver_flags, "-isysroot", xcode_sysroot) - toolchain:add("ldflags", "-arch", arch, "-ObjC", "-lstdc++", "-fobjc-link-runtime", target_minver_flags, "-isysroot", xcode_sysroot) - toolchain:add("shflags", "-arch", arch, "-ObjC", "-lstdc++", "-fobjc-link-runtime", target_minver_flags, "-isysroot", xcode_sysroot) + toolchain:add("ldflags", "-arch", arch, "-ObjC", "-fobjc-link-runtime", target_minver_flags, "-isysroot", xcode_sysroot) + toolchain:add("shflags", "-arch", arch, "-ObjC", "-fobjc-link-runtime", target_minver_flags, "-isysroot", xcode_sysroot) -- init flags for objc/c++ toolchain:add("mxflags", "-arch", arch, target_minver_flags, "-isysroot", xcode_sysroot) diff --git a/xmake/toolchains/xcode/load_macosx.lua b/xmake/toolchains/xcode/load_macosx.lua index 039152067..071f8ec6d 100644 --- a/xmake/toolchains/xcode/load_macosx.lua +++ b/xmake/toolchains/xcode/load_macosx.lua @@ -18,10 +18,6 @@ -- @file load_macosx.lua -- --- imports -import("core.project.config") - --- main entry function main(toolchain) local arch = toolchain:arch() @@ -75,8 +71,6 @@ function main(toolchain) end -- init flags for c/c++ - toolchain:add("ldflags", "-stdlib=libc++") - toolchain:add("shflags", "-stdlib=libc++") toolchain:add("ldflags", "-lz") toolchain:add("shflags", "-lz") diff --git a/xmake/toolchains/xcode/load_watchos.lua b/xmake/toolchains/xcode/load_watchos.lua index a727776bd..cceabeb02 100644 --- a/xmake/toolchains/xcode/load_watchos.lua +++ b/xmake/toolchains/xcode/load_watchos.lua @@ -18,10 +18,6 @@ -- @file load_watchos.lua -- --- imports -import("core.project.config") - --- main entry function main(toolchain) -- init architecture @@ -38,8 +34,8 @@ function main(toolchain) -- init flags for c/c++ toolchain:add("cxflags", "-arch", arch, target_minver_flags, "-isysroot", xcode_sysroot) - toolchain:add("ldflags", "-arch", arch, "-ObjC", "-lstdc++", "-fobjc-link-runtime", target_minver_flags, "-isysroot", xcode_sysroot) - toolchain:add("shflags", "-arch", arch, "-ObjC", "-lstdc++", "-fobjc-link-runtime", target_minver_flags, "-isysroot", xcode_sysroot) + toolchain:add("ldflags", "-arch", arch, "-ObjC", "-fobjc-link-runtime", target_minver_flags, "-isysroot", xcode_sysroot) + toolchain:add("shflags", "-arch", arch, "-ObjC", "-fobjc-link-runtime", target_minver_flags, "-isysroot", xcode_sysroot) -- init flags for objc/c++ toolchain:add("mxflags", "-arch", arch, target_minver_flags, "-isysroot", xcode_sysroot) diff --git a/xmake/toolchains/xcode/xmake.lua b/xmake/toolchains/xcode/xmake.lua index ff304e3b2..2f9e6a053 100644 --- a/xmake/toolchains/xcode/xmake.lua +++ b/xmake/toolchains/xcode/xmake.lua @@ -18,20 +18,13 @@ -- @file xmake.lua -- --- define toolchain toolchain("xcode") - - -- set homepage + set_kind("standalone") set_homepage("https://developer.apple.com/xcode/") set_description("Xcode IDE") + set_runtimes("c++_static", "c++_shared", "stdc++_static", "stdc++_shared") - -- mark as standalone toolchain - set_kind("standalone") - - -- check toolchain on_check("check") - - -- load toolchain on_load(function (toolchain) -- set toolset |
