From cab174afcbf6bfbb1f4cfd446406e95d4e3b00fa Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 13 Oct 2023 22:35:47 +0800 Subject: improve includes --- tests/apis/check_xxx/xmake.lua | 9 +- xmake/core/base/interpreter.lua | 34 ++++++-- xmake/includes/check/check_cflags.lua | 79 +++++++++++++++++ xmake/includes/check/check_cfuncs.lua | 116 +++++++++++++++++++++++++ xmake/includes/check/check_cincludes.lua | 73 ++++++++++++++++ xmake/includes/check/check_csnippets.lua | 134 +++++++++++++++++++++++++++++ xmake/includes/check/check_ctypes.lua | 98 +++++++++++++++++++++ xmake/includes/check/check_cxxflags.lua | 79 +++++++++++++++++ xmake/includes/check/check_cxxfuncs.lua | 116 +++++++++++++++++++++++++ xmake/includes/check/check_cxxincludes.lua | 67 +++++++++++++++ xmake/includes/check/check_cxxsnippets.lua | 134 +++++++++++++++++++++++++++++ xmake/includes/check/check_cxxtypes.lua | 98 +++++++++++++++++++++ xmake/includes/check/check_features.lua | 91 ++++++++++++++++++++ xmake/includes/check/check_links.lua | 67 +++++++++++++++ xmake/includes/check/check_macros.lua | 134 +++++++++++++++++++++++++++++ xmake/includes/check/check_syslinks.lua | 67 +++++++++++++++ xmake/includes/check/xmake.lua | 34 ++++++++ 17 files changed, 1414 insertions(+), 16 deletions(-) create mode 100644 xmake/includes/check/check_cflags.lua create mode 100644 xmake/includes/check/check_cfuncs.lua create mode 100644 xmake/includes/check/check_cincludes.lua create mode 100644 xmake/includes/check/check_csnippets.lua create mode 100644 xmake/includes/check/check_ctypes.lua create mode 100644 xmake/includes/check/check_cxxflags.lua create mode 100644 xmake/includes/check/check_cxxfuncs.lua create mode 100644 xmake/includes/check/check_cxxincludes.lua create mode 100644 xmake/includes/check/check_cxxsnippets.lua create mode 100644 xmake/includes/check/check_cxxtypes.lua create mode 100644 xmake/includes/check/check_features.lua create mode 100644 xmake/includes/check/check_links.lua create mode 100644 xmake/includes/check/check_macros.lua create mode 100644 xmake/includes/check/check_syslinks.lua create mode 100644 xmake/includes/check/xmake.lua diff --git a/tests/apis/check_xxx/xmake.lua b/tests/apis/check_xxx/xmake.lua index a5c748414..c68f71b48 100644 --- a/tests/apis/check_xxx/xmake.lua +++ b/tests/apis/check_xxx/xmake.lua @@ -1,11 +1,4 @@ -includes("check_links.lua") -includes("check_ctypes.lua") -includes("check_cflags.lua") -includes("check_cfuncs.lua") -includes("check_macros.lua") -includes("check_features.lua") -includes("check_csnippets.lua") -includes("check_cincludes.lua") +includes("@builtin/check") target("foo") set_kind("static") diff --git a/xmake/core/base/interpreter.lua b/xmake/core/base/interpreter.lua index 6060fc319..109032e28 100644 --- a/xmake/core/base/interpreter.lua +++ b/xmake/core/base/interpreter.lua @@ -1686,15 +1686,33 @@ function interpreter:api_builtin_includes(...) local subpaths = table.join(...) local subpaths_matched = {} for _, subpath in ipairs(subpaths) do - -- find the given files from the project directory local found = false - local files = os.match(subpath, not subpath:endswith(".lua")) - if files and #files > 0 then - table.join2(subpaths_matched, files) - found = true - elseif not path.is_absolute(subpath) then - -- attempt to find files from programdir/includes/*.lua - files = os.files(path.join(os.programdir(), "includes", subpath)) + -- attempt to find files from programdir/includes/*.lua + -- e.g. includes("@builtin/check") + if subpath:startswith("@builtin/") then + local builtin_path = subpath:sub(10) + local files + if builtin_path:endswith(".lua") then + files = os.files(path.join(os.programdir(), "includes", builtin_path)) + else + files = os.files(path.join(os.programdir(), "includes", builtin_path, "xmake.lua")) + end + if files and #files > 0 then + table.join2(subpaths_matched, files) + found = true + end + end + -- find the given files from the project directory + if not found then + local files = os.match(subpath, not subpath:endswith(".lua")) + if files and #files > 0 then + table.join2(subpaths_matched, files) + found = true + end + end + -- attempt to find files from programdir/includes/*.lua (deprecated) + if not found and not path.is_absolute(subpath) then + local files = os.files(path.join(os.programdir(), "includes", subpath)) if files and #files > 0 then table.join2(subpaths_matched, files) found = true diff --git a/xmake/includes/check/check_cflags.lua b/xmake/includes/check/check_cflags.lua new file mode 100644 index 000000000..5da75b699 --- /dev/null +++ b/xmake/includes/check/check_cflags.lua @@ -0,0 +1,79 @@ +--!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_cflags.lua +-- + +-- check c flags and add macro definition +-- +-- e.g. +-- +-- check_cflags("HAS_SSE2", "-msse2") +-- check_cflags("HAS_SSE2", {"-msse", "-msse2"}) +-- +function check_cflags(definition, flags, opt) + opt = opt or {} + local optname = opt.name or ("__" .. definition) + interp_save_scope() + option(optname) + set_showmenu(false) + add_defines(definition) + on_check(function (option) + import("core.tool.compiler") + if compiler.has_flags("c", flags, opt) then + option:enable(true) + end + end) + option_end() + interp_restore_scope() + add_options(optname) +end + +-- check c flags and add macro definition to the configuration flags +-- +-- e.g. +-- +-- configvar_check_cflags("HAS_SSE2", "-msse2") +-- configvar_check_cflags("HAS_SSE2", {"-msse", "-msse2"}) +-- configvar_check_cflags("HAS_SSE2", "-msse2", {default = 0}) +-- configvar_check_cflags("SSE_STR=2", "-msse2") +-- configvar_check_cflags("SSE=2", "-msse2", {quote = false}) +-- +function configvar_check_cflags(definition, flags, opt) + opt = opt or {} + local optname = opt.name or ("__" .. definition) + local defname, defval = table.unpack(definition:split('=')) + interp_save_scope() + option(optname) + set_showmenu(false) + if opt.default == nil then + set_configvar(defname, defval or 1, {quote = opt.quote}) + end + on_check(function (option) + import("core.tool.compiler") + if compiler.has_flags("c", flags, opt) then + option:enable(true) + end + end) + option_end() + interp_restore_scope() + if opt.default == nil then + add_options(optname) + else + set_configvar(defname, has_config(optname) and (defval or 1) or opt.default, {quote = opt.quote}) + end +end diff --git a/xmake/includes/check/check_cfuncs.lua b/xmake/includes/check/check_cfuncs.lua new file mode 100644 index 000000000..a7a2cfb22 --- /dev/null +++ b/xmake/includes/check/check_cfuncs.lua @@ -0,0 +1,116 @@ +--!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_cfuncs.lua +-- + +-- check c funcs and add macro definition +-- +-- the function syntax +-- - sigsetjmp +-- - sigsetjmp((void*)0, 0) +-- - sigsetjmp{sigsetjmp((void*)0, 0);} +-- - sigsetjmp{int a = 0; sigsetjmp((void*)a, a);} +-- +-- e.g. +-- +-- check_cfuncs("HAS_SETJMP", "setjmp", {includes = {"signal.h", "setjmp.h"}, links = {}}) +-- check_cfuncs("HAS_SETJMP", {"setjmp", "sigsetjmp{sigsetjmp((void*)0, 0);}"}) +-- +function check_cfuncs(definition, funcs, opt) + opt = opt or {} + local optname = opt.name or ("__" .. definition) + interp_save_scope() + option(optname) + set_showmenu(false) + add_cfuncs(funcs) + add_defines(definition) + if opt.links then + add_links(opt.links) + end + if opt.includes then + add_cincludes(opt.includes) + end + if opt.languages then + set_languages(opt.languages) + end + if opt.cflags then + add_cflags(opt.cflags) + end + if opt.cxflags then + add_cxflags(opt.cxflags) + end + if opt.defines then + add_defines(opt.defines) + end + if opt.warnings then + set_warnings(opt.warnings) + end + option_end() + interp_restore_scope() + add_options(optname) +end + +-- check c funcs and add macro definition to the configuration files +-- +-- e.g. +-- +-- configvar_check_cfuncs("HAS_SETJMP", "setjmp", {includes = {"signal.h", "setjmp.h"}, links = {}}) +-- configvar_check_cfuncs("HAS_SETJMP", {"setjmp", "sigsetjmp{sigsetjmp((void*)0, 0);}"}) +-- configvar_check_cfuncs("HAS_SETJMP", "setjmp", {includes = {"setjmp.h"}, default = 0}) +-- configvar_check_cfuncs("CUSTOM_SETJMP=setjmp", "setjmp", {includes = {"setjmp.h"}, default = "", quote = false}) +-- +function configvar_check_cfuncs(definition, funcs, opt) + opt = opt or {} + local optname = opt.name or ("__" .. definition) + local defname, defval = table.unpack(definition:split('=')) + interp_save_scope() + option(optname) + set_showmenu(false) + add_cfuncs(funcs) + if opt.default == nil then + set_configvar(defname, defval or 1, {quote = opt.quote}) + end + if opt.links then + add_links(opt.links) + end + if opt.includes then + add_cincludes(opt.includes) + end + if opt.languages then + set_languages(opt.languages) + end + if opt.cflags then + add_cflags(opt.cflags) + end + if opt.cxflags then + add_cxflags(opt.cxflags) + end + if opt.defines then + add_defines(opt.defines) + end + if opt.warnings then + set_warnings(opt.warnings) + end + option_end() + interp_restore_scope() + if opt.default == nil then + add_options(optname) + else + set_configvar(defname, has_config(optname) and (defval or 1) or opt.default, {quote = opt.quote}) + end +end diff --git a/xmake/includes/check/check_cincludes.lua b/xmake/includes/check/check_cincludes.lua new file mode 100644 index 000000000..68ace5980 --- /dev/null +++ b/xmake/includes/check/check_cincludes.lua @@ -0,0 +1,73 @@ +--!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_cincludes.lua +-- + +-- check include c files and add macro definition +-- +-- e.g. +-- +-- check_cincludes("HAS_STRING_H", "string.h") +-- check_cincludes("HAS_STRING_AND_STDIO_H", {"string.h", "stdio.h"}) +-- +function check_cincludes(definition, includes, opt) + opt = opt or {} + local optname = opt.name or ("__" .. definition) + interp_save_scope() + option(optname) + set_showmenu(false) + add_cincludes(includes) + if opt.includedirs then + add_includedirs(opt.includedirs) + end + add_defines(definition) + option_end() + interp_restore_scope() + add_options(optname) +end + +-- check include c files and add macro definition to the configuration files +-- +-- e.g. +-- +-- configvar_check_cincludes("HAS_STRING_H", "string.h") +-- configvar_check_cincludes("HAS_STRING_H", "string.h", {default = 0}) +-- configvar_check_cincludes("HAS_STRING_AND_STDIO_H", {"string.h", "stdio.h"}) +-- +function configvar_check_cincludes(definition, includes, opt) + opt = opt or {} + local optname = opt.name or ("__" .. definition) + local defname, defval = table.unpack(definition:split('=')) + interp_save_scope() + option(optname) + set_showmenu(false) + add_cincludes(includes) + if opt.includedirs then + add_includedirs(opt.includedirs) + end + if opt.default == nil then + set_configvar(defname, defval or 1, {quote = opt.quote}) + end + option_end() + interp_restore_scope() + if opt.default == nil then + add_options(optname) + else + set_configvar(defname, has_config(optname) and (defval or 1) or opt.default, {quote = opt.quote}) + end +end diff --git a/xmake/includes/check/check_csnippets.lua b/xmake/includes/check/check_csnippets.lua new file mode 100644 index 000000000..2e22c3220 --- /dev/null +++ b/xmake/includes/check/check_csnippets.lua @@ -0,0 +1,134 @@ +--!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_csnippets.lua +-- + +-- check c snippets and add macro definition +-- +-- e.g. +-- +-- check_csnippets("HAS_STATIC_ASSERT", "_Static_assert(1, \"\");", {includes = "stdio.h"}) +-- check_csnippets("HAS_LONG_8", "return (sizeof(long) == 8)? 0 : -1;", {tryrun = true}) +-- check_csnippets("PTR_SIZE", 'printf("%d", sizeof(void*)); return 0;', {output = true, number = true}) +-- +function check_csnippets(definition, snippets, opt) + opt = opt or {} + local optname = opt.name or ("__" .. definition) + interp_save_scope() + option(optname) + set_showmenu(false) + add_csnippets(definition, snippets, {tryrun = opt.tryrun, output = opt.output}) + if not opt.output then + add_defines(definition) + end + if opt.links then + add_links(opt.links) + end + if opt.includes then + add_cincludes(opt.includes) + end + if opt.languages then + set_languages(opt.languages) + end + if opt.cflags then + add_cflags(opt.cflags) + end + if opt.cxflags then + add_cxflags(opt.cxflags) + end + if opt.defines then + add_defines(opt.defines) + end + if opt.warnings then + set_warnings(opt.warnings) + end + if opt.output then + after_check(function (option) + if option:value() then + if opt.number then + option:add("defines", definition .. "=" .. tonumber(option:value())) + elseif opt.quote == false then + option:add("defines", definition .. "=" .. option:value()) + else + option:add("defines", definition .. "=\"" .. option:value() .. "\"") + end + end + end) + end + option_end() + interp_restore_scope() + add_options(optname) +end + +-- check c snippets and add macro definition to the configuration snippets +-- +-- e.g. +-- +-- configvar_check_csnippets("HAS_STATIC_ASSERT", "_Static_assert(1, \"\");", {includes = "stdio.h"}) +-- configvar_check_csnippets("HAS_LONG_8", "return (sizeof(long) == 8)? 0 : -1;", {tryrun = true}) +-- configvar_check_csnippets("HAS_LONG_8", "return (sizeof(long) == 8)? 0 : -1;", {tryrun = true, default = 0}) +-- configvar_check_csnippets("LONG_SIZE=8", "return (sizeof(long) == 8)? 0 : -1;", {tryrun = true, quote = false}) +-- configvar_check_csnippets("PTR_SIZE", 'printf("%d", sizeof(void*)); return 0;', {output = true, number = true}) +-- +function configvar_check_csnippets(definition, snippets, opt) + opt = opt or {} + local optname = opt.name or ("__" .. definition) + local defname, defval = table.unpack(definition:split('=')) + interp_save_scope() + option(optname) + set_showmenu(false) + add_csnippets(definition, snippets, {tryrun = opt.tryrun, output = opt.output}) + if opt.default == nil then + set_configvar(defname, defval or 1, {quote = opt.quote}) + end + if opt.links then + add_links(opt.links) + end + if opt.includes then + add_cincludes(opt.includes) + end + if opt.languages then + set_languages(opt.languages) + end + if opt.cflags then + add_cflags(opt.cflags) + end + if opt.cxflags then + add_cxflags(opt.cxflags) + end + if opt.defines then + add_defines(opt.defines) + end + if opt.warnings then + set_warnings(opt.warnings) + end + if opt.output then + after_check(function (option) + if option:value() then + option:set("configvar", defname, opt.number and tonumber(option:value()) or option:value(), {quote = opt.quote}) + end + end) + end + option_end() + interp_restore_scope() + if opt.default == nil then + add_options(optname) + else + set_configvar(defname, has_config(optname) and (defval or 1) or opt.default, {quote = opt.quote}) + end +end diff --git a/xmake/includes/check/check_ctypes.lua b/xmake/includes/check/check_ctypes.lua new file mode 100644 index 000000000..e89345eea --- /dev/null +++ b/xmake/includes/check/check_ctypes.lua @@ -0,0 +1,98 @@ +--!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_ctypes.lua +-- + +-- check c types and add macro definition +-- +-- e.g. +-- +-- check_ctypes("HAS_WCHAR", "wchar_t") +-- check_ctypes("HAS_WCHAR_AND_FLOAT", {"wchar_t", "float"}) +-- +function check_ctypes(definition, types, opt) + opt = opt or {} + local optname = opt.name or ("__" .. definition) + interp_save_scope() + option(optname) + set_showmenu(false) + add_ctypes(types) + add_defines(definition) + if opt.languages then + set_languages(opt.languages) + end + if opt.cflags then + add_cflags(opt.cflags) + end + if opt.cxflags then + add_cxflags(opt.cxflags) + end + if opt.defines then + add_defines(opt.defines) + end + if opt.includes then + add_cincludes(opt.includes) + end + option_end() + interp_restore_scope() + add_options(optname) +end + +-- check c types and add macro definition to the configuration types +-- +-- e.g. +-- +-- configvar_check_ctypes("HAS_WCHAR", "wchar_t") +-- configvar_check_ctypes("HAS_WCHAR", "wchar_t", {default = 0}) +-- configvar_check_ctypes("CUSTOM_WCHAR=wchar_t", "wchar_t", {default = "", quote = false}) +-- configvar_check_ctypes("HAS_WCHAR_AND_FLOAT", {"wchar_t", "float"}) +-- +function configvar_check_ctypes(definition, types, opt) + opt = opt or {} + local optname = opt.name or ("__" .. definition) + local defname, defval = table.unpack(definition:split('=')) + interp_save_scope() + option(optname) + set_showmenu(false) + add_ctypes(types) + if opt.default == nil then + set_configvar(defname, defval or 1, {quote = opt.quote}) + end + if opt.languages then + set_languages(opt.languages) + end + if opt.cflags then + add_cflags(opt.cflags) + end + if opt.cxflags then + add_cxflags(opt.cxflags) + end + if opt.defines then + add_defines(opt.defines) + end + if opt.includes then + add_cincludes(opt.includes) + end + option_end() + interp_restore_scope() + if opt.default == nil then + add_options(optname) + else + set_configvar(defname, has_config(optname) and (defval or 1) or opt.default, {quote = opt.quote}) + end +end diff --git a/xmake/includes/check/check_cxxflags.lua b/xmake/includes/check/check_cxxflags.lua new file mode 100644 index 000000000..6b6e78d0f --- /dev/null +++ b/xmake/includes/check/check_cxxflags.lua @@ -0,0 +1,79 @@ +--!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_cxxflags.lua +-- + +-- check c++ flags and add macro definition +-- +-- e.g. +-- +-- check_cxxflags("HAS_SSE2", "-msse2") +-- check_cxxflags("HAS_SSE2", {"-msse", "-msse2"}) +-- +function check_cxxflags(definition, flags, opt) + opt = opt or {} + local optname = opt.name or ("__" .. definition) + interp_save_scope() + option(optname) + set_showmenu(false) + add_defines(definition) + on_check(function (option) + import("core.tool.compiler") + if compiler.has_flags("cxx", flags, opt) then + option:enable(true) + end + end) + option_end() + interp_restore_scope() + add_options(optname) +end + +-- check c++ flags and add macro definition to the configuration flags +-- +-- e.g. +-- +-- configvar_check_cxxflags("HAS_SSE2", "-msse2") +-- configvar_check_cxxflags("HAS_SSE2", {"-msse", "-msse2"}) +-- configvar_check_cxxflags("HAS_SSE2", "-msse2", {default = 0}) +-- configvar_check_cxxflags("SSE_STR=2", "-msse2") +-- configvar_check_cxxflags("SSE=2", "-msse2", {quote = false}) +-- +function configvar_check_cxxflags(definition, flags, opt) + opt = opt or {} + local optname = opt.name or ("__" .. definition) + local defname, defval = table.unpack(definition:split('=')) + interp_save_scope() + option(optname) + set_showmenu(false) + if opt.default == nil then + set_configvar(defname, defval or 1, {quote = opt.quote}) + end + on_check(function (option) + import("core.tool.compiler") + if compiler.has_flags("cxx", flags, opt) then + option:enable(true) + end + end) + option_end() + interp_restore_scope() + if opt.default == nil then + add_options(optname) + else + set_configvar(defname, has_config(optname) and (defval or 1) or opt.default, {quote = opt.quote}) + end +end diff --git a/xmake/includes/check/check_cxxfuncs.lua b/xmake/includes/check/check_cxxfuncs.lua new file mode 100644 index 000000000..2ac98d799 --- /dev/null +++ b/xmake/includes/check/check_cxxfuncs.lua @@ -0,0 +1,116 @@ +--!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_cxxfuncs.lua +-- + +-- check c++ funcs and add macro definition +-- +-- the function syntax +-- - sigsetjmp +-- - sigsetjmp((void*)0, 0) +-- - sigsetjmp{sigsetjmp((void*)0, 0);} +-- - sigsetjmp{int a = 0; sigsetjmp((void*)a, a);} +-- +-- e.g. +-- +-- check_cxxfuncs("HAS_SETJMP", "setjmp", {includes = {"signal.h", "setjmp.h"}, links = {}}) +-- check_cxxfuncs("HAS_SETJMP", {"setjmp", "sigsetjmp{sigsetjmp((void*)0, 0);}"}) +-- +function check_cxxfuncs(definition, funcs, opt) + opt = opt or {} + local optname = opt.name or ("__" .. definition) + interp_save_scope() + option(optname) + set_showmenu(false) + add_cxxfuncs(funcs) + add_defines(definition) + if opt.links then + add_links(opt.links) + end + if opt.includes then + add_cxxincludes(opt.includes) + end + if opt.languages then + set_languages(opt.languages) + end + if opt.cxflags then + add_cxflags(opt.cxflags) + end + if opt.cxxflags then + add_cxxflags(opt.cxxflags) + end + if opt.defines then + add_defines(opt.defines) + end + if opt.warnings then + set_warnings(opt.warnings) + end + option_end() + interp_restore_scope() + add_options(optname) +end + +-- check c++ funcs and add macro definition to the configuration files +-- +-- e.g. +-- +-- configvar_check_cxxfuncs("HAS_SETJMP", "setjmp", {includes = {"signal.h", "setjmp.h"}, links = {}}) +-- configvar_check_cxxfuncs("HAS_SETJMP", {"setjmp", "sigsetjmp{sigsetjmp((void*)0, 0);}"}) +-- configvar_check_cxxfuncs("HAS_SETJMP", "setjmp", {includes = {"setjmp.h"}, default = 0}) +-- configvar_check_cxxfuncs("CUSTOM_SETJMP=setjmp", "setjmp", {includes = {"setjmp.h"}, default = "", quote = false}) +-- +function configvar_check_cxxfuncs(definition, funcs, opt) + opt = opt or {} + local optname = opt.name or ("__" .. definition) + local defname, defval = table.unpack(definition:split('=')) + interp_save_scope() + option(optname) + set_showmenu(false) + add_cxxfuncs(funcs) + if opt.default == nil then + set_configvar(defname, defval or 1, {quote = opt.quote}) + end + if opt.links then + add_links(opt.links) + end + if opt.includes then + add_cxxincludes(opt.includes) + end + if opt.languages then + set_languages(opt.languages) + end + if opt.cxflags then + add_cxflags(opt.cxflags) + end + if opt.cxxflags then + add_cxxflags(opt.cxxflags) + end + if opt.defines then + add_defines(opt.defines) + end + if opt.warnings then + set_warnings(opt.warnings) + end + option_end() + interp_restore_scope() + if opt.default == nil then + add_options(optname) + else + set_configvar(defname, has_config(optname) and (defval or 1) or opt.default, {quote = opt.quote}) + end +end diff --git a/xmake/includes/check/check_cxxincludes.lua b/xmake/includes/check/check_cxxincludes.lua new file mode 100644 index 000000000..4eff5f53e --- /dev/null +++ b/xmake/includes/check/check_cxxincludes.lua @@ -0,0 +1,67 @@ +--!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_cxxincludes.lua +-- + +-- check include c++ files and add macro definition +-- +-- e.g. +-- +-- check_cxxincludes("HAS_STRING_H", "string.h") +-- check_cxxincludes("HAS_STRING_AND_STDIO_H", {"string.h", "stdio.h"}) +-- +function check_cxxincludes(definition, includes, opt) + opt = opt or {} + local optname = opt.name or ("__" .. definition) + interp_save_scope() + option(optname) + set_showmenu(false) + add_cxxincludes(includes) + add_defines(definition) + option_end() + interp_restore_scope() + add_options(optname) +end + +-- check include c++ files and add macro definition to the configuration files +-- +-- e.g. +-- +-- configvar_check_cxxincludes("HAS_STRING_H", "string.h") +-- configvar_check_cxxincludes("HAS_STRING_H", "string.h", {default = 0}) +-- configvar_check_cxxincludes("HAS_STRING_AND_STDIO_H", {"string.h", "stdio.h"}) +-- +function configvar_check_cxxincludes(definition, includes, opt) + opt = opt or {} + local optname = opt.name or ("__" .. definition) + local defname, defval = table.unpack(definition:split('=')) + interp_save_scope() + option(optname) + set_showmenu(false) + add_cxxincludes(includes) + if opt.default == nil then + set_configvar(defname, defval or 1, {quote = opt.quote}) + end + option_end() + interp_restore_scope() + if opt.default == nil then + add_options(optname) + else + set_configvar(defname, has_config(optname) and (defval or 1) or opt.default, {quote = opt.quote}) + end +end diff --git a/xmake/includes/check/check_cxxsnippets.lua b/xmake/includes/check/check_cxxsnippets.lua new file mode 100644 index 000000000..358818844 --- /dev/null +++ b/xmake/includes/check/check_cxxsnippets.lua @@ -0,0 +1,134 @@ +--!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_cxxsnippets.lua +-- + +-- check c++ snippets and add macro definition +-- +-- e.g. +-- +-- check_cxxsnippets("HAS_STATIC_ASSERT", "static_assert(1, \"\");") +-- check_csnippets("HAS_LONG_8", "return (sizeof(long) == 8)? 0 : -1;", {tryrun = true}) +-- check_csnippets("PTR_SIZE", 'printf("%d", sizeof(void*)); return 0;', {output = true, number = true}) +-- +function check_cxxsnippets(definition, snippets, opt) + opt = opt or {} + local optname = opt.name or ("__" .. definition) + interp_save_scope() + option(optname) + set_showmenu(false) + add_cxxsnippets(definition, snippets, {tryrun = opt.tryrun, output = opt.output}) + if not opt.output then + add_defines(definition) + end + if opt.links then + add_links(opt.links) + end + if opt.includes then + add_cxxincludes(opt.includes) + end + if opt.languages then + set_languages(opt.languages) + end + if opt.cxflags then + add_cxflags(opt.cxflags) + end + if opt.cxxflags then + add_cxxflags(opt.cxxflags) + end + if opt.defines then + add_defines(opt.defines) + end + if opt.warnings then + set_warnings(opt.warnings) + end + if opt.output then + after_check(function (option) + if option:value() then + if opt.number then + option:add("defines", definition .. "=" .. tonumber(option:value())) + elseif opt.quote == false then + option:add("defines", definition .. "=" .. option:value()) + else + option:add("defines", definition .. "=\"" .. option:value() .. "\"") + end + end + end) + end + option_end() + interp_restore_scope() + add_options(optname) +end + +-- check c++ snippets and add macro definition to the configuration snippets +-- +-- e.g. +-- +-- configvar_check_cxxsnippets("HAS_STATIC_ASSERT", "static_assert(1, \"\");") +-- configvar_check_cxxsnippets("HAS_LONG_8", "return (sizeof(long) == 8)? 0 : -1;", {tryrun = true}) +-- configvar_check_cxxsnippets("HAS_LONG_8", "return (sizeof(long) == 8)? 0 : -1;", {tryrun = true, default = 0}) +-- configvar_check_cxxsnippets("LONG_SIZE=8", "return (sizeof(long) == 8)? 0 : -1;", {tryrun = true, quote = false}) +-- configvar_check_cxxsnippets("PTR_SIZE", 'printf("%d", sizeof(void*)); return 0;', {output = true, number = true}) +-- +function configvar_check_cxxsnippets(definition, snippets, opt) + opt = opt or {} + local optname = opt.name or ("__" .. definition) + local defname, defval = table.unpack(definition:split('=')) + interp_save_scope() + option(optname) + set_showmenu(false) + add_cxxsnippets(definition, snippets, {tryrun = opt.tryrun, output = opt.output}) + if opt.default == nil then + set_configvar(defname, defval or 1, {quote = opt.quote}) + end + if opt.links then + add_links(opt.links) + end + if opt.includes then + add_cxxincludes(opt.includes) + end + if opt.languages then + set_languages(opt.languages) + end + if opt.cxflags then + add_cxflags(opt.cxflags) + end + if opt.cxxflags then + add_cxxflags(opt.cxxflags) + end + if opt.defines then + add_defines(opt.defines) + end + if opt.warnings then + set_warnings(opt.warnings) + end + if opt.output then + after_check(function (option) + if option:value() then + option:set("configvar", defname, opt.number and tonumber(option:value()) or option:value(), {quote = opt.quote}) + end + end) + end + option_end() + interp_restore_scope() + if opt.default == nil then + add_options(optname) + else + set_configvar(defname, has_config(optname) and (defval or 1) or opt.default, {quote = opt.quote}) + end +end diff --git a/xmake/includes/check/check_cxxtypes.lua b/xmake/includes/check/check_cxxtypes.lua new file mode 100644 index 000000000..28964b6f4 --- /dev/null +++ b/xmake/includes/check/check_cxxtypes.lua @@ -0,0 +1,98 @@ +--!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_cxxtypes.lua +-- + +-- check c++ types and add macro definition +-- +-- e.g. +-- +-- check_cxxtypes("HAS_WCHAR", "wchar_t") +-- check_cxxtypes("HAS_WCHAR_AND_FLOAT", {"wchar_t", "float"}) +-- +function check_cxxtypes(definition, types, opt) + opt = opt or {} + local optname = opt.name or ("__" .. definition) + interp_save_scope() + option(optname) + set_showmenu(false) + add_cxxtypes(types) + add_defines(definition) + if opt.languages then + set_languages(opt.languages) + end + if opt.cxflags then + add_cxflags(opt.cxflags) + end + if opt.cxxflags then + add_cxxflags(opt.cxxflags) + end + if opt.defines then + add_defines(opt.defines) + end + if opt.includes then + add_cxxincludes(opt.includes) + end + option_end() + interp_restore_scope() + add_options(optname) +end + +-- check c++ types and add macro definition to the configuration types +-- +-- e.g. +-- +-- configvar_check_cxxtypes("HAS_WCHAR", "wchar_t") +-- configvar_check_cxxtypes("HAS_WCHAR", "wchar_t", {default = 0}) +-- configvar_check_cxxtypes("CUSTOM_WCHAR=wchar_t", "wchar_t", {default = "", quote = false}) +-- configvar_check_cxxtypes("HAS_WCHAR_AND_FLOAT", {"wchar_t", "float"}) +-- +function configvar_check_cxxtypes(definition, types, opt) + opt = opt or {} + local optname = opt.name or ("__" .. definition) + local defname, defval = table.unpack(definition:split('=')) + interp_save_scope() + option(optname) + set_showmenu(false) + add_cxxtypes(types) + if opt.default == nil then + set_configvar(defname, defval or 1, {quote = opt.quote}) + end + if opt.languages then + set_languages(opt.languages) + end + if opt.cxflags then + add_cxflags(opt.cxflags) + end + if opt.cxxflags then + add_cxxflags(opt.cxxflags) + end + if opt.defines then + add_defines(opt.defines) + end + if opt.includes then + add_cxxincludes(opt.includes) + end + option_end() + interp_restore_scope() + if opt.default == nil then + add_options(optname) + else + set_configvar(defname, has_config(optname) and (defval or 1) or opt.default, {quote = opt.quote}) + end +end diff --git a/xmake/includes/check/check_features.lua b/xmake/includes/check/check_features.lua new file mode 100644 index 000000000..2dca743fa --- /dev/null +++ b/xmake/includes/check/check_features.lua @@ -0,0 +1,91 @@ +--!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_features.lua +-- + +-- check features and add macro definition +-- +-- e.g. +-- +-- check_features("HAS_CONSTEXPR", "cxx_constexpr") +-- check_features("HAS_CONSEXPR_AND_STATIC_ASSERT", {"cxx_constexpr", "c_static_assert"}, {cxflags = "", languages = "c++11"}) +-- +function check_features(definition, features, opt) + opt = opt or {} + local optname = opt.name or ("__" .. definition) + interp_save_scope() + option(optname) + set_showmenu(false) + add_features(features) + add_defines(definition) + if opt.languages then + set_languages(opt.languages) + end + if opt.cflags then + add_cflags(opt.cflags) + end + if opt.cxflags then + add_cxflags(opt.cxflags) + end + if opt.cxxflags then + add_cxxflags(opt.cxxflags) + end + option_end() + interp_restore_scope() + add_options(optname) +end + +-- check features and add macro definition to the configuration files +-- +-- e.g. +-- +-- configvar_check_features("HAS_CONSTEXPR", "cxx_constexpr") +-- configvar_check_features("HAS_CONSTEXPR", "cxx_constexpr", {default = 0}) +-- configvar_check_features("HAS_CONSEXPR_AND_STATIC_ASSERT", {"cxx_constexpr", "c_static_assert"}, {languages = "c++11"}) +-- +function configvar_check_features(definition, features, opt) + opt = opt or {} + local optname = opt.name or ("__" .. definition) + local defname, defval = table.unpack(definition:split('=')) + interp_save_scope() + option(optname) + set_showmenu(false) + add_features(features) + if opt.default == nil then + set_configvar(defname, defval or 1, {quote = opt.quote}) + end + if opt.languages then + set_languages(opt.languages) + end + if opt.cflags then + add_cflags(opt.cflags) + end + if opt.cxflags then + add_cxflags(opt.cxflags) + end + if opt.cxxflags then + add_cxxflags(opt.cxxflags) + end + option_end() + interp_restore_scope() + if opt.default == nil then + add_options(optname) + else + set_configvar(defname, has_config(optname) and (defval or 1) or opt.default, {quote = opt.quote}) + end +end diff --git a/xmake/includes/check/check_links.lua b/xmake/includes/check/check_links.lua new file mode 100644 index 000000000..075be25b0 --- /dev/null +++ b/xmake/includes/check/check_links.lua @@ -0,0 +1,67 @@ +--!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_links.lua +-- + +-- check links and add macro definition +-- +-- e.g. +-- +-- check_links("HAS_PTHREAD", "pthread") +-- check_links("HAS_PTHREAD", {"pthread", "m", "dl"}) +-- +function check_links(definition, links, opt) + opt = opt or {} + local optname = opt.name or ("__" .. definition) + interp_save_scope() + option(optname) + set_showmenu(false) + add_links(links) + add_defines(definition) + option_end() + interp_restore_scope() + add_options(optname) +end + +-- check links and add macro definition to the configuration files +-- +-- e.g. +-- +-- configvar_check_links("HAS_PTHREAD", "pthread") +-- configvar_check_links("HAS_PTHREAD", "pthread", {default = 0}) +-- configvar_check_links("HAS_PTHREAD", {"pthread", "m", "dl"}) +-- +function configvar_check_links(definition, links, opt) + opt = opt or {} + local optname = opt.name or ("__" .. definition) + local defname, defval = table.unpack(definition:split('=')) + interp_save_scope() + option(optname) + set_showmenu(false) + add_links(links) + if opt.default == nil then + set_configvar(defname, defval or 1, {quote = opt.quote}) + end + option_end() + interp_restore_scope() + if opt.default == nil then + add_options(optname) + else + set_configvar(defname, has_config(optname) and (defval or 1) or opt.default, {quote = opt.quote}) + end +end diff --git a/xmake/includes/check/check_macros.lua b/xmake/includes/check/check_macros.lua new file mode 100644 index 000000000..2235798ec --- /dev/null +++ b/xmake/includes/check/check_macros.lua @@ -0,0 +1,134 @@ +--!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_macros.lua +-- + +-- check macros and add macro definition +-- +-- e.g. +-- +-- check_macros("HAS_GCC", "__GNUC__") +-- check_macros("NO_GCC", "__GNUC__", {defined = false}) +-- check_macros("HAS_CXX20", "__cplusplus >= 202002L", {languages = "c++20"}) +-- +function check_macros(definition, macros, opt) + opt = opt or {} + local optname = opt.name or ("__" .. definition) + local snippets = {} + interp_save_scope() + option(optname) + set_showmenu(false) + for _, macro in ipairs(macros) do + if macro:find(' ', 1, true) then + table.insert(snippets, ([[ + #if %s + #else + # #error %s is not satisfied! + #endif + ]]):format(macro, macro)) + else + table.insert(snippets, ([[ + #if%s %s + #else + # #error %s is not defined! + #endif + ]]):format(opt.defined ~= false and "def" or "ndef", macro, macro)) + end + end + if opt.languages and opt.languages:startswith("c++") then + add_cxxsnippets(definition, table.concat(snippets, "\n")) + else + add_csnippets(definition, table.concat(snippets, "\n")) + end + add_defines(definition) + if opt.languages then + set_languages(opt.languages) + end + if opt.cflags then + add_cflags(opt.cflags) + end + if opt.cxflags then + add_cxflags(opt.cxflags) + end + if opt.cxxflags then + add_cxxflags(opt.cxxflags) + end + option_end() + interp_restore_scope() + add_options(optname) +end + +-- check macros and add macro definition to the configuration files +-- +-- e.g. +-- configvar_check_macros("HAS_GCC", "__GNUC__") +-- configvar_check_macros("NO_GCC", "__GNUC__", {defined = false}) +-- configvar_check_macros("HAS_CXX20", "__cplusplus >= 202002L", {languages = "c++20"}) +function configvar_check_macros(definition, macros, opt) + opt = opt or {} + local optname = opt.name or ("__" .. definition) + local defname, defval = table.unpack(definition:split('=')) + local snippets = {} + interp_save_scope() + option(optname) + set_showmenu(false) + for _, macro in ipairs(macros) do + if macro:find(' ', 1, true) then + table.insert(snippets, ([[ + #if %s + #else + # #error %s is not satisfied! + #endif + ]]):format(macro, macro)) + else + table.insert(snippets, ([[ + #if%s %s + #else + # #error %s is not defined! + #endif + ]]):format(opt.defined ~= false and "def" or "ndef", macro, macro)) + end + end + if opt.languages and opt.languages:startswith("c++") then + add_cxxsnippets(definition, table.concat(snippets, "\n")) + else + add_csnippets(definition, table.concat(snippets, "\n")) + end + if opt.default == nil then + set_configvar(defname, defval or 1, {quote = opt.quote}) + end + if opt.languages then + set_languages(opt.languages) + end + if opt.cflags then + add_cflags(opt.cflags) + end + if opt.cxflags then + add_cxflags(opt.cxflags) + end + if opt.cxxflags then + add_cxxflags(opt.cxxflags) + end + option_end() + interp_restore_scope() + if opt.default == nil then + add_options(optname) + else + set_configvar(defname, has_config(optname) and (defval or 1) or opt.default, {quote = opt.quote}) + end +end diff --git a/xmake/includes/check/check_syslinks.lua b/xmake/includes/check/check_syslinks.lua new file mode 100644 index 000000000..ff44f8098 --- /dev/null +++ b/xmake/includes/check/check_syslinks.lua @@ -0,0 +1,67 @@ +--!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_syslinks.lua +-- + +-- check links and add macro definition +-- +-- e.g. +-- +-- check_syslinks("HAS_PTHREAD", "pthread") +-- check_syslinks("HAS_PTHREAD", {"pthread", "m", "dl"}) +-- +function check_syslinks(definition, links, opt) + opt = opt or {} + local optname = opt.name or ("__" .. definition) + interp_save_scope() + option(optname) + set_showmenu(false) + add_syslinks(links) + add_defines(definition) + option_end() + interp_restore_scope() + add_options(optname) +end + +-- check links and add macro definition to the configuration files +-- +-- e.g. +-- +-- configvar_check_syslinks("HAS_PTHREAD", "pthread") +-- configvar_check_syslinks("HAS_PTHREAD", "pthread", {default = 0}) +-- configvar_check_syslinks("HAS_PTHREAD", {"pthread", "m", "dl"}) +-- +function configvar_check_syslinks(definition, links, opt) + opt = opt or {} + local optname = opt.name or ("__" .. definition) + local defname, defval = table.unpack(definition:split('=')) + interp_save_scope() + option(optname) + set_showmenu(false) + add_syslinks(links) + if opt.default == nil then + set_configvar(defname, defval or 1, {quote = opt.quote}) + end + option_end() + interp_restore_scope() + if opt.default == nil then + add_options(optname) + else + set_configvar(defname, has_config(optname) and (defval or 1) or opt.default, {quote = opt.quote}) + end +end diff --git a/xmake/includes/check/xmake.lua b/xmake/includes/check/xmake.lua new file mode 100644 index 000000000..467d232f6 --- /dev/null +++ b/xmake/includes/check/xmake.lua @@ -0,0 +1,34 @@ +--!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 +-- + +includes("@builtin/check/check_cflags.lua") +includes("@builtin/check/check_cfuncs.lua") +includes("@builtin/check/check_cincludes.lua") +includes("@builtin/check/check_csnippets.lua") +includes("@builtin/check/check_ctypes.lua") +includes("@builtin/check/check_cxxflags.lua") +includes("@builtin/check/check_cxxfuncs.lua") +includes("@builtin/check/check_cxxincludes.lua") +includes("@builtin/check/check_cxxsnippets.lua") +includes("@builtin/check/check_cxxtypes.lua") +includes("@builtin/check/check_features.lua") +includes("@builtin/check/check_links.lua") +includes("@builtin/check/check_macros.lua") +includes("@builtin/check/check_syslinks.lua") -- cgit v1.3.1