From d9c46764bb2e906e7cf8e98ddd70969472ed1c19 Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 5 Oct 2020 23:16:36 +0800 Subject: add initial icc files --- xmake/modules/core/tools/icc.lua | 31 +++++++++++ xmake/modules/core/tools/icl.lua | 31 +++++++++++ xmake/modules/core/tools/icpc.lua | 28 ++++++++++ xmake/modules/detect/tools/find_icc.lua | 52 ++++++++++++++++++ xmake/modules/detect/tools/find_icl.lua | 52 ++++++++++++++++++ xmake/modules/detect/tools/find_icpc.lua | 52 ++++++++++++++++++ xmake/modules/detect/tools/icc/has_flags.lua | 23 ++++++++ xmake/modules/detect/tools/icl/has_flags.lua | 23 ++++++++ xmake/modules/detect/tools/icpc/has_flags.lua | 23 ++++++++ xmake/toolchains/icc/xmake.lua | 77 +++++++++++++++++++++++++++ 10 files changed, 392 insertions(+) create mode 100644 xmake/modules/core/tools/icc.lua create mode 100644 xmake/modules/core/tools/icl.lua create mode 100644 xmake/modules/core/tools/icpc.lua create mode 100644 xmake/modules/detect/tools/find_icc.lua create mode 100644 xmake/modules/detect/tools/find_icl.lua create mode 100644 xmake/modules/detect/tools/find_icpc.lua create mode 100644 xmake/modules/detect/tools/icc/has_flags.lua create mode 100644 xmake/modules/detect/tools/icl/has_flags.lua create mode 100644 xmake/modules/detect/tools/icpc/has_flags.lua create mode 100644 xmake/toolchains/icc/xmake.lua diff --git a/xmake/modules/core/tools/icc.lua b/xmake/modules/core/tools/icc.lua new file mode 100644 index 000000000..9a0eabac1 --- /dev/null +++ b/xmake/modules/core/tools/icc.lua @@ -0,0 +1,31 @@ +--!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-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file icc.lua +-- + +-- inherit gcc +inherit("gcc") + +-- init it +function init(self) + _super.init(self) +end + +-- TODO +-- inherit gcc.lua and override some interfaces in gcc.lua +-- ... diff --git a/xmake/modules/core/tools/icl.lua b/xmake/modules/core/tools/icl.lua new file mode 100644 index 000000000..bd2bd5e14 --- /dev/null +++ b/xmake/modules/core/tools/icl.lua @@ -0,0 +1,31 @@ +--!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-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file icl.lua +-- + +-- inherit cl +inherit("cl") + +-- init it +function init(self) + +end + +-- TODO +-- inherit cl.lua and override some interfaces in cl.lua +-- ... diff --git a/xmake/modules/core/tools/icpc.lua b/xmake/modules/core/tools/icpc.lua new file mode 100644 index 000000000..6639bfcfe --- /dev/null +++ b/xmake/modules/core/tools/icpc.lua @@ -0,0 +1,28 @@ +--!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-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file icpc.lua +-- + +-- inherit gcc +inherit("gcc") + +-- init it +function init(self) + _super.init(self) +end + diff --git a/xmake/modules/detect/tools/find_icc.lua b/xmake/modules/detect/tools/find_icc.lua new file mode 100644 index 000000000..789a16a9e --- /dev/null +++ b/xmake/modules/detect/tools/find_icc.lua @@ -0,0 +1,52 @@ +--!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-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file find_icc.lua +-- + +-- imports +import("lib.detect.find_program") +import("lib.detect.find_programver") + +-- find icc +-- +-- @param opt the argument options, e.g. {version = true} +-- +-- @return program, version +-- +-- @code +-- +-- local icc = find_icc() +-- local icc, version, hintname = find_icc({program = "icc", version = true}) +-- +-- @endcode +-- +function main(opt) + + -- init options + opt = opt or {} + + -- find program + local program = find_program(opt.program or "icc", 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_icl.lua b/xmake/modules/detect/tools/find_icl.lua new file mode 100644 index 000000000..f61f0ce76 --- /dev/null +++ b/xmake/modules/detect/tools/find_icl.lua @@ -0,0 +1,52 @@ +--!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-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file find_icl.lua +-- + +-- imports +import("lib.detect.find_program") +import("lib.detect.find_programver") + +-- find icl +-- +-- @param opt the argument options, e.g. {version = true} +-- +-- @return program, version +-- +-- @code +-- +-- local icl = find_icl() +-- local icl, version, hintname = find_icl({program = "icl", version = true}) +-- +-- @endcode +-- +function main(opt) + + -- init options + opt = opt or {} + + -- find program + local program = find_program(opt.program or "icl", 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_icpc.lua b/xmake/modules/detect/tools/find_icpc.lua new file mode 100644 index 000000000..6c806cad6 --- /dev/null +++ b/xmake/modules/detect/tools/find_icpc.lua @@ -0,0 +1,52 @@ +--!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-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file find_icpc.lua +-- + +-- imports +import("lib.detect.find_program") +import("lib.detect.find_programver") + +-- find icpc +-- +-- @param opt the argument options, e.g. {version = true} +-- +-- @return program, version +-- +-- @code +-- +-- local icpc = find_icpc() +-- local icpc, version, hintname = find_icpc({program = "icpc", version = true}) +-- +-- @endcode +-- +function main(opt) + + -- init options + opt = opt or {} + + -- find program + local program = find_program(opt.program or "icpc", 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/icc/has_flags.lua b/xmake/modules/detect/tools/icc/has_flags.lua new file mode 100644 index 000000000..6ac2ce551 --- /dev/null +++ b/xmake/modules/detect/tools/icc/has_flags.lua @@ -0,0 +1,23 @@ +--!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-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file has_flags.lua +-- + +-- imports +inherit("detect.tools.gcc.has_flags") + diff --git a/xmake/modules/detect/tools/icl/has_flags.lua b/xmake/modules/detect/tools/icl/has_flags.lua new file mode 100644 index 000000000..81573039e --- /dev/null +++ b/xmake/modules/detect/tools/icl/has_flags.lua @@ -0,0 +1,23 @@ +--!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-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file has_flags.lua +-- + +-- imports +inherit("detect.tools.cl.has_flags") + diff --git a/xmake/modules/detect/tools/icpc/has_flags.lua b/xmake/modules/detect/tools/icpc/has_flags.lua new file mode 100644 index 000000000..50d4f59d9 --- /dev/null +++ b/xmake/modules/detect/tools/icpc/has_flags.lua @@ -0,0 +1,23 @@ +--!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-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file has_flags.lua +-- + +-- imports +inherit("detect.tools.gxx.has_flags") + diff --git a/xmake/toolchains/icc/xmake.lua b/xmake/toolchains/icc/xmake.lua new file mode 100644 index 000000000..2b501c846 --- /dev/null +++ b/xmake/toolchains/icc/xmake.lua @@ -0,0 +1,77 @@ +--!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-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file xmake.lua +-- + +-- define toolchain +toolchain("icc") + + -- set homepage + set_homepage("https://software.intel.com/content/www/us/en/develop/tools/compilers/c-compilers.html") + set_description("Intel C/C++ Compiler") + + -- mark as standalone toolchain + set_kind("standalone") + + -- check toolchain + on_check(function (toolchain) + return import("lib.detect.find_tool")(toolchain:is_plat("windows") and "icl" or "icc") + end) + + -- on load + on_load(function (toolchain) + + -- set toolset + toolchain:set("toolset", "cc", "icc") + toolchain:set("toolset", "cxx", "icc", "icpc") + toolchain:set("toolset", "ld", "g++", "icc") -- TODO g++/clang++ as linker, i++? icpc? .. + toolchain:set("toolset", "sh", "g++", "icc") + toolchain:set("toolset", "ar", "ar") + toolchain:set("toolset", "ex", "ar") + toolchain:set("toolset", "strip", "strip") + toolchain:set("toolset", "as", "icc") + + -- add march flags + local march + if toolchain:is_arch("x86_64", "x64") then + march = "-m64" + elseif toolchain:is_arch("i386", "x86") then + march = "-m32" + end + if march then + toolchain:add("cxflags", march) + toolchain:add("mxflags", march) + toolchain:add("asflags", march) + toolchain:add("ldflags", march) + toolchain:add("shflags", march) + end + + -- add includedirs and linkdirs + if not toolchain:is_plat("windows") and os.isdir("/usr") then + for _, includedir in ipairs({"/usr/local/include", "/usr/include"}) do + if os.isdir(includedir) then + toolchain:add("includedirs", includedir) + end + end + for _, linkdir in ipairs({"/usr/local/lib", "/usr/lib"}) do + if os.isdir(linkdir) then + toolchain:add("linkdirs", linkdir) + end + end + end + end) -- cgit v1.3.1 From b3693176780c056c66fb2aa1e6e2f251242368c4 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 7 Oct 2020 00:26:35 +0800 Subject: support icc toolchain for macosx/linux --- xmake/toolchains/icc/xmake.lua | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/xmake/toolchains/icc/xmake.lua b/xmake/toolchains/icc/xmake.lua index 2b501c846..93a851562 100644 --- a/xmake/toolchains/icc/xmake.lua +++ b/xmake/toolchains/icc/xmake.lua @@ -37,14 +37,29 @@ toolchain("icc") on_load(function (toolchain) -- set toolset - toolchain:set("toolset", "cc", "icc") - toolchain:set("toolset", "cxx", "icc", "icpc") - toolchain:set("toolset", "ld", "g++", "icc") -- TODO g++/clang++ as linker, i++? icpc? .. - toolchain:set("toolset", "sh", "g++", "icc") - toolchain:set("toolset", "ar", "ar") - toolchain:set("toolset", "ex", "ar") - toolchain:set("toolset", "strip", "strip") - toolchain:set("toolset", "as", "icc") + if toolchain:is_plat("windows") then + toolchain:set("toolset", "cc", "icl.exe") + toolchain:set("toolset", "cxx", "icl.exe") + toolchain:set("toolset", "mrc", "rc.exe") + if toolchain:is_arch("x64") then + toolchain:set("toolset", "as", "ml64.exe") + else + toolchain:set("toolset", "as", "ml.exe") + end + toolchain:set("toolset", "ld", "link.exe") + toolchain:set("toolset", "sh", "link.exe") + toolchain:set("toolset", "ar", "link.exe") + toolchain:set("toolset", "ex", "lib.exe") + else + toolchain:set("toolset", "cc", "icc") + toolchain:set("toolset", "cxx", "icpc", "icc") + toolchain:set("toolset", "ld", "icpc", "icc") + toolchain:set("toolset", "sh", "icpc", "icc") + toolchain:set("toolset", "ar", "ar") + toolchain:set("toolset", "ex", "ar") + toolchain:set("toolset", "strip", "strip") + toolchain:set("toolset", "as", "icc") + end -- add march flags local march -- cgit v1.3.1 From acc4c79235d585c6c3f05aaf3d2c6e11adb076ff Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 7 Oct 2020 00:34:30 +0800 Subject: add find_intel --- xmake/modules/detect/sdks/find_intel.lua | 170 +++++++++++++++++++++++++++++++ xmake/toolchains/icc/check.lua | 44 ++++++++ xmake/toolchains/icc/load.lua | 103 +++++++++++++++++++ xmake/toolchains/icc/xmake.lua | 61 +---------- 4 files changed, 319 insertions(+), 59 deletions(-) create mode 100644 xmake/modules/detect/sdks/find_intel.lua create mode 100644 xmake/toolchains/icc/check.lua create mode 100644 xmake/toolchains/icc/load.lua diff --git a/xmake/modules/detect/sdks/find_intel.lua b/xmake/modules/detect/sdks/find_intel.lua new file mode 100644 index 000000000..cac5a5ca1 --- /dev/null +++ b/xmake/modules/detect/sdks/find_intel.lua @@ -0,0 +1,170 @@ +--!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-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file find_intel.lua +-- + +-- imports +import("lib.detect.find_file") +import("lib.detect.find_tool") + +--[[ +-- init vc variables +local vcvars = {"path", + "lib", + "libpath", + "include", + "DevEnvdir", + "VSInstallDir", + "VCInstallDir", + "WindowsSdkDir", + "WindowsLibPath", + "WindowsSDKVersion", + "WindowsSdkBinPath", + "UniversalCRTSdkDir", + "UCRTVersion"} + +-- load iclvars environment variables +function _load_iclvars(iclvars, vsver, arch, opt) + + -- make the genvcvars.bat + opt = opt or {} + local genvcvars_bat = os.tmpfile() .. "_genvcvars.bat" + local genvcvars_dat = os.tmpfile() .. "_genvcvars.txt" + local file = io.open(genvcvars_bat, "w") + file:print("@echo off") + -- fix error caused by the new vsDevCmd.bat of vs2019 + -- @see https://github.com/xmake-io/xmake/issues/549 + if vsver and tonumber(vsver) >= 16 then + file:print("set VSCMD_SKIP_SENDTELEMETRY=yes") + end + if opt.vcvars_ver then + file:print("call \"%s\" %s %s -vcvars_ver=%s > nul", iclvars, arch, opt.sdkver and opt.sdkver or "", opt.vcvars_ver) + else + file:print("call \"%s\" %s %s > nul", iclvars, arch, opt.sdkver and opt.sdkver or "") + end + for idx, var in ipairs(vcvars) do + file:print("echo " .. var .. " = %%" .. var .. "%% %s %s", idx == 1 and ">" or ">>", genvcvars_dat) + end + file:close() + + -- run genvcvars.bat + os.run(genvcvars_bat) + + -- load all envirnoment variables + local variables = {} + for _, line in ipairs((io.readfile(genvcvars_dat) or ""):split("\n")) do + local p = line:find('=', 1, true) + if p then + local name = line:sub(1, p - 1):trim() + local value = line:sub(p + 1):trim() + variables[name] = value + end + end + if not variables.path then + return + end + + -- remove some empty entries + for _, name in ipairs(vcvars) do + if variables[name] and #variables[name]:trim() == 0 then + variables[name] = nil + end + end + + -- fix WindowsSDKVersion + local WindowsSDKVersion = variables["WindowsSDKVersion"] + if WindowsSDKVersion then + WindowsSDKVersion = WindowsSDKVersion:gsub("\\", ""):trim() + if WindowsSDKVersion ~= "" then + variables["WindowsSDKVersion"] = WindowsSDKVersion + end + end + + -- fix UCRTVersion + -- + -- @note iclvars.bat maybe detect error if install WDK and SDK at same time (multi-sdk version exists in include directory). + -- + local UCRTVersion = variables["UCRTVersion"] + if UCRTVersion and WindowsSDKVersion and UCRTVersion ~= WindowsSDKVersion and WindowsSDKVersion ~= "" then + local lib = variables["lib"] + if lib then + lib = lib:gsub(UCRTVersion, WindowsSDKVersion) + variables["lib"] = lib + end + local include = variables["include"] + if include then + include = include:gsub(UCRTVersion, WindowsSDKVersion) + variables["include"] = include + end + UCRTVersion = WindowsSDKVersion + variables["UCRTVersion"] = UCRTVersion + end + + -- convert path/lib/include to PATH/LIB/INCLUDE + variables.PATH = variables.path + variables.LIB = variables.lib + variables.LIBPATH = variables.libpath + variables.INCLUDE = variables.include + variables.path = nil + variables.lib = nil + variables.include = nil + variables.libpath = nil + + -- ok + return variables +end + +-- find intel envirnoment on windows +function _find_intel_on_windows(opt) + + -- init options + opt = opt or {} + + -- find iclvars.bat, vcvars32.bat for vs7.1 + local iclvars = find_file("iclvars.bat", paths) or find_file("vcvars32.bat", paths) + if iclvars then + + -- load iclvars + local iclvars_x86 = _load_iclvars(iclvars, version, "x86", opt) + local iclvars_x64 = _load_iclvars(iclvars, version, "x64", opt) +]] + -- save results + -- results[vsvers[version]] = {version = version, iclvars_bat = iclvars, iclvars = {x86 = iclvars_x86, x64 = iclvars_x64}} + -- end +--end + +-- find intel envirnoment on linux +function _find_intel_on_linux(opt) + + -- attempt to find the sdk directory + local paths = {"/opt/intel/bin", "/usr/local/bin", "/usr/bin"} + local icc = find_file("icc", paths) + if icc then + local sdkdir = path.directory(path.directory(icc)) + return {sdkdir = sdkdir, bindir = path.directory(icc), path.join(sdkdir, "include"), libdir = path.join(sdkdir, "lib")} + end +end + +-- find intel environment +function main(opt) + if is_host("windows") then + return _find_intel_on_windows(opt) + else + return _find_intel_on_linux(opt) + end +end diff --git a/xmake/toolchains/icc/check.lua b/xmake/toolchains/icc/check.lua new file mode 100644 index 000000000..a5254f20f --- /dev/null +++ b/xmake/toolchains/icc/check.lua @@ -0,0 +1,44 @@ +--!A cross-toolchain 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-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file check.lua +-- + +-- imports +import("core.base.option") +import("core.project.config") +import("detect.sdks.find_intel") +import("lib.detect.find_tool") + +-- check intel on windows +function _check_intel_on_windows(toolchain) +end + +-- check intel on linux +function _check_intel_on_linux(toolchain) + return find_tool("icc") +end + +-- main entry +function main(toolchain) + if is_host("windows") then + return _check_intel_on_windows(toolchain) + else + return _check_intel_on_linux(toolchain) + end +end + diff --git a/xmake/toolchains/icc/load.lua b/xmake/toolchains/icc/load.lua new file mode 100644 index 000000000..1265ac731 --- /dev/null +++ b/xmake/toolchains/icc/load.lua @@ -0,0 +1,103 @@ +--!A cross-toolchain 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-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file load.lua +-- + +-- imports +import("core.base.option") +import("core.project.config") + +-- load intel on windows +function _load_intel_on_windows(toolchain) + + -- set toolset + if toolchain:is_plat("windows") then + toolchain:set("toolset", "cc", "icl.exe") + toolchain:set("toolset", "cxx", "icl.exe") + toolchain:set("toolset", "mrc", "rc.exe") + if toolchain:is_arch("x64") then + toolchain:set("toolset", "as", "ml64.exe") + else + toolchain:set("toolset", "as", "ml.exe") + end + toolchain:set("toolset", "ld", "link.exe") + toolchain:set("toolset", "sh", "link.exe") + toolchain:set("toolset", "ar", "link.exe") + toolchain:set("toolset", "ex", "lib.exe") + else + toolchain:set("toolset", "cc", "icc") + toolchain:set("toolset", "cxx", "icpc", "icc") + toolchain:set("toolset", "ld", "icpc", "icc") + toolchain:set("toolset", "sh", "icpc", "icc") + toolchain:set("toolset", "ar", "ar") + toolchain:set("toolset", "ex", "ar") + toolchain:set("toolset", "strip", "strip") + toolchain:set("toolset", "as", "icc") + end +end + +-- load intel on linux +function _load_intel_on_linux(toolchain) + + -- set toolset + toolchain:set("toolset", "cc", "icc") + toolchain:set("toolset", "cxx", "icpc", "icc") + toolchain:set("toolset", "ld", "icpc", "icc") + toolchain:set("toolset", "sh", "icpc", "icc") + toolchain:set("toolset", "ar", "ar") + toolchain:set("toolset", "ex", "ar") + toolchain:set("toolset", "strip", "strip") + toolchain:set("toolset", "as", "icc") + + -- add march flags + local march + if toolchain:is_arch("x86_64", "x64") then + march = "-m64" + elseif toolchain:is_arch("i386", "x86") then + march = "-m32" + end + if march then + toolchain:add("cxflags", march) + toolchain:add("mxflags", march) + toolchain:add("asflags", march) + toolchain:add("ldflags", march) + toolchain:add("shflags", march) + end + + -- add includedirs and linkdirs + for _, includedir in ipairs({"/usr/local/include", "/usr/include"}) do + if os.isdir(includedir) then + toolchain:add("includedirs", includedir) + end + end + for _, linkdir in ipairs({"/usr/local/lib", "/usr/lib"}) do + if os.isdir(linkdir) then + toolchain:add("linkdirs", linkdir) + end + end +end + +-- main entry +function main(toolchain) + if is_host("windows") then + return _load_intel_on_windows(toolchain) + else + return _load_intel_on_linux(toolchain) + end +end + diff --git a/xmake/toolchains/icc/xmake.lua b/xmake/toolchains/icc/xmake.lua index 93a851562..2cf971f0c 100644 --- a/xmake/toolchains/icc/xmake.lua +++ b/xmake/toolchains/icc/xmake.lua @@ -29,64 +29,7 @@ toolchain("icc") set_kind("standalone") -- check toolchain - on_check(function (toolchain) - return import("lib.detect.find_tool")(toolchain:is_plat("windows") and "icl" or "icc") - end) + on_check("check") -- on load - on_load(function (toolchain) - - -- set toolset - if toolchain:is_plat("windows") then - toolchain:set("toolset", "cc", "icl.exe") - toolchain:set("toolset", "cxx", "icl.exe") - toolchain:set("toolset", "mrc", "rc.exe") - if toolchain:is_arch("x64") then - toolchain:set("toolset", "as", "ml64.exe") - else - toolchain:set("toolset", "as", "ml.exe") - end - toolchain:set("toolset", "ld", "link.exe") - toolchain:set("toolset", "sh", "link.exe") - toolchain:set("toolset", "ar", "link.exe") - toolchain:set("toolset", "ex", "lib.exe") - else - toolchain:set("toolset", "cc", "icc") - toolchain:set("toolset", "cxx", "icpc", "icc") - toolchain:set("toolset", "ld", "icpc", "icc") - toolchain:set("toolset", "sh", "icpc", "icc") - toolchain:set("toolset", "ar", "ar") - toolchain:set("toolset", "ex", "ar") - toolchain:set("toolset", "strip", "strip") - toolchain:set("toolset", "as", "icc") - end - - -- add march flags - local march - if toolchain:is_arch("x86_64", "x64") then - march = "-m64" - elseif toolchain:is_arch("i386", "x86") then - march = "-m32" - end - if march then - toolchain:add("cxflags", march) - toolchain:add("mxflags", march) - toolchain:add("asflags", march) - toolchain:add("ldflags", march) - toolchain:add("shflags", march) - end - - -- add includedirs and linkdirs - if not toolchain:is_plat("windows") and os.isdir("/usr") then - for _, includedir in ipairs({"/usr/local/include", "/usr/include"}) do - if os.isdir(includedir) then - toolchain:add("includedirs", includedir) - end - end - for _, linkdir in ipairs({"/usr/local/lib", "/usr/lib"}) do - if os.isdir(linkdir) then - toolchain:add("linkdirs", linkdir) - end - end - end - end) + on_load("load") -- cgit v1.3.1 From ed9243b5b503c00057b10efb7cf6ee82eb9c35c5 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 7 Oct 2020 00:53:57 +0800 Subject: support icl for windows --- xmake/modules/detect/sdks/find_intel.lua | 122 +++++++++++-------------------- xmake/modules/detect/tools/find_icl.lua | 12 ++- xmake/toolchains/icc/check.lua | 28 +++++++ xmake/toolchains/icc/load.lua | 26 +++++++ 4 files changed, 103 insertions(+), 85 deletions(-) diff --git a/xmake/modules/detect/sdks/find_intel.lua b/xmake/modules/detect/sdks/find_intel.lua index cac5a5ca1..a5ddc95e0 100644 --- a/xmake/modules/detect/sdks/find_intel.lua +++ b/xmake/modules/detect/sdks/find_intel.lua @@ -22,52 +22,42 @@ import("lib.detect.find_file") import("lib.detect.find_tool") ---[[ -- init vc variables -local vcvars = {"path", - "lib", - "libpath", - "include", - "DevEnvdir", - "VSInstallDir", - "VCInstallDir", - "WindowsSdkDir", - "WindowsLibPath", - "WindowsSDKVersion", - "WindowsSdkBinPath", - "UniversalCRTSdkDir", - "UCRTVersion"} - --- load iclvars environment variables -function _load_iclvars(iclvars, vsver, arch, opt) - - -- make the genvcvars.bat +local iclvars = {"path", + "lib", + "libpath", + "include", + "DevEnvdir", + "VSInstallDir", + "VCInstallDir", + "WindowsSdkDir", + "WindowsLibPath", + "WindowsSDKVersion", + "WindowsSdkBinPath", + "UniversalCRTSdkDir", + "UCRTVersion"} + +-- load iclvars_bat environment variables +function _load_iclvars(iclvars_bat, arch, opt) + + -- make the geniclvars.bat opt = opt or {} - local genvcvars_bat = os.tmpfile() .. "_genvcvars.bat" - local genvcvars_dat = os.tmpfile() .. "_genvcvars.txt" - local file = io.open(genvcvars_bat, "w") + local geniclvars_bat = os.tmpfile() .. "_geniclvars.bat" + local geniclvars_dat = os.tmpfile() .. "_geniclvars.txt" + local file = io.open(geniclvars_bat, "w") file:print("@echo off") - -- fix error caused by the new vsDevCmd.bat of vs2019 - -- @see https://github.com/xmake-io/xmake/issues/549 - if vsver and tonumber(vsver) >= 16 then - file:print("set VSCMD_SKIP_SENDTELEMETRY=yes") - end - if opt.vcvars_ver then - file:print("call \"%s\" %s %s -vcvars_ver=%s > nul", iclvars, arch, opt.sdkver and opt.sdkver or "", opt.vcvars_ver) - else - file:print("call \"%s\" %s %s > nul", iclvars, arch, opt.sdkver and opt.sdkver or "") - end - for idx, var in ipairs(vcvars) do - file:print("echo " .. var .. " = %%" .. var .. "%% %s %s", idx == 1 and ">" or ">>", genvcvars_dat) + file:print("call \"%s\" -arch %s > nul", iclvars_bat, arch) + for idx, var in ipairs(iclvars) do + file:print("echo " .. var .. " = %%" .. var .. "%% %s %s", idx == 1 and ">" or ">>", geniclvars_dat) end file:close() - -- run genvcvars.bat - os.run(genvcvars_bat) + -- run geniclvars.bat + os.run(geniclvars_bat) -- load all envirnoment variables local variables = {} - for _, line in ipairs((io.readfile(genvcvars_dat) or ""):split("\n")) do + for _, line in ipairs((io.readfile(geniclvars_dat) or ""):split("\n")) do local p = line:find('=', 1, true) if p then local name = line:sub(1, p - 1):trim() @@ -80,41 +70,12 @@ function _load_iclvars(iclvars, vsver, arch, opt) end -- remove some empty entries - for _, name in ipairs(vcvars) do + for _, name in ipairs(iclvars) do if variables[name] and #variables[name]:trim() == 0 then variables[name] = nil end end - -- fix WindowsSDKVersion - local WindowsSDKVersion = variables["WindowsSDKVersion"] - if WindowsSDKVersion then - WindowsSDKVersion = WindowsSDKVersion:gsub("\\", ""):trim() - if WindowsSDKVersion ~= "" then - variables["WindowsSDKVersion"] = WindowsSDKVersion - end - end - - -- fix UCRTVersion - -- - -- @note iclvars.bat maybe detect error if install WDK and SDK at same time (multi-sdk version exists in include directory). - -- - local UCRTVersion = variables["UCRTVersion"] - if UCRTVersion and WindowsSDKVersion and UCRTVersion ~= WindowsSDKVersion and WindowsSDKVersion ~= "" then - local lib = variables["lib"] - if lib then - lib = lib:gsub(UCRTVersion, WindowsSDKVersion) - variables["lib"] = lib - end - local include = variables["include"] - if include then - include = include:gsub(UCRTVersion, WindowsSDKVersion) - variables["include"] = include - end - UCRTVersion = WindowsSDKVersion - variables["UCRTVersion"] = UCRTVersion - end - -- convert path/lib/include to PATH/LIB/INCLUDE variables.PATH = variables.path variables.LIB = variables.lib @@ -124,8 +85,6 @@ function _load_iclvars(iclvars, vsver, arch, opt) variables.lib = nil variables.include = nil variables.libpath = nil - - -- ok return variables end @@ -135,18 +94,19 @@ function _find_intel_on_windows(opt) -- init options opt = opt or {} - -- find iclvars.bat, vcvars32.bat for vs7.1 - local iclvars = find_file("iclvars.bat", paths) or find_file("vcvars32.bat", paths) - if iclvars then - - -- load iclvars - local iclvars_x86 = _load_iclvars(iclvars, version, "x86", opt) - local iclvars_x64 = _load_iclvars(iclvars, version, "x64", opt) -]] - -- save results - -- results[vsvers[version]] = {version = version, iclvars_bat = iclvars, iclvars = {x86 = iclvars_x86, x64 = iclvars_x64}} - -- end ---end + -- find iclvars_bat.bat + local paths = {"$(env ICPP_COMPILER20)"} + local iclvars_bat = find_file("bin/iclvars.bat", paths) + if iclvars_bat then + + -- load iclvars_bat + local iclvars_x86 = _load_iclvars(iclvars_bat, "ia32", opt) + local iclvars_x64 = _load_iclvars(iclvars_bat, "intel64", opt) + + -- save results + return {iclvars_bat = iclvars_bat, iclvars = {x86 = iclvars_x86, x64 = iclvars_x64}} + end +end -- find intel envirnoment on linux function _find_intel_on_linux(opt) diff --git a/xmake/modules/detect/tools/find_icl.lua b/xmake/modules/detect/tools/find_icl.lua index f61f0ce76..ac0008c0e 100644 --- a/xmake/modules/detect/tools/find_icl.lua +++ b/xmake/modules/detect/tools/find_icl.lua @@ -38,15 +38,19 @@ import("lib.detect.find_programver") function main(opt) -- init options - opt = opt or {} + opt = opt or {} + opt.check = opt.check or function (program) os.runv(program, {"/help"}, {envs = opt.envs}) end -- find program - local program = find_program(opt.program or "icl", opt) + local program = find_program(opt.program or "icl.exe", opt) -- find program version local version = nil - if program and opt.version then - version = find_programver(program, opt) + if program and opt and opt.version then + opt.command = opt.command or function () local _, info = os.iorunv(program, {"/help"}, {envs = opt.envs}); return info end + opt.parse = opt.parse or function (output) return output:match("Version (%d+%.?%d*%.?%d*.-)%s") end + version = find_programver(program, opt) end return program, version end + diff --git a/xmake/toolchains/icc/check.lua b/xmake/toolchains/icc/check.lua index a5254f20f..4cbc9f5d2 100644 --- a/xmake/toolchains/icc/check.lua +++ b/xmake/toolchains/icc/check.lua @@ -26,6 +26,34 @@ import("lib.detect.find_tool") -- check intel on windows function _check_intel_on_windows(toolchain) + + -- have been checked? + if config.get("__iclvarsall") then + return true + end + + -- find intel + local intel = find_intel() + if intel and intel.iclvars then + local iclvarsall = intel.iclvars + local iclenv = iclvarsall[toolchain:arch()] + if iclenv and iclenv.PATH and iclenv.INCLUDE and iclenv.LIB then + + -- save iclvars + config.set("__iclvarsall", iclvarsall) + + -- check compiler + local program = nil + local tool = find_tool("icl.exe", {force = true, envs = iclenv, version = true}) + if tool then + program = tool.program + end + if program then + cprint("checking for Intel C/C++ Compiler (%s) ... ${color.success}${text.success}", toolchain:arch()) + return true + end + end + end end -- check intel on linux diff --git a/xmake/toolchains/icc/load.lua b/xmake/toolchains/icc/load.lua index 1265ac731..c854b7b91 100644 --- a/xmake/toolchains/icc/load.lua +++ b/xmake/toolchains/icc/load.lua @@ -22,6 +22,26 @@ import("core.base.option") import("core.project.config") +-- add the given icl environment +function _add_iclenv(toolchain, name) + + -- get iclvarsall + local iclvarsall = config.get("__iclvarsall") + if not iclvarsall then + return + end + + -- get icl environment for the current arch + local arch = toolchain:arch() + local iclenv = iclvarsall[arch] or {} + + -- get the paths for the icl environment + local env = iclenv[name] + if env then + toolchain:add("runenvs", name:upper(), path.splitenv(env)) + end +end + -- load intel on windows function _load_intel_on_windows(toolchain) @@ -49,6 +69,12 @@ function _load_intel_on_windows(toolchain) toolchain:set("toolset", "strip", "strip") toolchain:set("toolset", "as", "icc") end + + -- add icl environments + _add_iclenv(toolchain, "PATH") + _add_iclenv(toolchain, "LIB") + _add_iclenv(toolchain, "INCLUDE") + _add_iclenv(toolchain, "LIBPATH") end -- load intel on linux -- cgit v1.3.1 From 846a3cfff907e7f533498db62bafa2fc96a37606 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 7 Oct 2020 00:57:35 +0800 Subject: fix bin path for icl/ia32 --- xmake/modules/detect/sdks/find_intel.lua | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/xmake/modules/detect/sdks/find_intel.lua b/xmake/modules/detect/sdks/find_intel.lua index a5ddc95e0..f6edfaafd 100644 --- a/xmake/modules/detect/sdks/find_intel.lua +++ b/xmake/modules/detect/sdks/find_intel.lua @@ -76,6 +76,11 @@ function _load_iclvars(iclvars_bat, arch, opt) end end + -- fix bin path for ia32 + if variables.path and arch == "ia32" then + variables.path = variables.path:gsub("windows\\bin\\intel64;", "windows\\bin\\intel64_ia32;") + end + -- convert path/lib/include to PATH/LIB/INCLUDE variables.PATH = variables.path variables.LIB = variables.lib -- cgit v1.3.1 From 0797bc2920576fa61ddf520996e7237569d804b6 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 7 Oct 2020 00:58:15 +0800 Subject: update changelog and readme --- CHANGELOG.md | 2 ++ README.md | 1 + README_zh.md | 1 + 3 files changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 68a9900ba..531e03436 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ * Upgrade luajit vm and support for runing on mips64 device * [#972](https://github.com/xmake-io/xmake/issues/972): Add `depend.on_changed()` api to simplify adding dependent files * [#981](https://github.com/xmake-io/xmake/issues/981): Add `set_fpmodels()` for math optimization mode +* [#980](https://github.com/xmake-io/xmake/issues/980): Support Intel C/C++ Compiler ### Change @@ -842,6 +843,7 @@ * 升级luajit到v2.1最新分支版本,并且支持mips64上运行xmake * [#972](https://github.com/xmake-io/xmake/issues/972): 添加`depend.on_changed()`去简化依赖文件的处理 * [#981](https://github.com/xmake-io/xmake/issues/981): 添加`set_fpmodels()`去抽象化设置math/float-point编译优化模式 +* [#980](https://github.com/xmake-io/xmake/issues/980): 添加对 Intel C/C++ 编译器的全平台支持 ### 改进 diff --git a/README.md b/README.md index c8c6e304d..d392ed746 100644 --- a/README.md +++ b/README.md @@ -198,6 +198,7 @@ envs Environment variables toolchain fasm Flat Assembler tinyc Tiny C Compiler emcc A toolchain for compiling to asm.js and WebAssembly +icc Intel C/C++ Compiler ``` ## Supported Languages diff --git a/README_zh.md b/README_zh.md index 5a41d8b4f..d6b96ad22 100644 --- a/README_zh.md +++ b/README_zh.md @@ -201,6 +201,7 @@ envs Environment variables toolchain fasm Flat Assembler tinyc Tiny C Compiler emcc A toolchain for compiling to asm.js and WebAssembly +icc Intel C/C++ Compiler ``` ## 支持语言 -- cgit v1.3.1