diff options
| author | Ângelo Andrade Cirino <[email protected]> | 2021-08-05 17:06:44 -0300 |
|---|---|---|
| committer | Ângelo Andrade Cirino <[email protected]> | 2021-08-05 17:06:44 -0300 |
| commit | 286ba62b6189953f8a0c255053ca3c3f7f1e5693 (patch) | |
| tree | 7d0671f7a57ea8ae102be3454d956848eb8b0b5c | |
| parent | 81ad292ea67f82d88d785a37d23b1f1603996da1 (diff) | |
| parent | a959af20d2a34038efb13053c112ef1d55084081 (diff) | |
Merge branch 'master' of https://github.com/xmake-io/xmake
97 files changed, 1995 insertions, 1912 deletions
diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 69daa9178..fce3236a6 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -10,9 +10,10 @@ jobs: build: strategy: matrix: + os: [windows-latest, windows-2016] arch: [x64, x86] - runs-on: windows-latest + runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v2 diff --git a/CHANGELOG.md b/CHANGELOG.md index 4df7191fe..756b3021d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,11 +4,31 @@ ### New features +* [#1534](https://github.com/xmake-io/xmake/issues/1534): Support to compile Vala lanuage project +* [#1544](https://github.com/xmake-io/xmake/issues/1544): Add utils.bin2c rule to generate header from binary file + +### Change + +* [#1540](https://github.com/xmake-io/xmake/issues/1540): Better support for compilation of automatically generated code + +### Bugs fixed + +* [#1531](https://github.com/xmake-io/xmake/issues/1531): Fix error info when loading targets failed + +## v2.5.6 + +### New features + * [#1483](https://github.com/xmake-io/xmake/issues/1483): Add `os.joinenvs()` and improve package tools envirnoments +* [#1523](https://github.com/xmake-io/xmake/issues/1523): Add `set_allowedmodes`, `set_allowedplats` and `set_allowedarchs` +* [#1523](https://github.com/xmake-io/xmake/issues/1523): Add `set_defaultmode`, `set_defaultplat` and `set_defaultarch` ### Change * Improve vs/vsxmake project generator to support vs2022 +* [#1513](https://github.com/xmake-io/xmake/issues/1513): Improve precompiled binary package compatibility on windows/msvc +* Improve to find vcpkg root directory on windows +* Improve to support Qt6 ### Bugs fixed @@ -1035,11 +1055,31 @@ ### 新特性 +* [#1534](https://github.com/xmake-io/xmake/issues/1534): 新增对 Vala 语言的支持 +* [#1544](https://github.com/xmake-io/xmake/issues/1544): 添加 utils.bin2c 规则去自动从二进制资源文件产生 .h 头文件并引入到 C/C++ 代码中 + +### 改进 + +* [#1540](https://github.com/xmake-io/xmake/issues/1540): 更好更方便地编译自动生成的代码 + +### Bugs 修复 + +* [#1531](https://github.com/xmake-io/xmake/issues/1531): 修复 targets 加载失败的错误信息提示错误 + +## v2.5.6 + +### 新特性 + * [#1483](https://github.com/xmake-io/xmake/issues/1483): 添加 `os.joinenvs()` 和改进包工具环境 +* [#1523](https://github.com/xmake-io/xmake/issues/1523): 添加 `set_allowedmodes`, `set_allowedplats` 和 `set_allowedarchs` +* [#1523](https://github.com/xmake-io/xmake/issues/1523): 添加 `set_defaultmode`, `set_defaultplat` 和 `set_defaultarch` ### 改进 * 改进 vs/vsxmake 工程插件支持 vs2022 +* [#1513](https://github.com/xmake-io/xmake/issues/1513): 改进 windows 预编译包的兼容性问题 +* 改进 vcpkg 包在 windows 上的查找 +* 改进对 Qt6 的支持 ### Bugs 修复 @@ -238,6 +238,7 @@ muslcc The musl-based cross-compilation toolchains * Fortran * Cuda * Zig +* Vala ## Support Features diff --git a/README_zh.md b/README_zh.md index 386c82714..61f5ad93a 100644 --- a/README_zh.md +++ b/README_zh.md @@ -245,6 +245,7 @@ muslcc The musl-based cross-compilation toolchains * Fortran * Cuda * Zig +* Vala ## 支持特性 diff --git a/core/plat/iphoneos/prefix.mak b/core/plat/iphoneos/prefix.mak index d81e6edba..c2b2d93b6 100644 --- a/core/plat/iphoneos/prefix.mak +++ b/core/plat/iphoneos/prefix.mak @@ -25,7 +25,7 @@ TARGETARCH += -miphoneos-version-min=10.0 PRE_ := $(if $(BIN),$(BIN)/$(PRE),xcrun -sdk iphoneos ) # cc -CC = $(PRE_)clang +CC := $(if $(CC),$(CC),$(PRE_)clang) ifeq ($(CXFLAGS_CHECK),) CC_CHECK = ${shell if $(CC) $(1) -S -o /dev/null -xc /dev/null > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi } CXFLAGS_CHECK := $(call CC_CHECK,-ftrapv,) @@ -33,7 +33,7 @@ export CXFLAGS_CHECK endif # ld -LD = $(PRE_)clang +LD := $(if $(CC),$(CC),$(PRE_)clang) ifeq ($(LDFLAGS_CHECK),) LD_CHECK = ${shell if $(LD) $(1) -S -o /dev/null -xc /dev/null > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi } LDFLAGS_CHECK := $(call LD_CHECK,-ftrapv,) @@ -41,10 +41,10 @@ export LDFLAGS_CHECK endif # tool -MM = $(PRE_)clang -AR = $(PRE_)ar -STRIP = $(PRE_)strip -RANLIB = $(PRE_)ranlib +MM := $(if $(CC),$(CC),$(PRE_)clang) +AR := $(if $(AR),$(AR),$(PRE_)ar) +STRIP := $(if $(STRIP),$(STRIP),$(PRE_)strip) +RANLIB := $(if $(RANLIB),$(RANLIB),$(PRE_)ranlib) AS = $(PRE_)clang RM = rm -f RMDIR = rm -rf diff --git a/core/project.mak b/core/project.mak index 4c3aed86c..eafef391e 100644 --- a/core/project.mak +++ b/core/project.mak @@ -10,7 +10,7 @@ PRO_VERSION_MAJOR = 2 PRO_VERSION_MINOR = 5 # the project alter version -PRO_VERSION_ALTER = 5 +PRO_VERSION_ALTER = 6 # the project prefix PRO_PREFIX = XM_ diff --git a/core/xmake.lua b/core/xmake.lua index 23d807ffe..e66405e57 100644 --- a/core/xmake.lua +++ b/core/xmake.lua @@ -2,7 +2,7 @@ set_project("xmake") -- version -set_version("2.5.5", {build = "%Y%m%d%H%M"}) +set_version("2.5.6", {build = "%Y%m%d%H%M"}) -- set xmake min version set_xmakever("2.2.3") @@ -114,10 +114,10 @@ install: @cp -r xmake/* $(xmake_dir_install) @# install the xmake core file @cp -p $(xmake_core) $(xmake_core_install) - @chmod 777 $(xmake_core_install) + @chmod 755 $(xmake_core_install) @# install the xrepo bin file @cp -p ./scripts/xrepo.sh $(xrepo_bin_install) - @chmod 777 $(xrepo_bin_install) + @chmod 755 $(xrepo_bin_install) @# remove xmake.out @if [ -f "$(TMP_DIR)/xmake.out" ]; then rm $(TMP_DIR)/xmake.out; fi @# ok diff --git a/scripts/get.ps1 b/scripts/get.ps1 index a189b2ba2..8cb27a888 100755 --- a/scripts/get.ps1 +++ b/scripts/get.ps1 @@ -86,12 +86,9 @@ param ( $outfile = Join-Path $temppath "$pid-xmake-installer.exe" $x64arch = @('AMD64', 'IA64', 'ARM64') $arch = if ($env:PROCESSOR_ARCHITECTURE -in $x64arch -or $env:PROCESSOR_ARCHITEW6432 -in $x64arch) { 'x64' } else { 'x86' } + $winarch = if ($env:PROCESSOR_ARCHITECTURE -in $x64arch -or $env:PROCESSOR_ARCHITEW6432 -in $x64arch) { 'win64' } else { 'win32' } $url = if ($v -is [version]) { - if ($v -gt "2.2.6") { - "https://ci.appveyor.com/api/projects/waruqi/xmake/artifacts/xmake-installer.exe?tag=v$v&pr=false&job=Image%3A+Visual+Studio+2017%3B+Platform%3A+$arch" - } else { - "https://github.com/xmake-io/xmake/releases/download/v$v/xmake-v$v.exe" - } + "https://github.com/xmake-io/xmake/releases/download/v$v/xmake-v$v.$winarch.exe" } else { "https://ci.appveyor.com/api/projects/waruqi/xmake/artifacts/xmake-installer.exe?branch=$v&pr=false&job=Image%3A+Visual+Studio+2017%3B+Platform%3A+$arch" } diff --git a/scripts/rpmbuild/SPECS/xmake.spec b/scripts/rpmbuild/SPECS/xmake.spec index 9887176bc..7c7d5ed38 100644 --- a/scripts/rpmbuild/SPECS/xmake.spec +++ b/scripts/rpmbuild/SPECS/xmake.spec @@ -1,4 +1,4 @@ -%define xmake_revision c44aea875ce6bde152a1bd2d92fec3fd9ca6b223 +%define xmake_revision fd248b8b97f62762ce6ea6e0008b4367bef29d4d %define tbox_revision 5ef932750ede0b90867fd4afdcf1deed2464c82b %define sv_revision 9a3cf7c8e589de4f70378824329882c4a047fffc %define lua_cjson_revision 515bab6d6d80b164b94db73af69609ea02f3a798 @@ -7,7 +7,7 @@ %undefine _disable_source_fetch Name: xmake -Version: 2.5.5 +Version: 2.5.6 Release: 1%{?dist} Summary: A cross-platform build utility based on Lua BuildArch: noarch diff --git a/tests/apis/add_allowedxxx/.gitignore b/tests/apis/add_allowedxxx/.gitignore new file mode 100644 index 000000000..152105761 --- /dev/null +++ b/tests/apis/add_allowedxxx/.gitignore @@ -0,0 +1,8 @@ +# Xmake cache +.xmake/ +build/ + +# MacOS Cache +.DS_Store + + diff --git a/tests/apis/add_allowedxxx/src/main.cpp b/tests/apis/add_allowedxxx/src/main.cpp new file mode 100644 index 000000000..7c435d251 --- /dev/null +++ b/tests/apis/add_allowedxxx/src/main.cpp @@ -0,0 +1,9 @@ +#include <iostream> + +using namespace std; + +int main(int argc, char** argv) +{ + cout << "hello world!" << endl; + return 0; +} diff --git a/tests/apis/add_allowedxxx/xmake.lua b/tests/apis/add_allowedxxx/xmake.lua new file mode 100644 index 000000000..e2f1f1ad9 --- /dev/null +++ b/tests/apis/add_allowedxxx/xmake.lua @@ -0,0 +1,83 @@ +add_rules("mode.debug", "mode.release") + +set_defaultmode("releasedbg") +set_defaultplat("linux") +set_defaultarchs("macosx|arm64", "linux|i386", "armv7") + +set_allowedmodes("releasedbg", "debug") +set_allowedplats("windows", "linux", "macosx") +set_allowedarchs("macosx|arm64", "macosx|x86_64", "linux|i386", "linux|x86_64") + +target("test") + set_kind("binary") + add_files("src/*.cpp") + +-- +-- If you want to known more usage about xmake, please see https://xmake.io +-- +-- ## FAQ +-- +-- You can enter the project directory firstly before building project. +-- +-- $ cd projectdir +-- +-- 1. How to build project? +-- +-- $ xmake +-- +-- 2. How to configure project? +-- +-- $ xmake f -p [macosx|linux|iphoneos ..] -a [x86_64|i386|arm64 ..] -m [debug|release] +-- +-- 3. Where is the build output directory? +-- +-- The default output directory is `./build` and you can configure the output directory. +-- +-- $ xmake f -o outputdir +-- $ xmake +-- +-- 4. How to run and debug target after building project? +-- +-- $ xmake run [targetname] +-- $ xmake run -d [targetname] +-- +-- 5. How to install target to the system directory or other output directory? +-- +-- $ xmake install +-- $ xmake install -o installdir +-- +-- 6. Add some frequently-used compilation flags in xmake.lua +-- +-- @code +-- -- add debug and release modes +-- add_rules("mode.debug", "mode.release") +-- +-- -- add macro defination +-- add_defines("NDEBUG", "_GNU_SOURCE=1") +-- +-- -- set warning all as error +-- set_warnings("all", "error") +-- +-- -- set language: c99, c++11 +-- set_languages("c99", "c++11") +-- +-- -- set optimization: none, faster, fastest, smallest +-- set_optimize("fastest") +-- +-- -- add include search directories +-- add_includedirs("/usr/include", "/usr/local/include") +-- +-- -- add link libraries and search directories +-- add_links("tbox") +-- add_linkdirs("/usr/local/lib", "/usr/lib") +-- +-- -- add system link libraries +-- add_syslinks("z", "pthread") +-- +-- -- add compilation and link flags +-- add_cxflags("-stdnolib", "-fno-strict-aliasing") +-- add_ldflags("-L/usr/local/lib", "-lpthread", {force = true}) +-- +-- @endcode +-- + diff --git a/tests/projects/other/autogen_code/.gitignore b/tests/projects/other/autogen_code/.gitignore new file mode 100644 index 000000000..152105761 --- /dev/null +++ b/tests/projects/other/autogen_code/.gitignore @@ -0,0 +1,8 @@ +# Xmake cache +.xmake/ +build/ + +# MacOS Cache +.DS_Store + + diff --git a/tests/projects/other/autogen_code/test.lua b/tests/projects/other/autogen_code/test.lua new file mode 100644 index 000000000..b57362078 --- /dev/null +++ b/tests/projects/other/autogen_code/test.lua @@ -0,0 +1,3 @@ +function main(t) + t:build() +end diff --git a/tests/projects/other/autogen_code/xmake.lua b/tests/projects/other/autogen_code/xmake.lua new file mode 100644 index 000000000..fb40d8e9c --- /dev/null +++ b/tests/projects/other/autogen_code/xmake.lua @@ -0,0 +1,20 @@ +add_rules("mode.debug", "mode.release") + +target("autogen_code") + set_kind("binary") + add_files("$(buildir)/autogen.cpp", {always_added = true}) + before_build(function (target) + io.writefile("$(buildir)/autogen.cpp", [[ +#include <iostream> + +using namespace std; + +int main(int argc, char** argv) +{ + cout << "hello world!" << endl; + return 0; +} + ]]) + end) + + diff --git a/tests/projects/other/bin2c/.gitignore b/tests/projects/other/bin2c/.gitignore new file mode 100644 index 000000000..152105761 --- /dev/null +++ b/tests/projects/other/bin2c/.gitignore @@ -0,0 +1,8 @@ +# Xmake cache +.xmake/ +build/ + +# MacOS Cache +.DS_Store + + diff --git a/tests/projects/other/bin2c/src/data.bin b/tests/projects/other/bin2c/src/data.bin new file mode 100644 index 000000000..5d26814ee --- /dev/null +++ b/tests/projects/other/bin2c/src/data.bin @@ -0,0 +1 @@ +hello xmake! diff --git a/tests/projects/other/bin2c/src/image.png b/tests/projects/other/bin2c/src/image.png new file mode 100644 index 000000000..d2c2e1ac6 --- /dev/null +++ b/tests/projects/other/bin2c/src/image.png @@ -0,0 +1 @@ +fake image diff --git a/tests/projects/other/bin2c/src/main.c b/tests/projects/other/bin2c/src/main.c new file mode 100644 index 000000000..31e416157 --- /dev/null +++ b/tests/projects/other/bin2c/src/main.c @@ -0,0 +1,16 @@ +#include <stdio.h> + +static unsigned char g_bin_data[] = { + #include "data.bin.h" +}; + +static unsigned char g_png_data[] = { + #include "image.png.h" +}; + +int main(int argc, char** argv) +{ + printf("data.bin: %s, size: %d\n", g_bin_data, (int)sizeof(g_bin_data)); + printf("image.png: %s, size: %d\n", g_png_data, (int)sizeof(g_png_data)); + return 0; +} diff --git a/tests/projects/other/bin2c/test.lua b/tests/projects/other/bin2c/test.lua new file mode 100644 index 000000000..b57362078 --- /dev/null +++ b/tests/projects/other/bin2c/test.lua @@ -0,0 +1,3 @@ +function main(t) + t:build() +end diff --git a/tests/projects/other/bin2c/xmake.lua b/tests/projects/other/bin2c/xmake.lua new file mode 100644 index 000000000..b5517a54e --- /dev/null +++ b/tests/projects/other/bin2c/xmake.lua @@ -0,0 +1,10 @@ +add_rules("mode.debug", "mode.release") + +target("test") + set_kind("binary") + add_rules("utils.bin2c", {linewidth = 16}) + add_files("src/*.c") + add_files("src/*.bin") + add_files("src/*.png", {rules = "utils.bin2c"}) + + diff --git a/tests/projects/vala/lua/src/main.vala b/tests/projects/vala/lua/src/main.vala new file mode 100644 index 000000000..8e8a32da0 --- /dev/null +++ b/tests/projects/vala/lua/src/main.vala @@ -0,0 +1,21 @@ +using Lua; + +static int my_func (LuaVM vm) { + stdout.printf ("Vala Code From Lua Code! (%f)\n", vm.to_number (1)); + return 1; +} + +static int main (string[] args) { + + string code = """ + print "Lua Code From Vala Code!" + my_func(33) + """; + + var vm = new LuaVM (); + vm.open_libs (); + vm.register ("my_func", my_func); + vm.do_string (code); + + return 0; +} diff --git a/tests/projects/vala/lua/xmake.lua b/tests/projects/vala/lua/xmake.lua new file mode 100644 index 000000000..df0cbeb89 --- /dev/null +++ b/tests/projects/vala/lua/xmake.lua @@ -0,0 +1,10 @@ +add_rules("mode.release", "mode.debug") + +add_requires("lua", "glib") + +target("test") + set_kind("binary") + add_rules("vala") + add_files("src/*.vala") + add_packages("lua", "glib") + add_values("vala.packages", "lua") diff --git a/xmake/actions/config/main.lua b/xmake/actions/config/main.lua index 68f8ab531..dcf5986dc 100644 --- a/xmake/actions/config/main.lua +++ b/xmake/actions/config/main.lua @@ -191,6 +191,52 @@ function _config_targets(targetname) end end +-- find default mode +function _find_default_mode() + local mode = config.mode() + if not mode then + mode = project.get("defaultmode") + if not mode then + mode = "release" + end + config.set("mode", mode) + end + return mode +end + +-- check configs +function _check_configs() + -- check allowed modes + local mode = config.mode() + local allowed_modes = project.allowed_modes() + if allowed_modes then + if not allowed_modes:has(mode) then + local allowed_modes_str = table.concat(allowed_modes:to_array(), ", ") + raise("`%s` is not a valid complation mode for this project, please use one of %s", mode, allowed_modes_str) + end + end + + -- check allowed plats + local plat = config.plat() + local allowed_plats = project.allowed_plats() + if allowed_plats then + if not allowed_plats:has(plat) then + local allowed_plats_str = table.concat(allowed_plats:to_array(), ", ") + raise("`%s` is not a valid platform for this project, please use one of %s", plat, allowed_plats_str) + end + end + + -- check allowed archs + local arch = config.arch() + local allowed_archs = project.allowed_archs(config.plat()) + if allowed_archs then + if not allowed_archs:has(arch) then + local allowed_archs_str = table.concat(allowed_archs:to_array(), ", ") + raise("`%s` is not a valid complation arch for this project, please use one of %s", arch, allowed_archs_str) + end + end +end + -- export configs function _export_configs() local exportfile = option.get("export") @@ -309,6 +355,10 @@ force to build in current directory via run `xmake -P .`]], os.projectdir()) end end + -- find default mode + local mode = _find_default_mode() + assert(mode == config.mode()) + -- find default platform and save to configuration local plat, arch = find_platform({global = true}) assert(plat == config.plat()) @@ -348,6 +398,9 @@ force to build in current directory via run `xmake -P .`]], os.projectdir()) -- only config for building project using third-party buildsystem if not trybuild then + -- check configs + _check_configs() + -- install and update packages local require_enable = option.boolean(option.get("require")) if (recheck or require_enable) then diff --git a/xmake/actions/config/menuconf.lua b/xmake/actions/config/menuconf.lua index 5657b30db..2f8706e4e 100644 --- a/xmake/actions/config/menuconf.lua +++ b/xmake/actions/config/menuconf.lua @@ -235,18 +235,23 @@ function app:_basic_configs(cache) local default = opt[4] local kind = (opt[3] == "k" or type(default) == "boolean") and "boolean" or "string" - -- get default platform + -- get default values if name == "plat" then default = find_platform() elseif name == "arch" then _, default = find_platform() + elseif name == "mode" then + default = project.get("defaultmode") + if not default then + default = "release" + end end -- choice option? local values = opt.values if values then if type(values) == "function" then - values = values() + values = values(false, {menuconf = true}) end for idx, value in ipairs(values) do if default == value then diff --git a/xmake/actions/config/xmake.lua b/xmake/actions/config/xmake.lua index 6b58698d6..67d0af595 100644 --- a/xmake/actions/config/xmake.lua +++ b/xmake/actions/config/xmake.lua @@ -18,201 +18,212 @@ -- @file xmake.lua -- --- define task -task("config") - - -- set category - set_category("action") +function _plat_values(complete, opt) + import("core.platform.platform") + import("core.base.hashset") + import("core.project.project") - -- on run - on_run("main") - - -- set menu - set_menu { - -- usage - usage = "xmake config|f [options] [target]" + if not complete or not opt.arch then + local plats = try {function () return project.allowed_plats() end} + if plats then + return plats:to_array() + end + return platform.plats() + end - -- description - , description = "Configure the project." + -- arch has given, find all supported platforms + local plats = {} + for _, plat in ipairs(platform.plats()) do + local archs = hashset.from(platform.archs(plat)) + if archs:has(opt.arch) then + table.insert(plats, plat) + end + end + return plats +end - -- xmake f - , shortname = 'f' +function _arch_values(complete, opt) + opt = opt or {} + if opt.helpmenu then + return + end - -- options - , options = - { - {'c', "clean", "k", nil , "Clean the cached configure and configure all again." } - , {nil, "export", "kv", nil , "Export the current configuration to the given file." - , " e.g." - , " - xmake f -m debug -xxx=y --export=build/config.txt" } - , {nil, "import", "kv", nil , "Import configuration from the given file." - , " e.g." - , " - xmake f -import=build/config.txt" } - , {nil, "menu", "k", nil , "Configure project with a menu-driven user interface." } - , {category = "."} - , {'p', "plat", "kv", "auto" , "Compile for the given platform." - , values = function (complete, opt) + -- imports + import("core.project.project") + import("core.platform.platform") + import("core.base.hashset") - -- imports - import("core.platform.platform") - import("core.base.hashset") + -- get all platforms + local plats = try {function () return project.allowed_plats() end} + if plats then + plats = plats:to_array() + end + plats = plats or platform.plats() - if not complete or not opt.arch then - return platform.plats() - end + -- get all architectures + local archset = hashset.new() + for _, plat in ipairs(opt.plat and { opt.plat } or plats) do + local archs = try {function () return project.allowed_archs(plat) end} + if archs then + archs = archs:to_array() + end + if not archs then + archs = platform.archs(plat) + end + if archs then + for _, arch in ipairs(archs) do + archset:insert(arch) + end + end + end + return archset:to_array() +end - -- arch has given, find all supported platforms - local plats = {} - for _, plat in ipairs(platform.plats()) do - local archs = hashset.from(platform.archs(plat)) - if archs:has(opt.arch) then - table.insert(plats, plat) - end - end - return plats - end } - , {'a', "arch", "kv", "auto" , "Compile for the given architecture.", - -- show the description of all architectures - function () +function _arch_description() + import("core.project.project") + import("core.platform.platform") - -- imports - import("core.platform.platform") + -- get all platforms + local plats = try {function () return project.allowed_plats() end} + if plats then + plats = plats:to_array() + end + plats = plats or platform.plats() - -- get all architectures - local description = {} - for i, plat in ipairs(platform.plats()) do - local archs = platform.archs(plat) - if archs then - description[i] = " - " .. plat .. ":" - for _, arch in ipairs(archs) do - description[i] = description[i] .. " " .. arch - end - end - end - return description - end - , values = function (complete, opt) - if not complete then return end + -- get all architectures + local description = {} + for i, plat in ipairs(plats) do + local archs = try {function () return project.allowed_archs(plat) end} + if archs then + archs = archs:to_array() + end + if not archs then + archs = platform.archs(plat) + end + if archs and #archs > 0 then + local desc = " - " .. plat .. ":" + for _, arch in ipairs(archs) do + desc = desc .. " " .. arch + end + table.insert(description, desc) + end + end + return description +end - -- imports - import("core.platform.platform") - import("core.base.hashset") +function _mode_values(complete, opt) + import("core.project.project") + opt = opt or {} + local modes = try {function() + if opt.menuconf then + -- we cannot load target.mode in menuconf + local allowed_modes = project.allowed_modes() + if allowed_modes then + return allowed_modes:to_array() + end + else + return project.modes() + end + end} + if not modes then + modes = {"debug", "release"} + end + return modes +end - -- get all architectures - local archset = hashset.new() - for _, plat in ipairs(opt.plat and { opt.plat } or platform.plats()) do - local archs = platform.archs(plat) - if archs then - for _, arch in ipairs(archs) do - archset:insert(arch) - end - end - end - return archset:to_array() - end } - , {'m', "mode", "kv", "release" , "Compile for the given mode." - , values = function (complete) - if complete then - local modes = (try { function() - return import("core.project.project").modes() - end }) or {"debug", "release"} - return modes - end - end } - , {'k', "kind", "kv", "static" , "Compile for the given target kind." - , values = {"static", "shared", "binary"} } - , {nil, "host", "kv", "$(host)" , "Set the current host environment." } +function _target_values(complete, opt) + return import("private.utils.complete_helper.targets")(complete, opt) +end - -- package configuration - , {category = "Package Configuration"} - , {nil, "require", "kv", nil , "Require all dependent packages?" - , values = function (complete) - if complete then - return {"yes", "no"} - else - return {"y: force to enable", "n: disable" } - end - end } - , {nil, "pkg_searchdirs", "kv", nil , "The search directories of the remote package." - , " e.g." - , " - xmake f --pkg_searchdirs=/dir1" .. path.envsep() .. "/dir2"} +function _toolchain_values(complete, opt) + if complete then + import("core.tool.toolchain") + return toolchain.list() + end +end - -- show project menu options - , function () +function _project_menu_options() + import("core.project.menu") + return menu.options() +end - -- import project menu - import("core.project.menu") +function _language_menu_options() + import("core.language.menu") + return menu.options("config") +end - -- get project menu options - return menu.options() - end +function _platform_menu_options() + import("core.platform.menu") + return menu.options("config") +end - , {category = "Cross Complation Configuration"} - , {nil, "cross", "kv", nil, "Set cross toolchains prefix" +task("config") + set_category("action") + on_run("main") + set_menu { + usage = "xmake config|f [options] [target]", + description = "Configure the project.", + shortname = 'f', + options = { + {'c', "clean", "k", nil , "Clean the cached configure and configure all again."}, + {nil, "export", "kv", nil , "Export the current configuration to the given file." + , " e.g." + , " - xmake f -m debug -xxx=y --export=build/config.txt"}, + {nil, "import", "kv", nil , "Import configuration from the given file." + , " e.g." + , " - xmake f -import=build/config.txt"}, + {nil, "menu", "k", nil , "Configure project with a menu-driven user interface."}, + {category = "."}, + {'p', "plat", "kv", "auto" , "Compile for the given platform.", values = _plat_values}, + {'a', "arch", "kv", "auto" , "Compile for the given architecture.", _arch_description, values = _arch_values}, + {'m', "mode", "kv", "auto" , "Compile for the given mode.", values = _mode_values}, + {'k', "kind", "kv", "static" , "Compile for the given target kind.", values = {"static", "shared", "binary"}}, + {nil, "host", "kv", "$(host)" , "Set the current host environment."}, + {category = "Package Configuration"}, + {nil, "require", "kv", nil , "Require all dependent packages?", values = {"yes", "no"}}, + {nil, "pkg_searchdirs", "kv", nil , "The search directories of the remote package." + , " e.g." + , " - xmake f --pkg_searchdirs=/dir1" .. path.envsep() .. "/dir2"}, + _project_menu_options, + {category = "Cross Complation Configuration"}, + {nil, "cross", "kv", nil, "Set cross toolchains prefix" , "e.g." , " - i386-mingw32-" - , " - arm-linux-androideabi-" } - , {nil, "target_os", "kv", nil, "Set target os only for cross-complation" } - , {nil, "bin", "kv", nil, "Set cross toolchains bin directory" + , " - arm-linux-androideabi-"}, + {nil, "target_os", "kv", nil, "Set target os only for cross-complation"}, + {nil, "bin", "kv", nil, "Set cross toolchains bin directory" , "e.g." - , " - sdk/bin (/arm-linux-gcc ..)" } - , {nil, "sdk", "kv", nil, "Set cross SDK directory" + , " - sdk/bin (/arm-linux-gcc ..)"}, + {nil, "sdk", "kv", nil, "Set cross SDK directory" , "e.g." , " - sdk/bin" , " - sdk/lib" - , " - sdk/include" } - , {nil, "toolchain", "kv", nil, "Set toolchain name" + , " - sdk/include"}, + {nil, "toolchain", "kv", nil, "Set toolchain name" , "e.g. " , " - xmake f --toolchain=clang" , " - xmake f --toolchain=[cross|llvm|sdcc ..] --sdk=/xxx" , " - run `xmake show -l toolchains` to get all toolchains" - , values = function (complete, opt) - if complete then - import("core.tool.toolchain") - return toolchain.list() - end - end } - - -- show language menu options - , function () - - -- import language menu - import("core.language.menu") - - -- get config menu options - return menu.options("config") - end - - -- show platform menu options - , function () - - -- import platform menu - import("core.platform.menu") - - -- get config menu options - return menu.options("config") - end - - , {category = "Other Configuration"} - , {nil, "debugger", "kv", "auto" , "Set debugger" } - , {nil, "ccache", "kv", true , "Enable or disable the c/c++ compiler cache." } - , {nil, "trybuild", "kv", nil , "Enable try-build mode and set the third-party buildsystem tool.", + , values = _toolchain_values}, + _language_menu_options, + _platform_menu_options, + {category = "Other Configuration"}, + {nil, "debugger", "kv", "auto" , "Set debugger"}, + {nil, "ccache", "kv", true , "Enable or disable the c/c++ compiler cache."}, + {nil, "trybuild", "kv", nil , "Enable try-build mode and set the third-party buildsystem tool.", "e.g.", " - xmake f --trybuild=auto; xmake", " - xmake f --trybuild=autotools -p android --ndk=xxx; xmake", "", "the third-party buildsystems:" - , values = {"auto", "make", "autotools", "cmake", "scons", "meson", "bazel", "ninja", "msbuild", "xcodebuild", "ndkbuild"}} - , {nil, "tryconfigs", "kv", nil , "Set the extra configurations of the third-party buildsystem for the try-build mode.", + , values = {"auto", "make", "autotools", "cmake", "scons", "meson", "bazel", "ninja", "msbuild", "xcodebuild", "ndkbuild"}}, + {nil, "tryconfigs", "kv", nil , "Set the extra configurations of the third-party buildsystem for the try-build mode.", "e.g.", - " - xmake f --trybuild=autotools --tryconfigs='--enable-shared=no'"} - , {'o', "buildir", "kv", "build" , "Set build directory." } - - , {} - , {nil, "target", "v" , nil , "Configure for the given target." - , values = function (complete, opt) return import("private.utils.complete_helper.targets")(complete, opt) end } - } - } + " - xmake f --trybuild=autotools --tryconfigs='--enable-shared=no'"}, + {'o', "buildir", "kv", "build" , "Set build directory."}, + {}, + {nil, "target", "v" , nil , "Configure for the given target." + , values = _target_values}}} diff --git a/xmake/actions/package/local/main.lua b/xmake/actions/package/local/main.lua index beaaa8862..21c807091 100644 --- a/xmake/actions/package/local/main.lua +++ b/xmake/actions/package/local/main.lua @@ -26,6 +26,19 @@ import("core.project.config") import("core.project.project") import("lib.luajit.bit") +-- get link deps +function _get_linkdeps(target) + local linkdeps = {} + for _, depname in ipairs(target:get("deps")) do + local dep = project.target(depname) + if not ((target:is_binary() or target:is_shared()) and dep:is_static()) then + table.join2(linkdeps, _get_linkdeps(dep)) + table.insert(linkdeps, dep:name()) + end + end + return linkdeps +end + -- package binary function _package_binary(target) @@ -48,10 +61,7 @@ function _package_binary(target) -- generate xmake.lua local file = io.open(path.join(packagedir, "xmake.lua"), "w") if file then - local deps = {} - for _, dep in ipairs(target:orderdeps()) do - table.insert(deps, dep:name()) - end + local deps = _get_linkdeps(target) file:print("package(\"%s\")", packagename) local homepage = option.get("homepage") if homepage then @@ -130,10 +140,7 @@ function _package_library(target) -- generate xmake.lua local file = io.open(path.join(packagedir, "xmake.lua"), "w") if file then - local deps = {} - for _, dep in ipairs(target:orderdeps()) do - table.insert(deps, dep:name()) - end + local deps = _get_linkdeps(target) file:print("package(\"%s\")", packagename) local homepage = option.get("homepage") if homepage then diff --git a/xmake/actions/update/main.lua b/xmake/actions/update/main.lua index 4bd4389cd..ed403f47a 100644 --- a/xmake/actions/update/main.lua +++ b/xmake/actions/update/main.lua @@ -311,8 +311,7 @@ function main() local winarch = os.arch() == "x64" and "win64" or "win32" if version:find('.', 1, true) then - mainurls = {format("https://ci.appveyor.com/api/projects/waruqi/xmake/artifacts/xmake-installer.exe?tag=%s&pr=false&job=Image%%3A+Visual+Studio+2017%%3B+Platform%%3A+%s", version, os.arch()), - format("https://github.com/xmake-io/xmake/releases/download/%s/xmake-%s.%s.exe", version, version, winarch), + mainurls = {format("https://github.com/xmake-io/xmake/releases/download/%s/xmake-%s.%s.exe", version, version, winarch), format("https://cdn.jsdelivr.net/gh/xmake-mirror/xmake-releases@%s/xmake-%s.%s.exe.zip", version, version, winarch), format("https://gitlab.com/xmake-mirror/xmake-releases/raw/%s/xmake-%s.%s.exe.zip", version, version, winarch)} else @@ -320,8 +319,7 @@ function main() local tags = fetchinfo.tags table.sort(tags) local latest_version = tags[#tags] or ("v" .. xmake.version():shortstr()) - mainurls = {format("https://ci.appveyor.com/api/projects/waruqi/xmake/artifacts/xmake-installer.exe?branch=%s&pr=false&job=Image%%3A+Visual+Studio+2017%%3B+Platform%%3A+%s", version, os.arch()), - format("https://github.com/xmake-io/xmake/releases/download/%s/xmake-%s.%s.exe", latest_version, version, winarch)} + mainurls = {format("https://github.com/xmake-io/xmake/releases/download/%s/xmake-%s.%s.exe", latest_version, version, winarch)} end -- re-sort mainurls diff --git a/xmake/core/base/option.lua b/xmake/core/base/option.lua index 539f3f637..6289cf05e 100644 --- a/xmake/core/base/option.lua +++ b/xmake/core/base/option.lua @@ -805,7 +805,7 @@ function option.show_options(options, taskname) -- append values local values = opt.values if type(values) == "function" then - values = values() + values = values(false, {helpmenu = true}) end if values then for _, value in ipairs(table.wrap(values)) do diff --git a/xmake/core/language/language.lua b/xmake/core/language/language.lua index 4815d47db..0b38769da 100644 --- a/xmake/core/language/language.lua +++ b/xmake/core/language/language.lua @@ -247,11 +247,7 @@ function language._interpreter() , "language.set_targetflags" } } - - -- save interpreter language._INTERPRETER = interp - - -- ok? return interp end @@ -313,11 +309,7 @@ function language.load(name) if not instance then return nil, errors end - - -- save instance to the cache language._LANGUAGES[name] = instance - - -- ok return instance end @@ -347,16 +339,10 @@ function language.load_sk(sourcekind) break end end - - -- not found? if not result then return nil, string.format("unknown language sourcekind: %s", sourcekind) end - - -- cache this language language._LANGUAGES_OF_SK[sourcekind] = result - - -- ok return result end @@ -386,45 +372,37 @@ function language.load_ex(extension) break end end - - -- not found? if not result then return nil, string.format("unknown language source extension: %s", extension) end - - -- cache this language language._LANGUAGES_OF_EX[extension] = result - - -- ok return result end -- load the language apis function language.apis() - - -- load all languages - local languages, errors = language.load() - if not languages then - os.raise(errors) - end - - -- merge apis for each language - local apis = {values = {}, paths = {}, custom = {}, dictionary = {}} - for name, instance in pairs(languages) do - local instance_apis = instance:get("apis") - if instance_apis then - table.join2(apis.values, table.wrap(instance_apis.values)) - table.join2(apis.paths, table.wrap(instance_apis.paths)) - table.join2(apis.custom, table.wrap(instance_apis.custom)) - table.join2(apis.dictionary, table.wrap(instance_apis.dictionary)) + local apis = language._APIS + if not apis then + local languages, errors = language.load() + if not languages then + os.raise(errors) + end + apis = {values = {}, paths = {}, custom = {}, dictionary = {}} + for name, instance in pairs(languages) do + local instance_apis = instance:get("apis") + if instance_apis then + table.join2(apis.values, table.wrap(instance_apis.values)) + table.join2(apis.paths, table.wrap(instance_apis.paths)) + table.join2(apis.custom, table.wrap(instance_apis.custom)) + table.join2(apis.dictionary, table.wrap(instance_apis.dictionary)) + end end + apis.values = table.unique(apis.values) + apis.paths = table.unique(apis.paths) + apis.custom = table.unique(apis.custom) + language._APIS = apis end - apis.values = table.unique(apis.values) - apis.paths = table.unique(apis.paths) - apis.custom = table.unique(apis.custom) - - -- ok return apis end @@ -443,28 +421,18 @@ end -- } -- function language.extensions() - - -- attempt to get it from cache - if language._EXTENSIONS then - return language._EXTENSIONS - end - - -- load all languages - local languages, errors = language.load() - if not languages then - os.raise(errors) - end - - -- merge all for each language - local extensions = {} - for name, instance in pairs(languages) do - table.join2(extensions, instance:extensions()) + local extensions = language._EXTENSIONS + if not extensions then + local languages, errors = language.load() + if not languages then + os.raise(errors) + end + extensions = {} + for name, instance in pairs(languages) do + table.join2(extensions, instance:extensions()) + end + language._EXTENSIONS = extensions end - - -- cache it - language._EXTENSIONS = extensions - - -- ok return extensions end @@ -482,28 +450,18 @@ end -- } -- function language.sourcekinds() - - -- attempt to get it from cache - if language._SOURCEKINDS then - return language._SOURCEKINDS - end - - -- load all languages - local languages, errors = language.load() - if not languages then - os.raise(errors) - end - - -- merge all for each language - local sourcekinds = {} - for name, instance in pairs(languages) do - table.join2(sourcekinds, instance:sourcekinds()) + local sourcekinds = language._SOURCEKINDS + if not sourcekinds then + local languages, errors = language.load() + if not languages then + os.raise(errors) + end + sourcekinds = {} + for name, instance in pairs(languages) do + table.join2(sourcekinds, instance:sourcekinds()) + end + language._SOURCEKINDS = sourcekinds end - - -- cache it - language._SOURCEKINDS = sourcekinds - - -- ok return sourcekinds end @@ -518,28 +476,18 @@ end -- } -- function language.sourceflags() - - -- attempt to get it from cache - if language._SOURCEFLAGS then - return language._SOURCEFLAGS - end - - -- load all languages - local languages, errors = language.load() - if not languages then - os.raise(errors) - end - - -- merge all for each language - local sourceflags = {} - for name, instance in pairs(languages) do - table.join2(sourceflags, instance:sourceflags()) + local sourceflags = language._SOURCEFLAGS + if not sourceflags then + local languages, errors = language.load() + if not languages then + os.raise(errors) + end + sourceflags = {} + for name, instance in pairs(languages) do + table.join2(sourceflags, instance:sourceflags()) + end + language._SOURCEFLAGS = sourceflags end - - -- cache it - language._SOURCEFLAGS = sourceflags - - -- ok return sourceflags end @@ -560,21 +508,15 @@ function language.sourcekind_of(sourcefile) if not sourcekind then return nil, string.format("%s is unknown extension", extension) end - - -- ok return sourcekind end -- get extension of the source kind function language.extension_of(sourcekind) - - -- get extension local extension = table.wrap(language.sourcekinds()[sourcekind])[1] if not extension then return nil, string.format("%s is unknown source kind", sourcekind) end - - -- ok return extension end @@ -615,8 +557,6 @@ function language.linkerinfos_of(targetkind, sourcekinds) end end end - - -- cache it language._LINKERINFOS = linkerinfos end @@ -654,34 +594,24 @@ end -- } -- function language.targetkinds() - - -- attempt to get it from cache - if language._TARGETKINDS then - return language._TARGETKINDS - end - - -- load all languages - local languages, errors = language.load() - if not languages then - os.raise(errors) - end - - -- merge all for each language - local targetkinds = {} - for name, instance in pairs(languages) do - for targetkind, linkerkind in pairs(table.wrap(instance:kinds())) do - targetkinds[targetkind] = targetkinds[targetkind] or {} - table.insert(targetkinds[targetkind], linkerkind) + local targetkinds = language._TARGETKINDS + if not targetkinds then + local languages, errors = language.load() + if not languages then + os.raise(errors) end + targetkinds = {} + for name, instance in pairs(languages) do + for targetkind, linkerkind in pairs(table.wrap(instance:kinds())) do + targetkinds[targetkind] = targetkinds[targetkind] or {} + table.insert(targetkinds[targetkind], linkerkind) + end + end + for targetkind, linkerkinds in pairs(targetkinds) do + targetkinds[targetkind] = table.unique(linkerkinds) + end + language._TARGETKINDS = targetkinds end - for targetkind, linkerkinds in pairs(targetkinds) do - targetkinds[targetkind] = table.unique(linkerkinds) - end - - -- cache it - language._TARGETKINDS = targetkinds - - -- ok return targetkinds end @@ -702,30 +632,19 @@ end -- } -- function language.langkinds() - - -- attempt to get it from cache - if language._LANGKINDS then - return language._LANGKINDS - end - - -- load all languages - local languages, errors = language.load() - if not languages then - os.raise(errors) - end - - -- merge all for each language - local langkinds = {} - for name, instance in pairs(languages) do - table.join2(langkinds, instance:langkinds()) + local langkinds = language._LANGKINDS + if not langkinds then + local languages, errors = language.load() + if not languages then + os.raise(errors) + end + langkinds = {} + for name, instance in pairs(languages) do + table.join2(langkinds, instance:langkinds()) + end + language._LANGKINDS = langkinds end - - -- cache it - language._LANGKINDS = langkinds - - -- ok return langkinds end --- return module return language diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index 1e3d2172b..28473c2bf 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -463,6 +463,10 @@ end -- is cross-compilation? function _instance:is_cross() + if self:is_plat("windows") and os.host() == "windows" then + -- always false on windows host + return false + end if not self:is_plat(os.host()) and not self:is_plat(os.subhost()) then return true end diff --git a/xmake/core/project/deprecated/project.lua b/xmake/core/project/deprecated/project.lua index 91a38106a..dceeac9ba 100644 --- a/xmake/core/project/deprecated/project.lua +++ b/xmake/core/project/deprecated/project.lua @@ -33,24 +33,6 @@ local platform = require("platform/platform") local deprecated = require("base/deprecated") local deprecated_interpreter = require("base/deprecated/interpreter") --- set modes -function deprecated_project._api_set_modes(interp, ...) - - -- get api function - local apifunc = interp:api_func("set_modes") - assert(apifunc) - - -- register api - interp:api_register_builtin("set_modes", function (...) - - -- deprecated - deprecated.add("add_rules(\"mode.debug\", \"mode.release\")", "set_modes(\"debug\", \"release\")") - - -- dispatch it - apifunc(...) - end) -end - -- add_headers for target function deprecated_project._api_target_add_headers(interp) @@ -159,37 +141,9 @@ function deprecated_project._api_target_add_tools(interp) end) end --- enable options? -function deprecated_project._api_is_option(interp, ...) - - -- make values - local values = "" - for _, v in ipairs(table.join(...)) do - if v and type(v) == "string" then - if #values == 0 then - values = v - else - values = values .. ", " .. v - end - end - end - - -- deprecated - deprecated.add("has_config(\"%s\")", "is_option(\"%s\")", values) - - -- done - return config.has(...) -end - -- register api function deprecated_project.api_register(interp) - -- register api: is_option() to root - interp:api_register(nil, "is_option", deprecated_project._api_is_option) - - -- register api: set_modes() to root - deprecated_project._api_set_modes(interp) - -- register api: add_headers() to target deprecated_project._api_target_add_headers(interp) diff --git a/xmake/core/project/option.lua b/xmake/core/project/option.lua index a92f8922f..93d25990f 100644 --- a/xmake/core/project/option.lua +++ b/xmake/core/project/option.lua @@ -175,7 +175,14 @@ function _instance:_check() end -- trace - utils.cprint("checking for %s ... %s", name, self:enabled() and "${color.success}${text.success}" or "${color.nothing}${text.nothing}") + local result + if self:enabled() then + local value = self:value() + result = "${color.success}" .. (type(value) == "boolean" and "${text.success}" or tostring(value)) + else + result = "${color.nothing}${text.nothing}" + end + utils.cprint("checking for %s ... %s", name, result) if not ok then os.raise(errors) end diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua index 9bdb4ca4d..3ff962d7c 100644 --- a/xmake/core/project/project.lua +++ b/xmake/core/project/project.lua @@ -30,6 +30,7 @@ local utils = require("base/utils") local table = require("base/table") local global = require("base/global") local process = require("base/process") +local hashset = require("base/hashset") local deprecated = require("base/deprecated") local interpreter = require("base/interpreter") local memcache = require("cache/memcache") @@ -378,13 +379,13 @@ function project._load_targets() local requires = project.required_packages() local ok, errors = project._load(true) if not ok then - return nil, errors + return nil, nil, errors end -- load targets local results, errors = project._load_scope("target", true, true) if not results then - return nil, errors + return nil, nil, errors end -- make targets @@ -445,7 +446,7 @@ function project._load_targets() table.insert(t._ORDERULES, r) end else - return nil, string.format("unknown rule(%s) in target(%s)!", rulename, t:name()) + return nil, nil, string.format("unknown rule(%s) in target(%s)!", rulename, t:name()) end end end @@ -650,8 +651,13 @@ function project.apis() { -- set_xxx "set_project" - , "set_modes" -- TODO deprecated , "set_description" + , "set_allowedmodes" + , "set_allowedplats" + , "set_allowedarchs" + , "set_defaultmode" + , "set_defaultplat" + , "set_defaultarchs" -- add_xxx , "add_requires" , "add_requireconfs" @@ -1079,20 +1085,6 @@ function project.mtimes() return project.interpreter():mtimes() end --- get the project modes -function project.modes() - local modes = project.get("modes") or {} - for _, target in pairs(table.wrap(project.targets())) do - for _, rule in ipairs(target:orderules()) do - local name = rule:name() - if name:startswith("mode.") then - table.insert(modes, name:sub(6)) - end - end - end - return table.unique(modes) -end - -- get the project menu function project.menu() @@ -1209,5 +1201,112 @@ function project.tmpfile(opt_or_key) return path.join(project.tmpdir(opt), "_" .. (hash.uuid4(key):gsub("-", ""))) end +-- get all modes +function project.modes() + local modes + local allowed_modes = project.allowed_modes() + if allowed_modes then + modes = allowed_modes:to_array() + else + modes = {} + for _, target in pairs(table.wrap(project.targets())) do + for _, rule in ipairs(target:orderules()) do + local name = rule:name() + if name:startswith("mode.") then + table.insert(modes, name:sub(6)) + end + end + end + modes = table.unique(modes) + end + return modes +end + +-- get default architectures from the given platform +-- +-- set_defaultarchs("linux|x86_64", "iphoneos|arm64") +-- +function project.default_arch(plat) + local default_archs = project._memcache():get("defaultarchs") + if not default_archs then + default_archs = {} + for _, defaultarch in ipairs(table.wrap(project.get("defaultarchs"))) do + local splitinfo = defaultarch:split('|') + if #splitinfo == 2 then + default_archs[splitinfo[1]] = splitinfo[2] + elseif #splitinfo == 1 and not default_archs.default then + default_archs.default = defaultarch + end + end + project._memcache():set("defaultarchs", default_archs or false) + end + return default_archs[plat or "default"] or default_archs["default"] +end + +-- get allowed modes +-- +-- set_allowedmodes("releasedbg", "debug") +-- +function project.allowed_modes() + local allowed_modes_set = project._memcache():get("allowedmodes") + if not allowed_modes_set then + local allowed_modes = table.wrap(project.get("allowedmodes")) + if #allowed_modes > 0 then + allowed_modes_set = hashset.from(allowed_modes) + end + project._memcache():set("allowedmodes", allowed_modes_set or false) + end + return allowed_modes_set or nil +end + +-- get allowed platforms +-- +-- set_allowedplats("windows", "mingw", "linux", "macosx") +-- +function project.allowed_plats() + local allowed_plats_set = project._memcache():get("allowedplats") + if not allowed_plats_set then + local allowed_plats = table.wrap(project.get("allowedplats")) + if #allowed_plats > 0 then + allowed_plats_set = hashset.from(allowed_plats) + end + project._memcache():set("allowedplats", allowed_plats_set or false) + end + return allowed_plats_set or nil +end + +-- get allowed architectures +-- +-- set_allowedarchs("macosx|arm64", "macosx|x86_64", "linux|i386") +-- +function project.allowed_archs(plat) + plat = plat or "" + local allowed_archs_set = project._memcache():get2("allowedarchs", plat) + if not allowed_archs_set then + local allowed_archs = table.wrap(project.get("allowedarchs")) + if #allowed_archs > 0 then + for _, allowed_arch in ipairs(allowed_archs) do + local splitinfo = allowed_arch:split('|') + local splitplat, splitarch + if #splitinfo == 2 then + splitplat = splitinfo[1] + splitarch = splitinfo[2] + elseif #splitinfo == 1 then + splitplat = "" + splitarch = allowed_arch + end + if plat == splitplat then + if not allowed_archs_set then + allowed_archs_set = hashset.new() + end + allowed_archs_set:insert(splitarch) + end + end + end + project._memcache():set2("allowedarchs", plat, allowed_archs_set or false) + end + return allowed_archs_set or nil +end + -- return module: project return project diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index 38d207656..3eed0cdad 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -1232,6 +1232,18 @@ function _instance:sourcefiles() results = os.dirs(file) end end + + -- Even if the current source file does not exist yet, we always add it. + -- This is usually used for some rules that automatically generate code files, + -- because they ensure that the code files have been generated before compilation. + -- + -- @see https://github.com/xmake-io/xmake/issues/1540 + -- + -- e.g. add_files("src/test.c", {always_added = true}) + -- + if #results == 0 and self:extraconf("files", file, "always_added") then + results = {file} + end end targetcache:set2("sourcefiles", file, results) end @@ -1545,30 +1557,18 @@ end -- e.g. cc cxx mm mxx as ... -- function _instance:sourcekinds() - - -- cached? return it directly - if self._SOURCEKINDS then - return self._SOURCEKINDS - end - - -- make source kinds - local sourcekinds = {} - for _, sourcefile in pairs(self:sourcefiles()) do - - -- get source kind - local sourcekind = self:sourcekind_of(sourcefile) - if sourcekind then - table.insert(sourcekinds, sourcekind) + local sourcekinds = self._SOURCEKINDS + if not sourcekinds then + sourcekinds = {} + for _, sourcefile in pairs(self:sourcefiles()) do + local sourcekind = self:sourcekind_of(sourcefile) + if sourcekind then + table.insert(sourcekinds, sourcekind) + end end + sourcekinds = table.unique(sourcekinds) + self._SOURCEKINDS = sourcekinds end - - -- remove repeat - sourcekinds = table.unique(sourcekinds) - - -- cache it - self._SOURCEKINDS = sourcekinds - - -- ok? return sourcekinds end diff --git a/xmake/core/sandbox/modules/import/core/project/project.lua b/xmake/core/sandbox/modules/import/core/project/project.lua index dcd78b205..8e50dfb24 100644 --- a/xmake/core/sandbox/modules/import/core/project/project.lua +++ b/xmake/core/sandbox/modules/import/core/project/project.lua @@ -53,6 +53,10 @@ sandbox_core_project.rcfiles = project.rcfiles sandbox_core_project.directory = project.directory sandbox_core_project.name = project.name sandbox_core_project.modes = project.modes +sandbox_core_project.default_arch = project.default_arch +sandbox_core_project.allowed_modes = project.allowed_modes +sandbox_core_project.allowed_plats = project.allowed_plats +sandbox_core_project.allowed_archs = project.allowed_archs sandbox_core_project.mtimes = project.mtimes sandbox_core_project.version = project.version sandbox_core_project.required_package = project.required_package diff --git a/xmake/languages/asm/api.lua b/xmake/languages/asm/api.lua deleted file mode 100644 index 49bda6a36..000000000 --- a/xmake/languages/asm/api.lua +++ /dev/null @@ -1,92 +0,0 @@ ---!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 api.lua --- - --- get apis -function apis() - - -- init apis - _g.values = - { - -- target.add_xxx - "target.add_links" - , "target.add_syslinks" - , "target.add_asflags" - , "target.add_ldflags" - , "target.add_arflags" - , "target.add_shflags" - , "target.add_defines" - , "target.add_undefines" - , "target.add_rpathdirs" -- @note do not translate path, it's usually an absolute path or contains $ORIGIN/@loader_path - -- option.add_xxx - , "option.add_links" - , "option.add_syslinks" - , "option.add_asflags" - , "option.add_ldflags" - , "option.add_arflags" - , "option.add_shflags" - , "option.add_defines" - , "option.add_undefines" - , "option.add_rpathdirs" - -- package.add_xxx - , "package.add_links" - , "package.add_syslinks" - , "package.add_asflags" - , "package.add_ldflags" - , "package.add_arflags" - , "package.add_shflags" - , "package.add_defines" - , "package.add_undefines" - , "package.add_rpathdirs" - , "package.add_linkdirs" - , "package.add_includedirs" - , "package.add_sysincludedirs" - -- toolchain.add_xxx - , "toolchain.add_links" - , "toolchain.add_syslinks" - , "toolchain.add_cflags" - , "toolchain.add_ldflags" - , "toolchain.add_arflags" - , "toolchain.add_shflags" - , "toolchain.add_defines" - , "toolchain.add_undefines" - , "toolchain.add_rpathdirs" - , "toolchain.add_linkdirs" - , "toolchain.add_includedirs" - , "toolchain.add_sysincludedirs" - } - _g.paths = - { - -- target.add_xxx - "target.add_headers" -- TODO deprecated - , "target.add_headerfiles" - , "target.add_linkdirs" - , "target.add_includedirs" - , "target.add_sysincludedirs" - -- option.add_xxx - , "option.add_linkdirs" - , "option.add_includedirs" - , "option.add_sysincludedirs" - } - - -- ok - return _g -end - - diff --git a/xmake/languages/asm/load.lua b/xmake/languages/asm/load.lua index fd547b488..9fe4681f4 100644 --- a/xmake/languages/asm/load.lua +++ b/xmake/languages/asm/load.lua @@ -18,17 +18,73 @@ -- @file load.lua -- --- imports -import("api") +function _get_apis() + local apis = {} + apis.values = { + -- target.add_xxx + "target.add_links" + , "target.add_syslinks" + , "target.add_asflags" + , "target.add_ldflags" + , "target.add_arflags" + , "target.add_shflags" + , "target.add_defines" + , "target.add_undefines" + , "target.add_rpathdirs" -- @note do not translate path, it's usually an absolute path or contains $ORIGIN/@loader_path + -- option.add_xxx + , "option.add_links" + , "option.add_syslinks" + , "option.add_asflags" + , "option.add_ldflags" + , "option.add_arflags" + , "option.add_shflags" + , "option.add_defines" + , "option.add_undefines" + , "option.add_rpathdirs" + -- package.add_xxx + , "package.add_links" + , "package.add_syslinks" + , "package.add_asflags" + , "package.add_ldflags" + , "package.add_arflags" + , "package.add_shflags" + , "package.add_defines" + , "package.add_undefines" + , "package.add_rpathdirs" + , "package.add_linkdirs" + , "package.add_includedirs" + , "package.add_sysincludedirs" + -- toolchain.add_xxx + , "toolchain.add_links" + , "toolchain.add_syslinks" + , "toolchain.add_cflags" + , "toolchain.add_ldflags" + , "toolchain.add_arflags" + , "toolchain.add_shflags" + , "toolchain.add_defines" + , "toolchain.add_undefines" + , "toolchain.add_rpathdirs" + , "toolchain.add_linkdirs" + , "toolchain.add_includedirs" + , "toolchain.add_sysincludedirs" + } + apis.paths = { + -- target.add_xxx + "target.add_headers" -- TODO deprecated + , "target.add_headerfiles" + , "target.add_linkdirs" + , "target.add_includedirs" + , "target.add_sysincludedirs" + -- option.add_xxx + , "option.add_linkdirs" + , "option.add_includedirs" + , "option.add_sysincludedirs" + } + return apis +end --- load it function main() - - -- init apis - _g.apis = api.apis() - - -- ok - return _g + return {apis = _get_apis()} end diff --git a/xmake/languages/asm/xmake.lua b/xmake/languages/asm/xmake.lua index a57790027..cb9aa22f5 100644 --- a/xmake/languages/asm/xmake.lua +++ b/xmake/languages/asm/xmake.lua @@ -18,38 +18,19 @@ -- @file xmake.lua -- --- define language language("asm") - - -- set source file kinds + add_rules("asm") set_sourcekinds {as = {".s", ".asm"}} - - -- set source file flags set_sourceflags {as = "asflags"} - - -- set target kinds set_targetkinds {binary = "ld", static = "ar", shared = "sh"} - - -- set target flags set_targetflags {binary = "ldflags", static = "arflags", shared = "shflags"} - - -- set language kinds - set_langkinds {as = "as"} - - -- set mixing kinds + set_langkinds {as = "as"} set_mixingkinds("as") - -- add rules - add_rules("asm") - - -- on load on_load("load") - -- set name flags - set_nameflags - { - object = - { + set_nameflags { + object = { "config.includedirs" , "target.symbols" , "target.warnings" @@ -65,8 +46,7 @@ language("asm") , "target.sysincludedirs" , "toolchain.sysincludedirs" } - , binary = - { + , binary = { "config.linkdirs" , "target.linkdirs" , "target.rpathdirs" @@ -78,8 +58,7 @@ language("asm") , "target.links" , "toolchain.links" } - , shared = - { + , shared = { "config.linkdirs" , "target.linkdirs" , "target.strip" @@ -92,14 +71,12 @@ language("asm") , "target.syslinks" , "toolchain.syslinks" } - , static = - { + , static = { "target.strip" , "target.symbols" } } - -- set menu set_menu { config = { diff --git a/xmake/languages/c++/api.lua b/xmake/languages/c++/api.lua deleted file mode 100644 index e3e8e7041..000000000 --- a/xmake/languages/c++/api.lua +++ /dev/null @@ -1,266 +0,0 @@ ---!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 api.lua --- - --- get function name and function info --- --- sigsetjmp --- sigsetjmp((void*)0, 0) --- sigsetjmp{sigsetjmp((void*)0, 0);} --- sigsetjmp{int a = 0; sigsetjmp((void*)a, a);} --- -function _funcinfo(func) - - -- parse name and code - local name, code = string.match(func, "(.+){(.+)}") - if code == nil then - local pos = func:find("%(") - if pos then - name = func:sub(1, pos - 1) - code = func - else - name = func - code = string.format("volatile void* p%s = (void*)&%s;", name, name) - end - end - - -- ok - return name:trim(), code -end - --- TODO add c function, deprecated -function _api_add_cfunc(interp, module, alias, links, includes, func) - - -- parse the function info - local funcname, funccode = _funcinfo(func) - - -- make the option name - local name = nil - if module ~= nil then - name = format("__%s_%s", module, funcname) - else - name = format("__%s", funcname) - end - - -- uses the alias name - if alias ~= nil then - funcname = alias - end - - -- make the option define - local define = nil - if module ~= nil then - define = format("$(prefix)_%s_HAVE_%s", module:upper(), funcname:upper()) - else - define = format("$(prefix)_HAVE_%s", funcname:upper()) - end - - -- save the current scope - local scope = interp:scope_save() - - -- check option - interp:api_call("option", name) - interp:api_call("set_category", "cfuncs") - interp:api_call("add_cfuncs", func) - if links then interp:api_call("add_links", links) end - if includes then interp:api_call("add_cincludes", includes) end - - -- restore the current scope - interp:scope_restore(scope) - - -- add this option - interp:api_call("add_options", name) -end - --- TODO add c functions, deprecated -function _api_add_cfuncs(interp, module, links, includes, ...) - - -- done - for _, func in ipairs({...}) do - _api_add_cfunc(interp, module, nil, links, includes, func) - end -end - --- TODO add c++ function, deprecated -function _api_add_cxxfunc(interp, module, alias, links, includes, func) - - -- parse the function info - local funcname, funccode = _funcinfo(func) - - -- make the option name - local name = nil - if module ~= nil then - name = format("__%s_%s", module, funcname) - else - name = format("__%s", funcname) - end - - -- uses the alias name - if alias ~= nil then - funcname = alias - end - - -- make the option define - local define = nil - if module ~= nil then - define = format("$(prefix)_%s_HAVE_%s", module:upper(), funcname:upper()) - else - define = format("$(prefix)_HAVE_%s", funcname:upper()) - end - - -- save the current scope - local scope = interp:scope_save() - - -- check option - interp:api_call("option", name) - interp:api_call("set_category", "cxxfuncs") - interp:api_call("add_cxxfuncs", func) - if links then interp:api_call("add_links", links) end - if includes then interp:api_call("add_cxxincludes", includes) end - - -- restore the current scope - interp:scope_restore(scope) - - -- add this option - interp:api_call("add_options", name) -end - --- TODO add c++ functions, deprecated -function _api_add_cxxfuncs(interp, module, links, includes, ...) - - -- done - for _, func in ipairs({...}) do - _api_add_cxxfunc(interp, module, nil, links, includes, func) - end -end - - --- get apis -function apis() - - -- init apis - _g.values = - { - -- target.add_xxx - "target.add_links" - , "target.add_syslinks" - , "target.add_cflags" - , "target.add_cxflags" - , "target.add_cxxflags" - , "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 - -- 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" - , "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_cxxflags" - , "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_cxxflags" - , "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" - } - _g.paths = - { - -- target.set_xxx - "target.set_headerdir" -- TODO deprecated - , "target.set_config_header" -- TODO deprecated - , "target.set_pcheader" - , "target.set_pcxxheader" - -- target.add_xxx - , "target.add_headers" -- TODO deprecated - , "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" - } - _g.dictionary = - { - -- option.add_xxx - "option.add_csnippets" - , "option.add_cxxsnippets" - } - _g.custom = - { - -- target.add_xxx - {"target.add_cfunc", _api_add_cfunc } - , {"target.add_cfuncs", _api_add_cfuncs } - , {"target.add_cxxfunc", _api_add_cxxfunc } - , {"target.add_cxxfuncs", _api_add_cxxfuncs } - } - - -- ok - return _g -end - - diff --git a/xmake/languages/c++/load.lua b/xmake/languages/c++/load.lua index fd547b488..12fb5283b 100644 --- a/xmake/languages/c++/load.lua +++ b/xmake/languages/c++/load.lua @@ -18,17 +18,239 @@ -- @file load.lua -- --- imports -import("api") +-- get function name and function info +-- +-- sigsetjmp +-- sigsetjmp((void*)0, 0) +-- sigsetjmp{sigsetjmp((void*)0, 0);} +-- sigsetjmp{int a = 0; sigsetjmp((void*)a, a);} +-- +function _funcinfo(func) + local name, code = string.match(func, "(.+){(.+)}") + if code == nil then + local pos = func:find("%(") + if pos then + name = func:sub(1, pos - 1) + code = func + else + name = func + code = string.format("volatile void* p%s = (void*)&%s;", name, name) + end + end + return name:trim(), code +end --- load it -function main() +-- TODO add c function, deprecated +function _api_add_cfunc(interp, module, alias, links, includes, func) + + -- parse the function info + local funcname, funccode = _funcinfo(func) + + -- make the option name + local name = nil + if module ~= nil then + name = format("__%s_%s", module, funcname) + else + name = format("__%s", funcname) + end + + -- uses the alias name + if alias ~= nil then + funcname = alias + end + + -- make the option define + local define = nil + if module ~= nil then + define = format("$(prefix)_%s_HAVE_%s", module:upper(), funcname:upper()) + else + define = format("$(prefix)_HAVE_%s", funcname:upper()) + end + + -- save the current scope + local scope = interp:scope_save() + + -- check option + interp:api_call("option", name) + interp:api_call("set_category", "cfuncs") + interp:api_call("add_cfuncs", func) + if links then interp:api_call("add_links", links) end + if includes then interp:api_call("add_cincludes", includes) end + + -- restore the current scope + interp:scope_restore(scope) + + -- add this option + interp:api_call("add_options", name) +end + +-- TODO add c functions, deprecated +function _api_add_cfuncs(interp, module, links, includes, ...) + wprint("target.add_cfuncs is deprecated, please use option.add_cfuncs()") + for _, func in ipairs({...}) do + _api_add_cfunc(interp, module, nil, links, includes, func) + end +end - -- init apis - _g.apis = api.apis() +-- TODO add c++ function, deprecated +function _api_add_cxxfunc(interp, module, alias, links, includes, func) - -- ok - return _g + -- parse the function info + local funcname, funccode = _funcinfo(func) + + -- make the option name + local name = nil + if module ~= nil then + name = format("__%s_%s", module, funcname) + else + name = format("__%s", funcname) + end + + -- uses the alias name + if alias ~= nil then + funcname = alias + end + + -- make the option define + local define = nil + if module ~= nil then + define = format("$(prefix)_%s_HAVE_%s", module:upper(), funcname:upper()) + else + define = format("$(prefix)_HAVE_%s", funcname:upper()) + end + + -- save the current scope + local scope = interp:scope_save() + + -- check option + interp:api_call("option", name) + interp:api_call("set_category", "cxxfuncs") + interp:api_call("add_cxxfuncs", func) + if links then interp:api_call("add_links", links) end + if includes then interp:api_call("add_cxxincludes", includes) end + + -- restore the current scope + interp:scope_restore(scope) + + -- add this option + interp:api_call("add_options", name) +end + +-- TODO add c++ functions, deprecated +function _api_add_cxxfuncs(interp, module, links, includes, ...) + wprint("target.add_cxxfuncs is deprecated, please use option.add_cxxfuncs()") + for _, func in ipairs({...}) do + _api_add_cxxfunc(interp, module, nil, links, includes, func) + end +end + +-- 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_cxxflags" + , "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 + -- 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" + , "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_cxxflags" + , "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_cxxflags" + , "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.paths = { + -- target.set_xxx + "target.set_headerdir" -- TODO deprecated + , "target.set_config_header" -- TODO deprecated + , "target.set_pcheader" + , "target.set_pcxxheader" + -- target.add_xxx + , "target.add_headers" -- TODO deprecated + , "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" + , "option.add_cxxsnippets" + } + apis.custom = { + -- target.add_xxx + {"target.add_cfunc", _api_add_cfunc } + , {"target.add_cfuncs", _api_add_cfuncs } + , {"target.add_cxxfunc", _api_add_cxxfunc } + , {"target.add_cxxfuncs", _api_add_cxxfuncs } + } + return apis +end + +function main() + return {apis = _get_apis()} end diff --git a/xmake/languages/c++/xmake.lua b/xmake/languages/c++/xmake.lua index 4a18dc5df..52c7baa91 100644 --- a/xmake/languages/c++/xmake.lua +++ b/xmake/languages/c++/xmake.lua @@ -18,41 +18,20 @@ -- @file xmake.lua -- --- define language language("c++") - - -- set source file kinds + add_rules("c++") set_sourcekinds {cc = ".c", cxx = {".cpp", ".cc", ".cxx"}} - - -- set source file flags set_sourceflags {cc = {"cflags", "cxflags"}, cxx = {"cxxflags", "cxflags"}} - - -- set target kinds set_targetkinds {binary = "ld", static = "ar", shared = "sh"} - - -- set target flags set_targetflags {binary = "ldflags", static = "arflags", shared = "shflags"} - - -- set language kinds - set_langkinds {c = "cc", cxx = "cxx"} - - -- set mixing kinds + set_langkinds {c = "cc", cxx = "cxx"} set_mixingkinds("cc", "cxx", "as", "mrc") - -- add rules - add_rules("c++") - - -- on load on_load("load") - - -- on check_main on_check_main("check_main") - -- set name flags - set_nameflags - { - object = - { + set_nameflags { + object = { "config.includedirs" , "config.frameworkdirs" , "config.frameworks" @@ -78,8 +57,7 @@ language("c++") , "target.sysincludedirs" , "toolchain.sysincludedirs" } - , binary = - { + , binary = { "config.linkdirs" , "config.frameworkdirs" , "target.linkdirs" @@ -101,8 +79,7 @@ language("c++") , "target.syslinks" , "toolchain.syslinks" } - , shared = - { + , shared = { "config.linkdirs" , "config.frameworkdirs" , "target.linkdirs" @@ -124,14 +101,12 @@ language("c++") , "target.syslinks" , "toolchain.syslinks" } - , static = - { + , static = { "target.strip" , "target.symbols" } } - -- set menu set_menu { config = { diff --git a/xmake/languages/cuda/api.lua b/xmake/languages/cuda/api.lua deleted file mode 100644 index 26f8ebf89..000000000 --- a/xmake/languages/cuda/api.lua +++ /dev/null @@ -1,79 +0,0 @@ ---!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 api.lua --- - --- get apis -function apis() - - -- init apis - _g.values = - { - -- target.add_xxx - "target.add_links" - , "target.add_syslinks" - , "target.add_cugencodes" - , "target.add_cuflags" - , "target.add_culdflags" - , "target.add_ldflags" - , "target.add_arflags" - , "target.add_shflags" - , "target.add_defines" - , "target.add_undefines" - , "target.add_rpathdirs" -- @note do not translate path, it's usually an absolute path or contains $ORIGIN/@loader_path - -- option.add_xxx - , "option.add_links" - , "option.add_syslinks" - , "option.add_cugencodes" - , "option.add_cuflags" - , "option.add_culdflags" - , "option.add_ldflags" - , "option.add_arflags" - , "option.add_shflags" - , "option.add_defines" - , "option.add_undefines" - , "option.add_rpathdirs" - -- toolchain.add_xxx - , "toolchain.add_links" - , "toolchain.add_syslinks" - , "toolchain.add_cugencodes" - , "toolchain.add_cuflags" - , "toolchain.add_culdflags" - , "toolchain.add_ldflags" - , "toolchain.add_arflags" - , "toolchain.add_shflags" - , "toolchain.add_defines" - , "toolchain.add_undefines" - , "toolchain.add_rpathdirs" - } - _g.paths = - { - -- target.add_xxx - "target.add_linkdirs" - , "target.add_includedirs" - , "target.add_sysincludedirs" - -- option.add_xxx - , "option.add_linkdirs" - , "option.add_sysincludedirs" - } - - -- ok - return _g -end - - diff --git a/xmake/languages/cuda/load.lua b/xmake/languages/cuda/load.lua index fd547b488..6df51bc2d 100644 --- a/xmake/languages/cuda/load.lua +++ b/xmake/languages/cuda/load.lua @@ -18,17 +18,60 @@ -- @file load.lua -- --- imports -import("api") +function _get_apis() + local apis = {} + apis.values = { + -- target.add_xxx + "target.add_links" + , "target.add_syslinks" + , "target.add_cugencodes" + , "target.add_cuflags" + , "target.add_culdflags" + , "target.add_ldflags" + , "target.add_arflags" + , "target.add_shflags" + , "target.add_defines" + , "target.add_undefines" + , "target.add_rpathdirs" -- @note do not translate path, it's usually an absolute path or contains $ORIGIN/@loader_path + -- option.add_xxx + , "option.add_links" + , "option.add_syslinks" + , "option.add_cugencodes" + , "option.add_cuflags" + , "option.add_culdflags" + , "option.add_ldflags" + , "option.add_arflags" + , "option.add_shflags" + , "option.add_defines" + , "option.add_undefines" + , "option.add_rpathdirs" + -- toolchain.add_xxx + , "toolchain.add_links" + , "toolchain.add_syslinks" + , "toolchain.add_cugencodes" + , "toolchain.add_cuflags" + , "toolchain.add_culdflags" + , "toolchain.add_ldflags" + , "toolchain.add_arflags" + , "toolchain.add_shflags" + , "toolchain.add_defines" + , "toolchain.add_undefines" + , "toolchain.add_rpathdirs" + } + apis.paths = { + -- target.add_xxx + "target.add_linkdirs" + , "target.add_includedirs" + , "target.add_sysincludedirs" + -- option.add_xxx + , "option.add_linkdirs" + , "option.add_sysincludedirs" + } + return apis +end --- load it function main() - - -- init apis - _g.apis = api.apis() - - -- ok - return _g + return {apis = _get_apis()} end diff --git a/xmake/languages/cuda/xmake.lua b/xmake/languages/cuda/xmake.lua index 1915730d0..a50935e4e 100644 --- a/xmake/languages/cuda/xmake.lua +++ b/xmake/languages/cuda/xmake.lua @@ -18,41 +18,20 @@ -- @file xmake.lua -- --- define language language("cuda") - - -- set source file kinds + add_rules("cuda") set_sourcekinds {cu = ".cu"} - - -- set source file flags set_sourceflags {cu = "cuflags"} - - -- set target kinds set_targetkinds {gpucode = "culd", binary = "ld", static = "ar", shared = "sh"} - - -- set target flags set_targetflags {gpucode = "culdflags", binary = "ldflags", static = "arflags", shared = "shflags"} - - -- set language kinds set_langkinds {cu = "cu"} - - -- set mixing kinds set_mixingkinds("cu", "cc", "cxx", "as") - -- add rules - add_rules("cuda") - - -- on load on_load("load") - - -- on check_main on_check_main("check_main") - -- set name flags - set_nameflags - { - object = - { + set_nameflags { + object = { "config.includedirs" , "target.symbols" , "target.warnings" @@ -68,8 +47,7 @@ language("cuda") , "target.sysincludedirs" , "toolchain.sysincludedirs" } - , binary = - { + , binary = { "config.linkdirs" , "target.linkdirs" , "target.rpathdirs" @@ -98,13 +76,11 @@ language("cuda") , "target.syslinks" , "toolchain.syslinks" } - , static = - { + , static = { "target.strip" , "target.symbols" } - , gpucode = - { + , gpucode = { "config.linkdirs" , "target.linkdirs" , "toolchain.linkdirs" @@ -117,7 +93,6 @@ language("cuda") } } - -- set menu set_menu { config = { diff --git a/xmake/languages/dlang/api.lua b/xmake/languages/dlang/api.lua deleted file mode 100644 index e6211e677..000000000 --- a/xmake/languages/dlang/api.lua +++ /dev/null @@ -1,82 +0,0 @@ ---!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 api.lua --- - --- get apis -function apis() - - -- init apis - _g.values = - { - -- target.add_xxx - "target.add_links" - , "target.add_syslinks" - , "target.add_dcflags" - , "target.add_ldflags" - , "target.add_arflags" - , "target.add_shflags" - , "target.add_rpathdirs" -- @note do not translate path, it's usually an absolute path or contains $ORIGIN/@loader_path - -- option.add_xxx - , "option.add_links" - , "option.add_syslinks" - , "option.add_dcflags" - , "option.add_ldflags" - , "option.add_arflags" - , "option.add_shflags" - , "option.add_rpathdirs" - -- package.add_xxx - , "package.add_links" - , "package.add_syslinks" - , "package.add_dcflags" - , "package.add_ldflags" - , "package.add_arflags" - , "package.add_shflags" - , "package.add_rpathdirs" - , "package.add_linkdirs" - , "package.add_includedirs" - , "package.add_sysincludedirs" - -- toolchain.add_xxx - , "toolchain.add_links" - , "toolchain.add_syslinks" - , "toolchain.add_dcflags" - , "toolchain.add_ldflags" - , "toolchain.add_arflags" - , "toolchain.add_shflags" - , "toolchain.add_rpathdirs" - , "toolchain.add_linkdirs" - , "toolchain.add_includedirs" - , "toolchain.add_sysincludedirs" - } - _g.paths = - { - -- target.add_xxx - "target.add_linkdirs" - , "target.add_includedirs" - , "target.add_sysincludedirs" - -- option.add_xxx - , "option.add_linkdirs" - , "option.add_includedirs" - , "option.add_sysincludedirs" - } - - -- ok - return _g -end - - diff --git a/xmake/languages/dlang/load.lua b/xmake/languages/dlang/load.lua index 97ef5346a..23653150c 100644 --- a/xmake/languages/dlang/load.lua +++ b/xmake/languages/dlang/load.lua @@ -18,13 +18,63 @@ -- @file load.lua -- --- imports -import("api") +function _get_apis() + local apis = {} + apis.values = { + -- target.add_xxx + "target.add_links" + , "target.add_syslinks" + , "target.add_dcflags" + , "target.add_ldflags" + , "target.add_arflags" + , "target.add_shflags" + , "target.add_rpathdirs" -- @note do not translate path, it's usually an absolute path or contains $ORIGIN/@loader_path + -- option.add_xxx + , "option.add_links" + , "option.add_syslinks" + , "option.add_dcflags" + , "option.add_ldflags" + , "option.add_arflags" + , "option.add_shflags" + , "option.add_rpathdirs" + -- package.add_xxx + , "package.add_links" + , "package.add_syslinks" + , "package.add_dcflags" + , "package.add_ldflags" + , "package.add_arflags" + , "package.add_shflags" + , "package.add_rpathdirs" + , "package.add_linkdirs" + , "package.add_includedirs" + , "package.add_sysincludedirs" + -- toolchain.add_xxx + , "toolchain.add_links" + , "toolchain.add_syslinks" + , "toolchain.add_dcflags" + , "toolchain.add_ldflags" + , "toolchain.add_arflags" + , "toolchain.add_shflags" + , "toolchain.add_rpathdirs" + , "toolchain.add_linkdirs" + , "toolchain.add_includedirs" + , "toolchain.add_sysincludedirs" + } + apis.paths = { + -- target.add_xxx + "target.add_linkdirs" + , "target.add_includedirs" + , "target.add_sysincludedirs" + -- option.add_xxx + , "option.add_linkdirs" + , "option.add_includedirs" + , "option.add_sysincludedirs" + } + return apis +end --- load it function main() - _g.apis = api.apis() - return _g + return {apis = _get_apis()} end diff --git a/xmake/languages/dlang/xmake.lua b/xmake/languages/dlang/xmake.lua index c9df5657b..9749c0d15 100644 --- a/xmake/languages/dlang/xmake.lua +++ b/xmake/languages/dlang/xmake.lua @@ -18,41 +18,20 @@ -- @file xmake.lua -- --- define language language("dlang") - - -- set source file kinds + add_rules("dlang") set_sourcekinds {dc = ".d"} - - -- set source file flags set_sourceflags {dc = "dcflags"} - - -- set target kinds set_targetkinds {binary = "dcld", static = "dcar", shared = "dcsh"} - - -- set target flags set_targetflags {binary = "ldflags", static = "arflags", shared = "shflags"} - - -- set language kinds - set_langkinds {d = "dc"} - - -- set mixing kinds + set_langkinds {d = "dc"} set_mixingkinds("dc", "cc", "cxx", "as") - -- add rules - add_rules("dlang") - - -- on load on_load("load") - - -- on check_main on_check_main("check_main") - -- set name flags - set_nameflags - { - object = - { + set_nameflags { + object = { "config.includedirs" , "target.symbols" , "target.warnings" @@ -63,8 +42,7 @@ language("dlang") , "target.sysincludedirs" , "toolchain.sysincludedirs" } - , binary = - { + , binary = { "config.linkdirs" , "target.linkdirs" , "target.rpathdirs" @@ -79,8 +57,7 @@ language("dlang") , "target.syslinks" , "toolchain.syslinks" } - , shared = - { + , shared = { "config.linkdirs" , "target.linkdirs" , "target.strip" @@ -93,14 +70,12 @@ language("dlang") , "target.syslinks" , "toolchain.syslinks" } - , static = - { + , static = { "target.strip" , "target.symbols" } } - -- set menu set_menu { config = { diff --git a/xmake/languages/fortran/api.lua b/xmake/languages/fortran/api.lua deleted file mode 100644 index b9724bb7e..000000000 --- a/xmake/languages/fortran/api.lua +++ /dev/null @@ -1,82 +0,0 @@ ---!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 api.lua --- - --- get apis -function apis() - - -- init apis - _g.values = - { - -- target.add_xxx - "target.add_links" - , "target.add_syslinks" - , "target.add_fcflags" - , "target.add_ldflags" - , "target.add_arflags" - , "target.add_shflags" - , "target.add_rpathdirs" -- @note do not translate path, it's usually an absolute path or contains $ORIGIN/@loader_path - -- option.add_xxx - , "option.add_links" - , "option.add_syslinks" - , "option.add_fcflags" - , "option.add_ldflags" - , "option.add_arflags" - , "option.add_shflags" - , "option.add_rpathdirs" - -- package.add_xxx - , "package.add_links" - , "package.add_syslinks" - , "package.add_fcflags" - , "package.add_ldflags" - , "package.add_arflags" - , "package.add_shflags" - , "package.add_rpathdirs" - , "package.add_linkdirs" - , "package.add_includedirs" - , "package.add_sysincludedirs" - -- toolchain.add_xxx - , "toolchain.add_links" - , "toolchain.add_syslinks" - , "toolchain.add_fcflags" - , "toolchain.add_ldflags" - , "toolchain.add_arflags" - , "toolchain.add_shflags" - , "toolchain.add_rpathdirs" - , "toolchain.add_linkdirs" - , "toolchain.add_includedirs" - , "toolchain.add_sysincludedirs" - } - _g.paths = - { - -- target.add_xxx - "target.add_linkdirs" - , "target.add_includedirs" - , "target.add_sysincludedirs" - -- option.add_xxx - , "option.add_linkdirs" - , "option.add_includedirs" - , "option.add_sysincludedirs" - } - - -- ok - return _g -end - - diff --git a/xmake/languages/fortran/load.lua b/xmake/languages/fortran/load.lua index fd547b488..e701b198f 100644 --- a/xmake/languages/fortran/load.lua +++ b/xmake/languages/fortran/load.lua @@ -18,17 +18,63 @@ -- @file load.lua -- --- imports -import("api") +function _get_apis() + local apis = {} + apis.values = { + -- target.add_xxx + "target.add_links" + , "target.add_syslinks" + , "target.add_fcflags" + , "target.add_ldflags" + , "target.add_arflags" + , "target.add_shflags" + , "target.add_rpathdirs" -- @note do not translate path, it's usually an absolute path or contains $ORIGIN/@loader_path + -- option.add_xxx + , "option.add_links" + , "option.add_syslinks" + , "option.add_fcflags" + , "option.add_ldflags" + , "option.add_arflags" + , "option.add_shflags" + , "option.add_rpathdirs" + -- package.add_xxx + , "package.add_links" + , "package.add_syslinks" + , "package.add_fcflags" + , "package.add_ldflags" + , "package.add_arflags" + , "package.add_shflags" + , "package.add_rpathdirs" + , "package.add_linkdirs" + , "package.add_includedirs" + , "package.add_sysincludedirs" + -- toolchain.add_xxx + , "toolchain.add_links" + , "toolchain.add_syslinks" + , "toolchain.add_fcflags" + , "toolchain.add_ldflags" + , "toolchain.add_arflags" + , "toolchain.add_shflags" + , "toolchain.add_rpathdirs" + , "toolchain.add_linkdirs" + , "toolchain.add_includedirs" + , "toolchain.add_sysincludedirs" + } + apis.paths = { + -- target.add_xxx + "target.add_linkdirs" + , "target.add_includedirs" + , "target.add_sysincludedirs" + -- option.add_xxx + , "option.add_linkdirs" + , "option.add_includedirs" + , "option.add_sysincludedirs" + } + return apis +end --- load it function main() - - -- init apis - _g.apis = api.apis() - - -- ok - return _g + return {apis = _get_apis()} end diff --git a/xmake/languages/fortran/xmake.lua b/xmake/languages/fortran/xmake.lua index 435b55ca2..5d73f153d 100644 --- a/xmake/languages/fortran/xmake.lua +++ b/xmake/languages/fortran/xmake.lua @@ -18,41 +18,20 @@ -- @file xmake.lua -- --- define language language("fortran") - - -- set source file kinds + add_rules("fortran") set_sourcekinds {fc = {".f03", ".f90", ".f95", ".for", ".f"}} - - -- set source file flags set_sourceflags {fc = "fcflags"} - - -- set target kinds set_targetkinds {binary = "fcld", static = "ar", shared = "fcsh"} - - -- set target flags set_targetflags {binary = "ldflags", static = "arflags", shared = "shflags"} - - -- set language kinds - set_langkinds {fortran = "fc"} - - -- set mixing kinds + set_langkinds {fortran = "fc"} set_mixingkinds("fc", "cc", "cxx", "as") - -- add rules - add_rules("fortran") - - -- on load on_load("load") - - -- on check_main on_check_main("check_main") - -- set name flags - set_nameflags - { - object = - { + set_nameflags { + object = { "config.includedirs" , "target.symbols" , "target.warnings" @@ -63,8 +42,7 @@ language("fortran") , "target.sysincludedirs" , "toolchain.sysincludedirs" } - , binary = - { + , binary = { "config.linkdirs" , "target.linkdirs" , "target.rpathdirs" @@ -79,8 +57,7 @@ language("fortran") , "target.syslinks" , "toolchain.syslinks" } - , shared = - { + , shared = { "config.linkdirs" , "target.linkdirs" , "target.strip" @@ -93,14 +70,12 @@ language("fortran") , "target.syslinks" , "toolchain.syslinks" } - , static = - { + , static = { "target.strip" , "target.symbols" } } - -- set menu set_menu { config = { diff --git a/xmake/languages/golang/api.lua b/xmake/languages/golang/api.lua deleted file mode 100644 index 730502bdf..000000000 --- a/xmake/languages/golang/api.lua +++ /dev/null @@ -1,62 +0,0 @@ ---!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 api.lua --- - --- get apis -function apis() - - -- init apis - _g.values = - { - -- target.add_xxx - "target.add_links" - , "target.add_syslinks" - , "target.add_gcflags" - , "target.add_ldflags" - , "target.add_arflags" - -- option.add_xxx - , "option.add_links" - , "option.add_syslinks" - , "option.add_gcflags" - , "option.add_ldflags" - , "option.add_arflags" - -- toolchain.add_xxx - , "toolchain.add_links" - , "toolchain.add_syslinks" - , "toolchain.add_gcflags" - , "toolchain.add_ldflags" - , "toolchain.add_arflags" - } - _g.paths = - { - -- target.add_xxx - "target.add_linkdirs" - , "target.add_includedirs" - , "target.add_sysincludedirs" - -- option.add_xxx - , "option.add_linkdirs" - , "option.add_includedirs" - , "option.add_sysincludedirs" - } - - -- ok - return _g -end - - diff --git a/xmake/languages/golang/load.lua b/xmake/languages/golang/load.lua index fd547b488..c4d3176b3 100644 --- a/xmake/languages/golang/load.lua +++ b/xmake/languages/golang/load.lua @@ -18,17 +18,43 @@ -- @file load.lua -- --- imports -import("api") +function _get_apis() + local apis = {} + apis.values = { + -- target.add_xxx + "target.add_links" + , "target.add_syslinks" + , "target.add_gcflags" + , "target.add_ldflags" + , "target.add_arflags" + -- option.add_xxx + , "option.add_links" + , "option.add_syslinks" + , "option.add_gcflags" + , "option.add_ldflags" + , "option.add_arflags" + -- toolchain.add_xxx + , "toolchain.add_links" + , "toolchain.add_syslinks" + , "toolchain.add_gcflags" + , "toolchain.add_ldflags" + , "toolchain.add_arflags" + } + apis.paths = { + -- target.add_xxx + "target.add_linkdirs" + , "target.add_includedirs" + , "target.add_sysincludedirs" + -- option.add_xxx + , "option.add_linkdirs" + , "option.add_includedirs" + , "option.add_sysincludedirs" + } + return apis +end --- load it function main() - - -- init apis - _g.apis = api.apis() - - -- ok - return _g + return {apis = _get_apis()} end diff --git a/xmake/languages/golang/xmake.lua b/xmake/languages/golang/xmake.lua index cae73ca26..213bf2b46 100644 --- a/xmake/languages/golang/xmake.lua +++ b/xmake/languages/golang/xmake.lua @@ -18,41 +18,20 @@ -- @file xmake.lua -- --- define language language("golang") - - -- set source file kinds + add_rules("go") set_sourcekinds {gc = ".go"} - - -- set source file flags set_sourceflags {gc = "gcflags"} - - -- set target kinds set_targetkinds {binary = "gcld", static = "gcar"} - - -- set target flags set_targetflags {binary = "ldflags", static = "arflags"} - - -- set language kinds - set_langkinds {go = "gc"} - - -- set mixing kinds + set_langkinds {go = "gc"} set_mixingkinds("gc") - -- add rules - add_rules("go") - - -- on load on_load("load") - - -- on check_main on_check_main("check_main") - -- set name flags - set_nameflags - { - object = - { + set_nameflags { + object = { "config.includedirs" , "target.symbols" , "target.warnings" @@ -67,8 +46,7 @@ language("golang") , "target.sysincludedirs" , "toolchain.sysincludedirs" } - , binary = - { + , binary = { "config.linkdirs" , "target.linkdirs" , "target.strip" @@ -81,8 +59,7 @@ language("golang") , "target.syslinks" , "toolchain.syslinks" } - , shared = - { + , shared = { "config.linkdirs" , "target.linkdirs" , "target.strip" @@ -97,7 +74,6 @@ language("golang") } } - -- set menu set_menu { config = { diff --git a/xmake/languages/msrc/load.lua b/xmake/languages/msrc/load.lua index fd547b488..d6e03a68b 100644 --- a/xmake/languages/msrc/load.lua +++ b/xmake/languages/msrc/load.lua @@ -18,17 +18,29 @@ -- @file load.lua -- --- imports -import("api") +function _get_apis() + local apis = {} + apis.values = { + -- target.add_xxx + "target.add_mrcflags" + -- option.add_xxx + , "option.add_mrcflags" + -- toolchain.add_xxx + , "toolchain.add_mrcflags" + } + apis.paths = { + -- target.add_xxx + "target.add_includedirs" + , "target.add_sysincludedirs" + -- option.add_xxx + , "option.add_includedirs" + , "option.add_sysincludedirs" + } + return apis +end --- load it function main() - - -- init apis - _g.apis = api.apis() - - -- ok - return _g + return {apis = _get_apis()} end diff --git a/xmake/languages/msrc/xmake.lua b/xmake/languages/msrc/xmake.lua index e5becdba7..93d113d53 100644 --- a/xmake/languages/msrc/xmake.lua +++ b/xmake/languages/msrc/xmake.lua @@ -18,32 +18,17 @@ -- @file xmake.lua -- --- define language language("msrc") - - -- set source file kinds + add_rules("win.sdk.resource") set_sourcekinds {mrc = ".rc"} - - -- set source file flags set_sourceflags {mrc = "mrcflags"} - - -- set language kinds - set_langkinds {msrc = "mrc"} - - -- set mixing kinds + set_langkinds {msrc = "mrc"} set_mixingkinds("mrc") - -- add rules - add_rules("win.sdk.resource") - - -- on load on_load("load") - -- set name flags - set_nameflags - { - object = - { + set_nameflags { + object = { "config.includedirs" , "target.defines" , "target.undefines" @@ -56,7 +41,6 @@ language("msrc") } } - -- set menu set_menu { config = { diff --git a/xmake/languages/objc++/api.lua b/xmake/languages/objc++/api.lua deleted file mode 100644 index 8df275896..000000000 --- a/xmake/languages/objc++/api.lua +++ /dev/null @@ -1,102 +0,0 @@ ---!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 api.lua --- - --- get apis -function apis() - - -- init apis - _g.values = - { - -- target.add_xxx - "target.add_links" - , "target.add_syslinks" - , "target.add_mflags" - , "target.add_mxflags" - , "target.add_mxxflags" - , "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 - -- 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_mflags" - , "option.add_mxflags" - , "option.add_mxxflags" - , "option.add_ldflags" - , "option.add_arflags" - , "option.add_shflags" - , "option.add_defines" - , "option.add_undefines" - , "option.add_frameworks" - , "option.add_rpathdirs" - -- toolchain.add_xxx - , "toolchain.add_links" - , "toolchain.add_syslinks" - , "toolchain.add_mflags" - , "toolchain.add_mxflags" - , "toolchain.add_mxxflags" - , "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" - } - _g.paths = - { - -- target.set_xxx - "target.set_headerdir" -- TODO deprecated - , "target.set_config_header" - , "target.set_pcheader" - , "target.set_pcxxheader" - -- target.add_xxx - , "target.add_headers" -- TODO deprecated - , "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" - } - - -- ok - return _g -end - - diff --git a/xmake/languages/objc++/load.lua b/xmake/languages/objc++/load.lua index fd547b488..85df22850 100644 --- a/xmake/languages/objc++/load.lua +++ b/xmake/languages/objc++/load.lua @@ -18,17 +18,83 @@ -- @file load.lua -- --- imports -import("api") +function _get_apis() + local apis = {} + apis.values = { + -- target.add_xxx + "target.add_links" + , "target.add_syslinks" + , "target.add_mflags" + , "target.add_mxflags" + , "target.add_mxxflags" + , "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 + -- 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_mflags" + , "option.add_mxflags" + , "option.add_mxxflags" + , "option.add_ldflags" + , "option.add_arflags" + , "option.add_shflags" + , "option.add_defines" + , "option.add_undefines" + , "option.add_frameworks" + , "option.add_rpathdirs" + -- toolchain.add_xxx + , "toolchain.add_links" + , "toolchain.add_syslinks" + , "toolchain.add_mflags" + , "toolchain.add_mxflags" + , "toolchain.add_mxxflags" + , "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.paths = { + -- target.set_xxx + "target.set_headerdir" -- TODO deprecated + , "target.set_config_header" + , "target.set_pcheader" + , "target.set_pcxxheader" + -- target.add_xxx + , "target.add_headers" -- TODO deprecated + , "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" + } + return apis +end --- load it function main() - - -- init apis - _g.apis = api.apis() - - -- ok - return _g + return {apis = _get_apis()} end diff --git a/xmake/languages/rust/api.lua b/xmake/languages/rust/api.lua deleted file mode 100644 index dbd7e6776..000000000 --- a/xmake/languages/rust/api.lua +++ /dev/null @@ -1,58 +0,0 @@ ---!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 api.lua --- - --- get apis -function apis() - - -- init apis - _g.values = - { - -- target.add_xxx - "target.add_rcflags" - , "target.add_ldflags" - , "target.add_arflags" - , "target.add_shflags" - , "target.add_rpathdirs" -- @note do not translate path, it's usually an absolute path or contains $ORIGIN/@loader_path - -- option.add_xxx - , "option.add_rcflags" - , "option.add_ldflags" - , "option.add_arflags" - , "option.add_shflags" - , "option.add_rpathdirs" - -- toolchain.add_xxx - , "toolchain.add_rcflags" - , "toolchain.add_ldflags" - , "toolchain.add_arflags" - , "toolchain.add_shflags" - , "toolchain.add_rpathdirs" - } - _g.paths = - { - -- target.add_xxx - "target.add_linkdirs" - -- option.add_xxx - , "option.add_linkdirs" - } - - -- ok - return _g -end - - diff --git a/xmake/languages/rust/load.lua b/xmake/languages/rust/load.lua index fd547b488..c02f50bfd 100644 --- a/xmake/languages/rust/load.lua +++ b/xmake/languages/rust/load.lua @@ -18,17 +18,39 @@ -- @file load.lua -- --- imports -import("api") +function _get_apis() + local apis = {} + apis.values = { + -- target.add_xxx + "target.add_rcflags" + , "target.add_ldflags" + , "target.add_arflags" + , "target.add_shflags" + , "target.add_rpathdirs" -- @note do not translate path, it's usually an absolute path or contains $ORIGIN/@loader_path + -- option.add_xxx + , "option.add_rcflags" + , "option.add_ldflags" + , "option.add_arflags" + , "option.add_shflags" + , "option.add_rpathdirs" + -- toolchain.add_xxx + , "toolchain.add_rcflags" + , "toolchain.add_ldflags" + , "toolchain.add_arflags" + , "toolchain.add_shflags" + , "toolchain.add_rpathdirs" + } + apis.paths = { + -- target.add_xxx + "target.add_linkdirs" + -- option.add_xxx + , "option.add_linkdirs" + } + return apis +end --- load it function main() - - -- init apis - _g.apis = api.apis() - - -- ok - return _g + return {apis = _get_apis()} end diff --git a/xmake/languages/rust/xmake.lua b/xmake/languages/rust/xmake.lua index 9c7e94edc..dc6ae3d15 100644 --- a/xmake/languages/rust/xmake.lua +++ b/xmake/languages/rust/xmake.lua @@ -18,48 +18,26 @@ -- @file xmake.lua -- --- define language language("rust") - - -- set source file kinds + add_rules("rust") set_sourcekinds {rc = ".rs"} - - -- set source file flags set_sourceflags {rc = "rcflags"} - - -- set target kinds set_targetkinds {binary = "rcld", static = "rcar", shared = "rcsh"} - - -- set target flags set_targetflags {binary = "ldflags", static = "arflags", shared = "shflags"} - - -- set language kinds set_langkinds {rust = "rc"} - - -- set mixing kinds set_mixingkinds("rc") - -- add rules - add_rules("rust") - - -- on load on_load("load") - - -- on check_main on_check_main("check_main") - -- set name flags - set_nameflags - { - object = - { + set_nameflags { + object = { "target.symbols" , "target.warnings" , "target.optimize:check" , "target.vectorexts:check" } - , binary = - { + , binary = { "config.linkdirs" , "target.linkdirs" , "target.rpathdirs" @@ -68,22 +46,19 @@ language("rust") , "toolchain.linkdirs" , "toolchain.rpathdirs" } - , shared = - { + , shared = { "config.linkdirs" , "target.linkdirs" , "target.strip" , "target.symbols" , "toolchain.linkdirs" } - , static = - { + , static = { "target.strip" , "target.symbols" } } - -- set menu set_menu { config = { diff --git a/xmake/languages/swift/api.lua b/xmake/languages/swift/api.lua deleted file mode 100644 index 3b8dd0506..000000000 --- a/xmake/languages/swift/api.lua +++ /dev/null @@ -1,69 +0,0 @@ ---!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 api.lua --- - --- get apis -function apis() - - -- init apis - _g.values = - { - -- target.add_xxx - "target.add_links" - , "target.add_syslinks" - , "target.add_scflags" - , "target.add_ldflags" - , "target.add_arflags" - , "target.add_shflags" - , "target.add_frameworks" - , "target.add_rpathdirs" -- @note do not translate path, it's usually an absolute path or contains $ORIGIN/@loader_path - -- option.add_xxx - , "option.add_links" - , "option.add_syslinks" - , "option.add_scflags" - , "option.add_ldflags" - , "option.add_arflags" - , "option.add_shflags" - , "option.add_frameworks" - , "option.add_rpathdirs" - -- toolchain.add_xxx - , "toolchain.add_links" - , "toolchain.add_syslinks" - , "toolchain.add_scflags" - , "toolchain.add_ldflags" - , "toolchain.add_arflags" - , "toolchain.add_shflags" - , "toolchain.add_frameworks" - , "toolchain.add_rpathdirs" - } - _g.paths = - { - -- target.add_xxx - "target.add_linkdirs" - , "target.add_frameworkdirs" - -- option.add_xxx - , "option.add_linkdirs" - , "option.add_frameworkdirs" - } - - -- ok - return _g -end - - diff --git a/xmake/languages/swift/load.lua b/xmake/languages/swift/load.lua index fd547b488..8de44b044 100644 --- a/xmake/languages/swift/load.lua +++ b/xmake/languages/swift/load.lua @@ -18,17 +18,50 @@ -- @file load.lua -- --- imports -import("api") +function _get_apis() + local apis = {} + apis.values = { + -- target.add_xxx + "target.add_links" + , "target.add_syslinks" + , "target.add_scflags" + , "target.add_ldflags" + , "target.add_arflags" + , "target.add_shflags" + , "target.add_frameworks" + , "target.add_rpathdirs" -- @note do not translate path, it's usually an absolute path or contains $ORIGIN/@loader_path + -- option.add_xxx + , "option.add_links" + , "option.add_syslinks" + , "option.add_scflags" + , "option.add_ldflags" + , "option.add_arflags" + , "option.add_shflags" + , "option.add_frameworks" + , "option.add_rpathdirs" + -- toolchain.add_xxx + , "toolchain.add_links" + , "toolchain.add_syslinks" + , "toolchain.add_scflags" + , "toolchain.add_ldflags" + , "toolchain.add_arflags" + , "toolchain.add_shflags" + , "toolchain.add_frameworks" + , "toolchain.add_rpathdirs" + } + apis.paths = { + -- target.add_xxx + "target.add_linkdirs" + , "target.add_frameworkdirs" + -- option.add_xxx + , "option.add_linkdirs" + , "option.add_frameworkdirs" + } + return apis +end --- load it function main() - - -- init apis - _g.apis = api.apis() - - -- ok - return _g + return {apis = _get_apis()} end diff --git a/xmake/languages/swift/xmake.lua b/xmake/languages/swift/xmake.lua index b0de2d067..ba0d6b693 100644 --- a/xmake/languages/swift/xmake.lua +++ b/xmake/languages/swift/xmake.lua @@ -18,38 +18,19 @@ -- @file xmake.lua -- --- define language language("swift") - - -- set source file kinds + add_rules("swift") set_sourcekinds {sc = ".swift"} - - -- set source file flags set_sourceflags {sc = "scflags"} - - -- set target kinds set_targetkinds {binary = "scld", static = "ar", shared = "scsh"} - - -- set target flags set_targetflags {binary = "ldflags", static = "arflags", shared = "shflags"} - - -- set language kinds - set_langkinds {swift = "sc"} - - -- set mixing kinds + set_langkinds {swift = "sc"} set_mixingkinds("sc", "mm", "mxx", "cc", "cxx") - -- add rules - add_rules("swift") - - -- on load on_load("load") - -- set name flags - set_nameflags - { - object = - { + set_nameflags { + object = { "config.includedirs" , "config.frameworkdirs" , "config.Frameworks" @@ -69,8 +50,7 @@ language("swift") , "toolchain.frameworkdirs" , "toolchain.frameworks" } - , binary = - { + , binary = { "config.linkdirs" , "config.frameworkdirs" , "target.linkdirs" @@ -91,8 +71,7 @@ language("swift") , "target.syslinks" , "toolchain.syslinks" } - , shared = - { + , shared = { "config.linkdirs" , "config.frameworkdirs" , "target.linkdirs" @@ -111,14 +90,12 @@ language("swift") , "target.syslinks" , "toolchain.syslinks" } - , static = - { + , static = { "target.strip" , "target.symbols" } } - -- set menu set_menu { config = { diff --git a/xmake/languages/zig/api.lua b/xmake/languages/zig/api.lua deleted file mode 100644 index 3501a2e9d..000000000 --- a/xmake/languages/zig/api.lua +++ /dev/null @@ -1,74 +0,0 @@ ---!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 api.lua --- - --- get apis -function apis() - - -- init apis - _g.values = - { - -- target.add_xxx - "target.add_links" - , "target.add_syslinks" - , "target.add_zcflags" - , "target.add_ldflags" - , "target.add_arflags" - , "target.add_shflags" - , "target.add_rpathdirs" -- @note do not translate path, it's usually an absolute path or contains $ORIGIN/@loader_path - -- option.add_xxx - , "option.add_links" - , "option.add_syslinks" - , "option.add_zcflags" - , "option.add_ldflags" - , "option.add_arflags" - , "option.add_shflags" - , "option.add_rpathdirs" - -- package.add_xxx - , "package.add_links" - , "package.add_syslinks" - , "package.add_zcflags" - , "package.add_ldflags" - , "package.add_arflags" - , "package.add_shflags" - , "package.add_rpathdirs" - , "package.add_linkdirs" - -- toolchain.add_xxx - , "toolchain.add_links" - , "toolchain.add_syslinks" - , "toolchain.add_zcflags" - , "toolchain.add_ldflags" - , "toolchain.add_arflags" - , "toolchain.add_shflags" - , "toolchain.add_rpathdirs" - , "toolchain.add_linkdirs" - } - _g.paths = - { - -- target.add_xxx - "target.add_linkdirs" - -- option.add_xxx - , "option.add_linkdirs" - } - - -- ok - return _g -end - - diff --git a/xmake/languages/zig/load.lua b/xmake/languages/zig/load.lua index fd547b488..418645a5e 100644 --- a/xmake/languages/zig/load.lua +++ b/xmake/languages/zig/load.lua @@ -18,17 +18,55 @@ -- @file load.lua -- --- imports -import("api") +function _get_apis() + local apis = {} + apis.values = { + -- target.add_xxx + "target.add_links" + , "target.add_syslinks" + , "target.add_zcflags" + , "target.add_ldflags" + , "target.add_arflags" + , "target.add_shflags" + , "target.add_rpathdirs" -- @note do not translate path, it's usually an absolute path or contains $ORIGIN/@loader_path + -- option.add_xxx + , "option.add_links" + , "option.add_syslinks" + , "option.add_zcflags" + , "option.add_ldflags" + , "option.add_arflags" + , "option.add_shflags" + , "option.add_rpathdirs" + -- package.add_xxx + , "package.add_links" + , "package.add_syslinks" + , "package.add_zcflags" + , "package.add_ldflags" + , "package.add_arflags" + , "package.add_shflags" + , "package.add_rpathdirs" + , "package.add_linkdirs" + -- toolchain.add_xxx + , "toolchain.add_links" + , "toolchain.add_syslinks" + , "toolchain.add_zcflags" + , "toolchain.add_ldflags" + , "toolchain.add_arflags" + , "toolchain.add_shflags" + , "toolchain.add_rpathdirs" + , "toolchain.add_linkdirs" + } + apis.paths = { + -- target.add_xxx + "target.add_linkdirs" + -- option.add_xxx + , "option.add_linkdirs" + } + return apis +end --- load it function main() - - -- init apis - _g.apis = api.apis() - - -- ok - return _g + return {apis = _get_apis()} end diff --git a/xmake/languages/zig/xmake.lua b/xmake/languages/zig/xmake.lua index 117890613..9c85e3962 100644 --- a/xmake/languages/zig/xmake.lua +++ b/xmake/languages/zig/xmake.lua @@ -18,48 +18,26 @@ -- @file xmake.lua -- --- define language language("zig") - - -- set source file kinds + add_rules("zig") set_sourcekinds {zc = ".zig"} - - -- set source file flags set_sourceflags {zc = "zcflags"} - - -- set target kinds set_targetkinds {binary = "zcld", static = "zcar", shared = "zcsh"} - - -- set target flags set_targetflags {binary = "ldflags", static = "arflags", shared = "shflags"} - - -- set language kinds - set_langkinds {zig = "zc"} - - -- set mixing kinds + set_langkinds {zig = "zc"} set_mixingkinds("zc", "cc", "cxx", "as") - -- add rules - add_rules("zig") - - -- on load on_load("load") - - -- on check_main on_check_main("check_main") - -- set name flags - set_nameflags - { - object = - { + set_nameflags { + object = { "target.symbols" , "target.warnings" , "target.optimize:check" , "target.vectorexts:check" } - , binary = - { + , binary = { "config.linkdirs" , "target.linkdirs" , "target.rpathdirs" @@ -74,8 +52,7 @@ language("zig") , "target.syslinks" , "toolchain.syslinks" } - , shared = - { + , shared = { "config.linkdirs" , "target.linkdirs" , "target.strip" @@ -88,17 +65,14 @@ language("zig") , "target.syslinks" , "toolchain.syslinks" } - , static = - { + , static = { "target.strip" , "target.symbols" } } - -- set menu set_menu { - config = - { + config = { {category = "Cross Complation Configuration/Compiler Configuration" } , {nil, "zc", "kv", nil, "The Zig Compiler" } diff --git a/xmake/modules/detect/sdks/find_qt.lua b/xmake/modules/detect/sdks/find_qt.lua index 3b71a5640..9dbc7b386 100644 --- a/xmake/modules/detect/sdks/find_qt.lua +++ b/xmake/modules/detect/sdks/find_qt.lua @@ -169,12 +169,13 @@ function _find_qt(sdkdir, sdkver) sdkdir = qtenvs.QT_INSTALL_PREFIX local sdkver = qtenvs.QT_VERSION local bindir = qtenvs.QT_INSTALL_BINS + local libexecdir = qtenvs.QT_INSTALL_LIBEXECS local qmldir = qtenvs.QT_INSTALL_QML local libdir = qtenvs.QT_INSTALL_LIBS local pluginsdir = qtenvs.QT_INSTALL_PLUGINS local includedir = qtenvs.QT_INSTALL_HEADERS local mkspecsdir = path.join(qtenvs.QT_INSTALL_ARCHDATA, "mkspecs") - return {sdkdir = sdkdir, bindir = bindir, libdir = libdir, includedir = includedir, qmldir = qmldir, pluginsdir = pluginsdir, mkspecsdir = mkspecsdir, sdkver = sdkver} + return {sdkdir = sdkdir, bindir = bindir, libexecdir = libexecdir, libdir = libdir, includedir = includedir, qmldir = qmldir, pluginsdir = pluginsdir, mkspecsdir = mkspecsdir, sdkver = sdkver} end -- find qt sdk toolchains diff --git a/xmake/modules/detect/sdks/find_vcpkgdir.lua b/xmake/modules/detect/sdks/find_vcpkgdir.lua index d2f6bd3fd..4645895eb 100644 --- a/xmake/modules/detect/sdks/find_vcpkgdir.lua +++ b/xmake/modules/detect/sdks/find_vcpkgdir.lua @@ -57,6 +57,16 @@ function main() end end end + if not vcpkgdir and is_host("windows") then + -- attempt to read path info after running `vcpkg integrate install` + local pathfile = "~/../Local/vcpkg/vcpkg.path.txt" + if os.isfile(pathfile) then + local dir = io.readfile(pathfile):trim() + if os.isdir(dir) then + vcpkgdir = dir + end + end + end detectcache:set("detect.sdks.find_vcpkgdir", vcpkgdir or false) detectcache:save() end diff --git a/xmake/modules/detect/sdks/find_vstudio.lua b/xmake/modules/detect/sdks/find_vstudio.lua index 362a2a705..2934d23c8 100644 --- a/xmake/modules/detect/sdks/find_vstudio.lua +++ b/xmake/modules/detect/sdks/find_vstudio.lua @@ -35,7 +35,8 @@ local vcvars = {"path", "WindowsSDKVersion", "WindowsSdkBinPath", "UniversalCRTSdkDir", - "UCRTVersion"} + "UCRTVersion", + "VCToolsVersion"} -- load vcvarsall environment variables function _load_vcvarsall(vcvarsall, vsver, arch, opt) diff --git a/xmake/languages/msrc/api.lua b/xmake/modules/detect/tools/find_valac.lua index ab7ae6bad..2c7453872 100644 --- a/xmake/languages/msrc/api.lua +++ b/xmake/modules/detect/tools/find_valac.lua @@ -15,34 +15,38 @@ -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki --- @file api.lua +-- @file find_valac.lua -- --- get apis -function apis() +-- imports +import("lib.detect.find_program") +import("lib.detect.find_programver") - -- init apis - _g.values = - { - -- target.add_xxx - "target.add_mrcflags" - -- option.add_xxx - , "option.add_mrcflags" - -- toolchain.add_xxx - , "toolchain.add_mrcflags" - } - _g.paths = - { - -- target.add_xxx - "target.add_includedirs" - , "target.add_sysincludedirs" - -- option.add_xxx - , "option.add_includedirs" - , "option.add_sysincludedirs" - } +-- find valac +-- +-- @param opt the argument options, e.g. {version = true} +-- +-- @return program, version +-- +-- @code +-- +-- local valac = find_valac() +-- local valac, version, hintname = find_valac({program = "valac", version = true}) +-- +-- @endcode +-- +function main(opt) - -- ok - return _g -end + -- init options + opt = opt or {} + -- find program + local program = find_program(opt.program or "valac", opt) + -- find program version + local version = nil + if program and opt.version then + version = find_programver(program, opt) + end + return program, version +end diff --git a/xmake/modules/detect/tools/find_vcpkg.lua b/xmake/modules/detect/tools/find_vcpkg.lua index 46ae1ea36..7f4dc37a8 100644 --- a/xmake/modules/detect/tools/find_vcpkg.lua +++ b/xmake/modules/detect/tools/find_vcpkg.lua @@ -50,16 +50,6 @@ function main(opt) if vcpkgdir then table.insert(paths, vcpkgdir) end - if is_host("windows") then - -- attempt to read path info after running `vcpkg integrate install` - local pathfile = "~/../Local/vcpkg/vcpkg.path.txt" - if os.isfile(pathfile) then - local dir = io.readfile(pathfile):trim() - if os.isdir(dir) then - table.insert(paths, dir) - end - end - end -- find program opt.paths = paths diff --git a/xmake/modules/package/tools/autoconf.lua b/xmake/modules/package/tools/autoconf.lua index 4536580ae..209e6c68a 100644 --- a/xmake/modules/package/tools/autoconf.lua +++ b/xmake/modules/package/tools/autoconf.lua @@ -26,7 +26,7 @@ import("core.tool.compiler") -- translate path function _translate_path(package, p) - if p and is_host("windows") and package:is_plat("mingw") then + if p and is_host("windows") and (package:is_plat("mingw") or package:is_plat("msys") or package:is_plat("cygwin")) then p = p:gsub("\\", "/") end return p diff --git a/xmake/modules/package/tools/cmake.lua b/xmake/modules/package/tools/cmake.lua index d924bfb6d..3e48fee40 100644 --- a/xmake/modules/package/tools/cmake.lua +++ b/xmake/modules/package/tools/cmake.lua @@ -406,6 +406,7 @@ end function _get_cmake_generator_for_msvc(package) local vsvers = { + ["2022"] = "17", ["2019"] = "16", ["2017"] = "15", ["2015"] = "14", diff --git a/xmake/modules/package/tools/xmake.lua b/xmake/modules/package/tools/xmake.lua index e1e3ac4b0..0c7d9c294 100644 --- a/xmake/modules/package/tools/xmake.lua +++ b/xmake/modules/package/tools/xmake.lua @@ -46,6 +46,7 @@ function _get_configs(package, configs) table.insert(configs, "--plat=" .. package:plat()) table.insert(configs, "--arch=" .. package:arch()) table.insert(configs, "--mode=" .. (package:is_debug() and "debug" or "release")) + table.insert(configs, "--kind=" .. (package:config("shared") and "shared" or "static")) if package:is_plat("windows") then local vs_runtime = package:config("vs_runtime") if vs_runtime then diff --git a/xmake/modules/private/action/require/impl/actions/download.lua b/xmake/modules/private/action/require/impl/actions/download.lua index abc017a70..bee421052 100644 --- a/xmake/modules/private/action/require/impl/actions/download.lua +++ b/xmake/modules/private/action/require/impl/actions/download.lua @@ -83,7 +83,7 @@ function _checkout(package, url, sourcedir, url_alias) git.checkout(revision, {repodir = packagedir}) -- update all submodules - if os.isdir(".gitmodules") then + if os.isfile(path.join(packagedir, ".gitmodules")) then git.submodule.update({init = true, recursive = true, longpaths = longpaths, repodir = packagedir}) end end diff --git a/xmake/modules/private/action/require/impl/actions/download_resources.lua b/xmake/modules/private/action/require/impl/actions/download_resources.lua index 5bf1f9a46..fa115c04a 100644 --- a/xmake/modules/private/action/require/impl/actions/download_resources.lua +++ b/xmake/modules/private/action/require/impl/actions/download_resources.lua @@ -68,7 +68,7 @@ function _checkout(package, resource_name, resource_url, resource_revision) git.checkout(resource_revision, {repodir = resourcedir}) -- update all submodules - if os.isdir(".gitmodules") then + if os.isfile(path.join(resourcedir, ".gitmodules")) then git.submodule.update({init = true, recursive = true, longpaths = longpaths, repodir = resourcedir}) end end diff --git a/xmake/modules/private/action/require/impl/install_packages.lua b/xmake/modules/private/action/require/impl/install_packages.lua index fb7647861..7e83ae939 100644 --- a/xmake/modules/private/action/require/impl/install_packages.lua +++ b/xmake/modules/private/action/require/impl/install_packages.lua @@ -520,7 +520,9 @@ function main(requires, opt) -- fetch and register packages (with system) from local first runjobs("fetch_packages", function (index) local instance = packages[index] - if instance and (not option.get("force") or (option.get("shallow") and not instance:is_toplevel())) then + if instance and (instance:is_fetchonly() or + not option.get("force") or + (option.get("shallow") and not instance:is_toplevel())) then local oldenvs = os.getenvs() instance:envs_enter() instance:fetch() diff --git a/xmake/modules/private/action/require/impl/package.lua b/xmake/modules/private/action/require/impl/package.lua index 844847558..612911429 100644 --- a/xmake/modules/private/action/require/impl/package.lua +++ b/xmake/modules/private/action/require/impl/package.lua @@ -26,6 +26,7 @@ import("core.base.hashset") import("private.utils.progress") import("core.cache.memcache") import("core.project.project") +import("core.tool.toolchain") import("core.package.package", {alias = "core_package"}) import("devel.git") import("private.action.require.impl.repository") @@ -528,6 +529,74 @@ function _inherit_parent_configs(requireinfo, package, parentinfo) end end +-- select artifacts for msvc +function _select_artifacts_for_msvc(package, artifacts_manifest) + local msvc + for _, instance in ipairs(package:toolchains()) do + if instance:name() == "msvc" then + msvc = instance + break + end + end + if not msvc then + msvc = toolchain.load("msvc", {plat = package:plat(), arch = package:arch()}) + end + local vcvars = msvc:config("vcvars") + if vcvars then + local vs_toolset = vcvars.VCToolsVersion + if vs_toolset and semver.is_valid(vs_toolset) then + local artifacts_infos = {} + for key, artifacts_info in pairs(artifacts_manifest) do + if key:startswith(package:plat() .. "-" .. package:arch() .. "-vc") and key:endswith("-" .. package:buildhash()) then + table.insert(artifacts_infos, artifacts_info) + end + end + -- we sort them to select a newest toolset to get better optimzed performance + table.sort(artifacts_infos, function (a, b) + if a.toolset and b.toolset then + return semver.compare(a.toolset, b.toolset) > 0 + else + return false + end + end) + if package:config("shared") or package:is_binary() then + -- executable programs and dynamic libraries only need to select the latest toolset + return artifacts_infos[1] + else + -- static libraries need to consider toolset compatibility + for _, artifacts_info in ipairs(artifacts_infos) do + -- toolset is backwards compatible + -- + -- @see https://github.com/xmake-io/xmake/issues/1513 + -- https://docs.microsoft.com/en-us/cpp/porting/binary-compat-2015-2017?view=msvc-160 + if artifacts_info.toolset and semver.compare(vs_toolset, artifacts_info.toolset) >= 0 then + return artifacts_info + end + end + end + end + end +end + +-- select artifacts for generic +function _select_artifacts_for_generic(package, artifacts_manifest) + local buildid = package:plat() .. "-" .. package:arch() .. "-" .. package:buildhash() + return artifacts_manifest[buildid] +end + +-- select to use precompiled artifacts? +function _select_artifacts(package, artifacts_manifest) + local artifacts_info + if package:is_plat("windows") then -- for msvc + artifacts_info = _select_artifacts_for_msvc(package, artifacts_manifest) + else + artifacts_info = _select_artifacts_for_generic(package, artifacts_manifest) + end + if artifacts_info then + package:artifacts_set(artifacts_info) + end +end + -- load required packages function _load_package(packagename, requireinfo, opt) @@ -594,6 +663,10 @@ function _load_package(packagename, requireinfo, opt) -- get package from cache first local package_cached = _memcache():get2("packages", packagekey) if package_cached then + -- since toplevel is not part of packagekey, we need to ensure it's part of the cached package table too + if requireinfo.is_toplevel and not package_cached:is_toplevel() then + package_cached:requireinfo().is_toplevel = true + end return package_cached end @@ -625,14 +698,11 @@ function _load_package(packagename, requireinfo, opt) _check_package_configurations(package) -- save artifacts info, we need 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 local artifacts_manifest = repository.artifacts_manifest(packagename, version) if artifacts_manifest then - local buildid = package:plat() .. "-" .. package:arch() .. "-" .. package:buildhash() - local artifacts_info = artifacts_manifest[buildid] - if artifacts_info then - package:artifacts_set(artifacts_info) - end + _select_artifacts(package, artifacts_manifest) end end diff --git a/xmake/modules/private/detect/find_platform.lua b/xmake/modules/private/detect/find_platform.lua index 590ff9b11..54f8a2182 100644 --- a/xmake/modules/private/detect/find_platform.lua +++ b/xmake/modules/private/detect/find_platform.lua @@ -20,13 +20,19 @@ -- imports import("core.project.config") +import("core.project.project") import("detect.sdks.find_cross_toolchain") -- find platform function _find_plat(plat) plat = plat or config.get("plat") if not plat then - plat = os.subhost() + if not plat then + plat = project.get("defaultplat") + end + if not plat then + plat = os.subhost() + end if plat == "msys" then local msystem = os.getenv("MSYSTEM") if msystem and msystem:lower():find("mingw", 1, true) then @@ -81,28 +87,33 @@ end function _find_arch(plat, arch) arch = arch or config.get("arch") if not arch then - if plat == "android" then - arch = "armeabi-v7a" - elseif plat == "iphoneos" or plat == "appletvos" then - arch = "arm64" - elseif plat == "watchos" then - arch = "armv7k" - elseif plat == "wasm" then - arch = "wasm32" - elseif plat == "mingw" then - local mingw_chost = nil - if is_subhost("msys") then - mingw_chost = os.getenv("MINGW_CHOST") - end - if mingw_chost == "i686-w64-mingw32" then - arch = "i386" + if not arch then + arch = project.default_arch(plat) + end + if not arch then + if plat == "android" then + arch = "armeabi-v7a" + elseif plat == "iphoneos" or plat == "appletvos" then + arch = "arm64" + elseif plat == "watchos" then + arch = "armv7k" + elseif plat == "wasm" then + arch = "wasm32" + elseif plat == "mingw" then + local mingw_chost = nil + if is_subhost("msys") then + mingw_chost = os.getenv("MINGW_CHOST") + end + if mingw_chost == "i686-w64-mingw32" then + arch = "i386" + else + arch = "x86_64" + end + elseif plat == "cross" then + arch = _find_arch_from_cross() else - arch = "x86_64" + arch = os.subarch() end - elseif plat == "cross" then - arch = _find_arch_from_cross() - else - arch = os.subarch() end end return arch @@ -126,17 +137,19 @@ end -- function main(opt) - -- find plat and arch + -- find platform opt = opt or {} local plat = _find_plat(opt.plat) - local arch = _find_arch(plat, opt.arch) - - -- save the local configuration if be global if opt.global then if not opt.plat and not config.get("plat") then config.set("plat", plat) cprint("checking for platform ... ${color.success}%s", plat) end + end + + -- find architecture + local arch = _find_arch(plat, opt.arch) + if opt.global then if not opt.arch and not config.get("arch") then config.set("arch", arch) cprint("checking for architecture ... ${color.success}%s", arch) diff --git a/xmake/modules/private/utils/bin2c.lua b/xmake/modules/private/utils/bin2c.lua new file mode 100644 index 000000000..91ea1eafe --- /dev/null +++ b/xmake/modules/private/utils/bin2c.lua @@ -0,0 +1,107 @@ +--!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 bin2c.lua +-- + +-- imports +import("core.base.bytes") +import("core.base.option") + +local options = { + {'w', "linewidth", "kv", nil, "Set the line width"}, + {'i', "binarypath", "kv", nil, "Set the binary file path."}, + {'o', "outputpath", "kv", nil, "Set the output file path."} +} + +function _do_dump(binarydata, outputfile, opt) + local i = 0 + local n = 147 + local p = 0 + local e = binarydata:size() + local line = nil + local linewidth = opt.linewidth or 0x20 + local first = true + while p < e do + line = "" + if p + linewidth <= e then + for i = 0, linewidth - 1 do + if first then + first = false + line = line .. " " + else + line = line .. "," + end + line = line .. string.format(" 0x%02X", binarydata[p + i + 1]) + end + outputfile:print(line) + p = p + linewidth + elseif p < e then + local left = e - p + for i = 0, left - 1 do + if first then + first = false + line = line .. " " + else + line = line .. "," + end + line = line .. string.format(" 0x%02X", binarydata[p + i + 1]) + end + outputfile:print(line) + p = p + left + else + break + end + end +end + +function _do_bin2c(binarypath, outputpath, opt) + + -- init source directory and options + opt = opt or {} + binarypath = path.absolute(binarypath) + outputpath = path.absolute(outputpath) + assert(os.isfile(binarypath), "%s not found!", binarypath) + + -- trace + print("generating code data file from %s ..", binarypath) + + -- do dump + local binarydata = bytes(io.readfile(binarypath, {encoding = "binary"})) + local outputfile = io.open(outputpath, 'w') + if outputfile then + binarydata = binarydata .. bytes('\0') + _do_dump(binarydata, outputfile, opt) + outputfile:close() + end + + -- trace + cprint("${bright}%s generated!", outputpath) +end + +-- main entry +function main(...) + + -- parse arguments + local argv = {...} + local opt = option.parse(argv, options, "Print c/c++ code files from the given binary file." + , "" + , "Usage: xmake l private.utils.bin2c [options]") + + -- do bin2c + _do_bin2c(opt.binarypath, opt.outputpath, opt) +end diff --git a/xmake/modules/target/action/install/cmake_importfiles.lua b/xmake/modules/target/action/install/cmake_importfiles.lua index 7bfb5d636..12d044251 100644 --- a/xmake/modules/target/action/install/cmake_importfiles.lua +++ b/xmake/modules/target/action/install/cmake_importfiles.lua @@ -27,7 +27,8 @@ function _get_builtinvars(target, installdir) PROJECTNAME = project.name() or target:name(), TARGETFILENAME = path.filename(target:targetfile()), TARGETKIND = target:is_shared() and "SHARED" or "STATIC", - PACKAGE_VERSION = target:get("version") or "1.0.0"} + PACKAGE_VERSION = target:get("version") or "1.0.0", + TARGET_PTRBYTES = target:is_arch("x86", "i386") and "4" or "8"} end -- install cmake import file diff --git a/xmake/plugins/project/vstudio/impl/vs201x.lua b/xmake/plugins/project/vstudio/impl/vs201x.lua index a66761d4d..da0dd9317 100644 --- a/xmake/plugins/project/vstudio/impl/vs201x.lua +++ b/xmake/plugins/project/vstudio/impl/vs201x.lua @@ -212,7 +212,17 @@ function _make_vsinfo_archs() end else -- we use it first if global set_arch("xx") is setted in xmake.lua - vsinfo_archs = project.get("target.arch") or platform.archs() + vsinfo_archs = project.get("target.arch") + if not vsinfo_archs then + -- for set_allowedarchs() + local allowed_archs = project.allowed_archs(config.plat()) + if allowed_archs then + vsinfo_archs = allowed_archs:to_array() + end + end + if not vsinfo_archs then + vsinfo_archs = platform.archs() + end end if not vsinfo_archs or #vsinfo_archs == 0 then vsinfo_archs = { config.arch() } diff --git a/xmake/plugins/project/vsxmake/getinfo.lua b/xmake/plugins/project/vsxmake/getinfo.lua index 407e4cbe4..965e55028 100644 --- a/xmake/plugins/project/vsxmake/getinfo.lua +++ b/xmake/plugins/project/vsxmake/getinfo.lua @@ -262,7 +262,17 @@ function _make_vsinfo_archs() end else -- we use it first if global set_arch("xx") is setted in xmake.lua - vsinfo_archs = project.get("target.arch") or platform.archs() + vsinfo_archs = project.get("target.arch") + if not vsinfo_archs then + -- for set_allowedarchs() + local allowed_archs = project.allowed_archs(config.plat()) + if allowed_archs then + vsinfo_archs = allowed_archs:to_array() + end + end + if not vsinfo_archs then + vsinfo_archs = platform.archs() + end end if not vsinfo_archs or #vsinfo_archs == 0 then vsinfo_archs = { config.arch() } diff --git a/xmake/repository/packages/7/7z/patches/21.02/backport-21.03-fix-for-GCC-10.patch b/xmake/repository/packages/7/7z/patches/21.02/backport-21.03-fix-for-GCC-10.patch new file mode 100644 index 000000000..a5e7db712 --- /dev/null +++ b/xmake/repository/packages/7/7z/patches/21.02/backport-21.03-fix-for-GCC-10.patch @@ -0,0 +1,19 @@ +diff --git a/CPP/7zip/Common/OffsetStream.cpp b/CPP/7zip/Common/OffsetStream.cpp +index b3e710f..b16124c 100644 +--- a/CPP/7zip/Common/OffsetStream.cpp ++++ b/CPP/7zip/Common/OffsetStream.cpp +@@ -20,13 +20,13 @@ STDMETHODIMP COffsetOutStream::Write(const void *data, UInt32 size, UInt32 *proc + + STDMETHODIMP COffsetOutStream::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) + { +- UInt64 absoluteNewPosition; + if (seekOrigin == STREAM_SEEK_SET) + { + if (offset < 0) + return HRESULT_WIN32_ERROR_NEGATIVE_SEEK; + offset += _offset; + } ++ UInt64 absoluteNewPosition = 0; // =0 for gcc-10 + HRESULT result = _stream->Seek(offset, seekOrigin, &absoluteNewPosition); + if (newPosition) + *newPosition = absoluteNewPosition - _offset; diff --git a/xmake/repository/packages/7/7z/xmake.lua b/xmake/repository/packages/7/7z/xmake.lua index 313f5e434..afa0c38dc 100644 --- a/xmake/repository/packages/7/7z/xmake.lua +++ b/xmake/repository/packages/7/7z/xmake.lua @@ -5,7 +5,7 @@ package("7z") set_description("A file archiver with a high compression ratio.") if is_host("windows") then - if os.arch() == "x64" then + if is_arch("x64", "x86_64") then set_urls("https://github.com/xmake-mirror/7zip/releases/download/$(version)/7z$(version)-x64.zip", "https://gitlab.com/xmake-mirror/7zip-releases/raw/master/7z$(version)-x64.zip") add_versions("19.00", "fc21cf510d70a69bfa8e5b0449fe0a054fb76e2f8bd568364821f319c8b1d86d") @@ -17,24 +17,39 @@ package("7z") add_versions("18.05", "544c37bebee30437aba405071484e0ac6310332b4bdabe4ca7420a800d4b4b5e") end else - add_urls("https://github.com/xmake-mirror/p7zip/archive/$(version).zip", {alias = "github"}) - add_urls("https://gitlab.com/xmake-mirror/p7zip/-/archive/$(version)/p7zip-$(version).zip", {alias = "gitlab"}) - add_urls("https://gitee.com/xmake-mirror/p7zip.git", - "https://github.com/xmake-mirror/p7zip.git", - "https://gitlab.com/xmake-mirror/p7zip.git") - add_versions("github:16.02", "1cb98f266f8f6109d99d35473dfc8db71a9933b1dea58a89833650858e504b52") - add_versions("gitlab:16.02", "93c6a14efb6dc9ee2fbb8c8fd4b5f319537c98182f8810f3b25cfa6363d9905b") + set_urls("https://github.com/xmake-mirror/7zip/archive/refs/tags/$(version).tar.gz", + "https://github.com/xmake-mirror/7zip.git") + add_versions("21.02", "b2a4c5bec8207508b26f94507f62f5a79c57ae9ab77dbf393f3b2fc8eef2e382") + add_patches("21.02", path.join(os.scriptdir(), "patches", "21.02", "backport-21.03-fix-for-GCC-10.patch"), "f1d8fa0bbb25123b28e9b2842da07604238b77e51b918260a369f97c2f694c89") end - set_plat(os.host()) - set_arch(os.arch()) on_install("macosx", "linux", function (package) - os.vrun("make 7z") - os.cp("bin", package:installdir()) + -- Clang has some indentation warnings that fails compilation using -Werror, remove it + io.replace("CPP/7zip/7zip_gcc.mak", "CFLAGS_WARN_WALL = -Wall -Werror -Wextra", "CFLAGS_WARN_WALL = -Wall -Wextra", {plain = true}) + + os.cd("CPP/7zip/Bundles/Alone2") + os.vrun("make -j -f makefile.gcc") + + local bin = package:installdir("bin") + os.cp("_o/7zz", bin) + os.ln(bin .. "/7zz", bin .. "/7z") end) on_install("windows", function (package) os.cp("*", package:installdir("bin")) + + --[[ + Build code for windows + + local archdir = package:is_arch("x64", "x86_64") and "x64" or "x86" + os.cd("CPP/7zip/Bundles/Alone2") + local configs = {"-f", "makefile"} + table.insert(configs, "PLATFORM=" .. archdir) + import("package.tools.nmake").build(package, configs) + + local bin = package:installdir("bin") + os.cp(archdir .. "/7zz.exe", bin .. "/7z.exe") + ]] end) on_test(function (package) diff --git a/xmake/repository/packages/g/git/xmake.lua b/xmake/repository/packages/g/git/xmake.lua index df9fb6668..c90cdf241 100644 --- a/xmake/repository/packages/g/git/xmake.lua +++ b/xmake/repository/packages/g/git/xmake.lua @@ -23,8 +23,6 @@ package("git") end end end - set_plat(os.host()) - set_arch(os.arch()) on_load("windows", function (package) package:addenv("PATH", path.join("share", "MinGit", "mingw32", "bin")) diff --git a/xmake/rules/lex_yacc/lex/xmake.lua b/xmake/rules/lex_yacc/lex/xmake.lua index cbdb766e4..adc3c49ec 100644 --- a/xmake/rules/lex_yacc/lex/xmake.lua +++ b/xmake/rules/lex_yacc/lex/xmake.lua @@ -23,10 +23,8 @@ rule("lex") set_extensions(".l", ".ll") on_buildcmd_file(function (target, batchcmds, sourcefile_lex, opt) - -- imports - import("lib.detect.find_tool") - -- get lex + import("lib.detect.find_tool") local lex = assert(find_tool("flex") or find_tool("lex"), "lex not found!") -- get c/c++ source file for lex diff --git a/xmake/rules/lex_yacc/yacc/xmake.lua b/xmake/rules/lex_yacc/yacc/xmake.lua index f93db2ccb..70514cadb 100644 --- a/xmake/rules/lex_yacc/yacc/xmake.lua +++ b/xmake/rules/lex_yacc/yacc/xmake.lua @@ -23,10 +23,8 @@ rule("yacc") set_extensions(".y", ".yy") before_buildcmd_file(function (target, batchcmds, sourcefile_yacc, opt) - -- imports - import("lib.detect.find_tool") - -- get yacc + import("lib.detect.find_tool") local yacc = assert(find_tool("bison") or find_tool("yacc"), "yacc/bison not found!") -- get c/c++ source file for yacc diff --git a/xmake/rules/qt/load.lua b/xmake/rules/qt/load.lua index 407911fab..03599f7e2 100644 --- a/xmake/rules/qt/load.lua +++ b/xmake/rules/qt/load.lua @@ -22,6 +22,7 @@ import("core.base.semver") import("core.project.config") import("core.project.target") +import("core.base.hashset") import("lib.detect.find_library") -- make link for framework @@ -188,7 +189,7 @@ function main(target, opt) end -- do frameworks for qt - local useframeworks = false + local frameworksset = hashset.new() for _, framework in ipairs(target:get("frameworks")) do -- translate qt frameworks @@ -216,13 +217,13 @@ function main(target, opt) -- add includedirs if is_plat("macosx") then local frameworkdir = path.join(qt.libdir, framework .. ".framework") - if os.isdir(frameworkdir) and not framework:endswith("Support") then + if os.isdir(frameworkdir) and os.isdir(path.join(frameworkdir, "Headers")) then _add_includedirs(target, path.join(frameworkdir, "Headers")) -- e.g. QtGui.framework/Headers/5.15.0/QtGui/qpa/qplatformopenglcontext.h -- https://github.com/xmake-io/xmake/issues/1226 _add_includedirs(target, path.join(frameworkdir, "Headers", qt.sdkver)) _add_includedirs(target, path.join(frameworkdir, "Headers", qt.sdkver, framework)) - useframeworks = true + frameworksset:insert(framework) else target:add("syslinks", _link(qt.libdir, framework, qt_sdkver)) _add_includedirs(target, path.join(qt.includedir, framework)) @@ -243,9 +244,7 @@ function main(target, opt) -- remove private frameworks local local_frameworks = {} for _, framework in ipairs(target:get("frameworks")) do - if target:is_plat("macosx") and framework:endswith("Support") then - -- we need handle Qt*Support as plain links, e.g. QtPlatformSupport - elseif not framework:lower():endswith("private") then + if frameworksset:has(framework) then table.insert(local_frameworks, framework) end end @@ -264,7 +263,7 @@ function main(target, opt) if is_plat("macosx") then target:add("frameworks", "DiskArbitration", "IOKit", "CoreFoundation", "CoreGraphics", "OpenGL") target:add("frameworks", "Carbon", "Foundation", "AppKit", "Security", "SystemConfiguration") - if useframeworks then + if not frameworksset:empty() then target:add("frameworkdirs", qt.libdir) target:add("rpathdirs", "@executable_path/Frameworks", qt.libdir) else diff --git a/xmake/rules/qt/moc/xmake.lua b/xmake/rules/qt/moc/xmake.lua index 439a0b573..80ce37174 100644 --- a/xmake/rules/qt/moc/xmake.lua +++ b/xmake/rules/qt/moc/xmake.lua @@ -27,7 +27,11 @@ rule("qt.moc") import("core.tool.compiler") -- get moc - local moc = path.join(target:data("qt").bindir, is_host("windows") and "moc.exe" or "moc") + local qt = assert(target:data("qt"), "qt not found!") + local moc = path.join(qt.bindir, is_host("windows") and "moc.exe" or "moc") + if not os.isexec(moc) and qt.libexecdir then + moc = path.join(qt.libexecdir, is_host("windows") and "moc.exe" or "moc") + end assert(moc and os.isexec(moc), "moc not found!") -- get c++ source file for moc diff --git a/xmake/rules/qt/qrc/xmake.lua b/xmake/rules/qt/qrc/xmake.lua index 2529ef118..df416c2a9 100644 --- a/xmake/rules/qt/qrc/xmake.lua +++ b/xmake/rules/qt/qrc/xmake.lua @@ -24,8 +24,12 @@ rule("qt.qrc") on_load(function (target) -- get rcc - local rcc = path.join(target:data("qt").bindir, is_host("windows") and "rcc.exe" or "rcc") - assert(rcc and os.isexec(rcc), "rcc not found!") + local qt = assert(target:data("qt"), "qt not found!") + local rcc = path.join(qt.bindir, is_host("windows") and "rcc.exe" or "rcc") + if not os.isexec(rcc) and qt.libexecdir then + rcc = path.join(qt.libexecdir, is_host("windows") and "rcc.exe" or "rcc") + end + assert(os.isexec(rcc), "rcc not found!") -- save rcc target:data_set("qt.rcc", rcc) diff --git a/xmake/rules/qt/ui/xmake.lua b/xmake/rules/qt/ui/xmake.lua index b1ce103e5..dd377563b 100644 --- a/xmake/rules/qt/ui/xmake.lua +++ b/xmake/rules/qt/ui/xmake.lua @@ -24,7 +24,11 @@ rule("qt.ui") on_load(function (target) -- get uic - local uic = path.join(target:data("qt").bindir, is_host("windows") and "uic.exe" or "uic") + local qt = assert(target:data("qt"), "qt not found!") + local uic = path.join(qt.bindir, is_host("windows") and "uic.exe" or "uic") + if not os.isexec(uic) and qt.libexecdir then + uic = path.join(qt.libexecdir, is_host("windows") and "uic.exe" or "uic") + end assert(uic and os.isexec(uic), "uic not found!") -- add includedirs, @note we need create this directory first to suppress warning (file not found). diff --git a/xmake/rules/utils/bin2c/xmake.lua b/xmake/rules/utils/bin2c/xmake.lua new file mode 100644 index 000000000..12db55192 --- /dev/null +++ b/xmake/rules/utils/bin2c/xmake.lua @@ -0,0 +1,46 @@ +--!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 +-- + +rule("utils.bin2c") + set_extensions(".bin") + before_buildcmd_file(function (target, batchcmds, sourcefile_bin, opt) + + -- get header file + local headerdir = path.join(target:autogendir(), "rules", "c++", "bin2c") + local headerfile = path.join(headerdir, path.filename(sourcefile_bin) .. ".h") + target:add("includedirs", headerdir) + + -- add commands + batchcmds:show_progress(opt.progress, "${color.build.object}generating.bin2c %s", sourcefile_bin) + batchcmds:mkdir(headerdir) + local argv = {"lua", "private.utils.bin2c", "-i", sourcefile_bin, "-o", headerfile} + local linewidth = target:extraconf("rules", "utils.bin2c", "linewidth") + if linewidth then + table.insert(argv, "-w") + table.insert(argv, tostring(linewidth)) + end + batchcmds:vrunv(os.programfile(), argv) + + -- add deps + batchcmds:add_depfiles(sourcefile_bin) + batchcmds:set_depmtime(os.mtime(headerfile)) + batchcmds:set_depcache(target:dependfile(headerfile)) + end) + diff --git a/xmake/rules/vala/xmake.lua b/xmake/rules/vala/xmake.lua new file mode 100644 index 000000000..a2ce76937 --- /dev/null +++ b/xmake/rules/vala/xmake.lua @@ -0,0 +1,64 @@ +--!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 +-- + +rule("vala") + set_extensions(".vala") + on_load(function (target) + -- only vala source files? we need patch c source kind for linker + local sourcekinds = target:sourcekinds() + if #sourcekinds == 0 then + table.insert(sourcekinds, "cc") + end + end) + before_buildcmd_file(function (target, batchcmds, sourcefile_vala, opt) + + -- get valac + import("lib.detect.find_tool") + local valac = assert(find_tool("valac"), "valac not found!") + + -- get c source file for vala + local sourcefile_c = target:autogenfile((sourcefile_vala:gsub(".vala$", ".c"))) + local basedir = path.directory(sourcefile_c) + + -- add objectfile + local objectfile = target:objectfile(sourcefile_c) + table.insert(target:objectfiles(), objectfile) + + -- add commands + batchcmds:show_progress(opt.progress, "${color.build.object}compiling.vala %s", sourcefile_vala) + batchcmds:mkdir(basedir) + local argv = {"-C", "-b", basedir} + local packages = target:values("vala.packages") + if packages then + for _, package in ipairs(packages) do + table.insert(argv, "--pkg") + table.insert(argv, package) + end + end + table.insert(argv, sourcefile_vala) + batchcmds:vrunv(valac.program, argv) + batchcmds:compile(sourcefile_c, objectfile) + + -- add deps + batchcmds:add_depfiles(sourcefile_vala) + batchcmds:set_depmtime(os.mtime(objectfile)) + batchcmds:set_depcache(target:dependfile(objectfile)) + end) + diff --git a/xmake/scripts/cmake_importfiles/xxxConfigVersion.cmake b/xmake/scripts/cmake_importfiles/xxxConfigVersion.cmake index 68ca4fbd6..f09774e12 100644 --- a/xmake/scripts/cmake_importfiles/xxxConfigVersion.cmake +++ b/xmake/scripts/cmake_importfiles/xxxConfigVersion.cmake @@ -41,8 +41,8 @@ if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "" OR "8" STREQUAL "") endif() # check that the installed version has the same 32/64bit-ness as the one which is currently searching: -if(NOT CMAKE_SIZEOF_VOID_P STREQUAL "8") - math(EXPR installedBits "8 * 8") +if(NOT CMAKE_SIZEOF_VOID_P STREQUAL "@TARGET_PTRBYTES@") + math(EXPR installedBits "@TARGET_PTRBYTES@ * 8") set(PACKAGE_VERSION "${PACKAGE_VERSION} (${installedBits}bit)") set(PACKAGE_VERSION_UNSUITABLE TRUE) endif() |
