diff options
| author | OpportunityLiu <[email protected]> | 2019-07-13 09:32:30 +0800 |
|---|---|---|
| committer | OpportunityLiu <[email protected]> | 2019-07-14 00:04:52 +0800 |
| commit | 515a9c3f542ef1b104a3af9a2398335e2d10fe7c (patch) | |
| tree | 43cce985ab728cc7e4290b369cb000a8762fbff5 | |
| parent | 6061930a5c24f9b1ba717a9a39dafda02e8a802a (diff) | |
support call xmake from msbuild
47 files changed, 1234 insertions, 394 deletions
diff --git a/xmake/modules/detect/tools/find_nvcc.lua b/xmake/modules/detect/tools/find_nvcc.lua index 5b97f3dc9..ce98c9a60 100644 --- a/xmake/modules/detect/tools/find_nvcc.lua +++ b/xmake/modules/detect/tools/find_nvcc.lua @@ -51,7 +51,7 @@ function main(opt) -- not found? attempt to find program from cuda toolchains if not program then - local toolchains = find_cuda(config.get("cuda")) + local toolchains = find_cuda() if toolchains and toolchains.bindir then program = find_program(path.join(toolchains.bindir, "nvcc"), opt) end diff --git a/xmake/plugins/project/main.lua b/xmake/plugins/project/main.lua index e56795086..d2ce39a10 100755 --- a/xmake/plugins/project/main.lua +++ b/xmake/plugins/project/main.lua @@ -24,16 +24,9 @@ import("core.base.task") import("core.platform.environment") import("make.makefile") import("cmake.cmakelists") -import("vstudio.vs2002") -import("vstudio.vs2003") -import("vstudio.vs2005") -import("vstudio.vs2008") -import("vstudio.vs2010") -import("vstudio.vs2012") -import("vstudio.vs2013") -import("vstudio.vs2015") -import("vstudio.vs2017") -import("vstudio.vs2019") +import("vstudio.vs") +import("vstudio.vsx") +import("vsxmake.vsxmake") import("clang.compile_flags") import("clang.compile_commands") @@ -45,16 +38,22 @@ function _make(kind) { makefile = makefile.make , cmakelists = cmakelists.make - , vs2002 = vs2002.make - , vs2003 = vs2003.make - , vs2005 = vs2005.make - , vs2008 = vs2008.make - , vs2010 = vs2010.make - , vs2012 = vs2012.make - , vs2013 = vs2013.make - , vs2015 = vs2015.make - , vs2017 = vs2017.make - , vs2019 = vs2019.make + , vs2002 = vs.make(2002) + , vs2003 = vs.make(2003) + , vs2005 = vs.make(2005) + , vs2008 = vs.make(2008) + , vs2010 = vsx.make(2010) + , vs2012 = vsx.make(2012) + , vs2013 = vsx.make(2013) + , vs2015 = vsx.make(2015) + , vs2017 = vsx.make(2017) + , vs2019 = vsx.make(2019) + , vsxmake2010 = vsxmake.make(2010) + , vsxmake2012 = vsxmake.make(2012) + , vsxmake2013 = vsxmake.make(2013) + , vsxmake2015 = vsxmake.make(2015) + , vsxmake2017 = vsxmake.make(2017) + , vsxmake2019 = vsxmake.make(2019) , compile_flags = compile_flags.make , compile_commands = compile_commands.make } diff --git a/xmake/plugins/project/vstudio/impl/vs200x_vcproj.lua b/xmake/plugins/project/vstudio/impl/vs200x_vcproj.lua index 61878af6a..91769a6bf 100644 --- a/xmake/plugins/project/vstudio/impl/vs200x_vcproj.lua +++ b/xmake/plugins/project/vstudio/impl/vs200x_vcproj.lua @@ -97,7 +97,7 @@ function _make_linkflags(target, vcprojdir) -- save flag table.insert(flags, flag) end - + -- make flags string flags = os.args(flags) @@ -114,20 +114,11 @@ function _make_header(vcprojfile, vsinfo, target) -- the target name local targetname = target:name() - -- the versions - local versions = - { - vs2002 = '7.0' - , vs2003 = '7.1' - , vs2005 = '8.0' - , vs2008 = '9.0' - } - -- make header - vcprojfile:print("<?xml version=\"1.0\" encoding=\"gb2312\"?>") + vcprojfile:print("<?xml version=\"1.0\" encoding=\"utf-8\"?>") vcprojfile:enter("<VisualStudioProject") vcprojfile:print("ProjectType=\"Visual C++\"") - vcprojfile:print("Version=\"%s0\"", assert(versions["vs" .. vsinfo.vstudio_version])) + vcprojfile:print("Version=\"%s0\"", assert(vsinfo.project_version)) vcprojfile:print("Name=\"%s\"", targetname) vcprojfile:print("ProjectGUID=\"{%s}\"", hash.uuid(targetname)) vcprojfile:print("RootNamespace=\"%s\"", targetname) diff --git a/xmake/plugins/project/vstudio/impl/vs201x_solution.lua b/xmake/plugins/project/vstudio/impl/vs201x_solution.lua index 3cd2ce4e0..d38ac15cf 100644 --- a/xmake/plugins/project/vstudio/impl/vs201x_solution.lua +++ b/xmake/plugins/project/vstudio/impl/vs201x_solution.lua @@ -116,7 +116,4 @@ function make(vsinfo) -- exit solution file slnfile:close() - - -- convert gb2312 to utf8 - io.writefile(slnpath, io.readfile(slnpath):convert("gb2312", "utf8")) end diff --git a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua index 8545ee802..6fea45987 100644 --- a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua +++ b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua @@ -26,17 +26,6 @@ import("vsfile") -- get toolset version function _get_toolset_ver(targetinfo, vsinfo) - -- the toolset versions - local toolset_vers = - { - vs2010 = "v100" - , vs2012 = "v110" - , vs2013 = "v120" - , vs2015 = "v140" - , vs2017 = "v141" - , vs2019 = "v142" - } - -- get toolset version from vs version local toolset_ver = nil local vs_toolset = config.get("vs_toolset") @@ -45,7 +34,7 @@ function _get_toolset_ver(targetinfo, vsinfo) toolset_ver = "v" .. verinfo[1] .. (verinfo[2] or "0") end if not toolset_ver then - toolset_ver = toolset_vers["vs" .. vsinfo.vstudio_version] + toolset_ver = vsinfo.toolset_version end -- for xp? @@ -63,14 +52,6 @@ end -- get platform sdk version function _get_platform_sdkver(target, vsinfo) - -- the default sdk version - local sdkvers = - { - vs2015 = "10.0.10240.0" - , vs2017 = "10.0.14393.0" - , vs2019 = "10.0.17763.0" - } - -- get sdk version for vcvarsall[arch].WindowsSDKVersion local sdkver = nil for _, targetinfo in ipairs(target.info) do @@ -81,7 +62,7 @@ function _get_platform_sdkver(target, vsinfo) end -- done - return sdkver or sdkvers["vs" .. vsinfo.vstudio_version] + return sdkver or vsinfo.sdk_version end -- make compiling command @@ -167,20 +148,9 @@ end -- make header function _make_header(vcxprojfile, vsinfo) - -- the versions - local versions = - { - vs2010 = '4' - , vs2012 = '4' - , vs2013 = '12' - , vs2015 = '14' - , vs2017 = '15' - , vs2019 = '16' - } - -- make header vcxprojfile:print("<?xml version=\"1.0\" encoding=\"utf-8\"?>") - vcxprojfile:enter("<Project DefaultTargets=\"Build\" ToolsVersion=\"%s.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">", assert(versions["vs" .. vsinfo.vstudio_version])) + vcxprojfile:enter("<Project DefaultTargets=\"Build\" ToolsVersion=\"%s.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">", assert(vsinfo.project_version)) end -- make tailer @@ -813,7 +783,4 @@ function make(vsinfo, target) -- exit solution file vcxprojfile:close() - - -- convert gb2312 to utf8 - io.writefile(vcxprojpath, io.readfile(vcxprojpath):convert("gb2312", "utf8")) end diff --git a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj_filters.lua b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj_filters.lua index 0a850bda1..d241dd909 100755 --- a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj_filters.lua +++ b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj_filters.lua @@ -161,7 +161,4 @@ function make(vsinfo, target) -- exit solution file
filtersfile:close()
-
- -- convert gb2312 to utf8
- io.writefile(filterspath, io.readfile(filterspath):convert("gb2312", "utf8"))
end
diff --git a/xmake/plugins/project/vstudio/impl/vsinfo.lua b/xmake/plugins/project/vstudio/impl/vsinfo.lua new file mode 100644 index 000000000..3da30d398 --- /dev/null +++ b/xmake/plugins/project/vstudio/impl/vsinfo.lua @@ -0,0 +1,93 @@ +--!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 - 2019, TBOOX Open Source Group. +-- +-- @author OpportunityLiu +-- @file vsinfo.lua +-- + +local vsinfo = +{ + [2002] = + { vstudio_version = "2002" + , solution_version = "7" + , project_version = "7.0" + } +, [2003] = + { vstudio_version = "2003" + , solution_version = "8" + , project_version = "7.1" + } +, [2005] = + { vstudio_version = "2005" + , solution_version = "9" + , project_version = "8.0" + } +, [2008] = + { vstudio_version = "2008" + , solution_version = "10" + , project_version = "9.0" + } +, [2010] = + { vstudio_version = "2010" + , project_version = "4" + , filters_version = "4.0" + , solution_version = "11" + , toolset_version = "v100" + } +, [2012] = + { vstudio_version = "2012" + , project_version = "4" + , filters_version = "4.0" + , solution_version = "12" + , toolset_version = "v110" + } +, [2013] = + { vstudio_version = "2013" + , project_version = "12" + , filters_version = "4.0" + , solution_version = "12" + , toolset_version = "v120" + } +, [2015] = + { vstudio_version = "2015" + , project_version = "14" + , filters_version = "4.0" + , solution_version = "12" + , toolset_version = "v140" + , sdk_version = "10.0.10240.0" + } +, [2017] = + { vstudio_version = "2017" + , project_version = "15" + , filters_version = "4.0" + , solution_version = "12" + , toolset_version = "v141" + , sdk_version = "10.0.14393.0" + } +, [2019] = + { vstudio_version = "2019" + , project_version = "16" + , filters_version = "4.0" + , solution_version = "12" + , toolset_version = "v142" + , sdk_version = "10.0.17763.0" + } +} + +function main(version) + assert(version) + return assert(vsinfo[version]); +end
\ No newline at end of file diff --git a/xmake/plugins/project/vstudio/vs2002.lua b/xmake/plugins/project/vstudio/vs.lua index 98b4125b2..a50180a23 100644 --- a/xmake/plugins/project/vstudio/vs2002.lua +++ b/xmake/plugins/project/vstudio/vs.lua @@ -15,22 +15,21 @@ -- Copyright (C) 2015 - 2019, TBOOX Open Source Group. -- -- @author ruki --- @file vs2003.lua +-- @file vs.lua -- -- imports import("impl.vs200x") +import("impl.vsinfo") --- make -function make(outputdir) +-- make factory +function make(version) - -- init vstudio info - local vsinfo = - { - vstudio_version = "2002" - , solution_version = "7" - } + -- get vs version info + local info = vsinfo(version) - -- make project - vs200x.make(outputdir, vsinfo) + -- make + return function(outputdir) + vs200x.make(outputdir, info) + end end diff --git a/xmake/plugins/project/vstudio/vs2005.lua b/xmake/plugins/project/vstudio/vs2005.lua deleted file mode 100644 index d212a7264..000000000 --- a/xmake/plugins/project/vstudio/vs2005.lua +++ /dev/null @@ -1,36 +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 - 2019, TBOOX Open Source Group. --- --- @author ruki --- @file vs2005.lua --- - --- imports -import("impl.vs200x") - --- make -function make(outputdir) - - -- init vstudio info - local vsinfo = - { - vstudio_version = "2005" - , solution_version = "9" - } - - -- make project - vs200x.make(outputdir, vsinfo) -end diff --git a/xmake/plugins/project/vstudio/vs2008.lua b/xmake/plugins/project/vstudio/vs2008.lua deleted file mode 100644 index 226847af0..000000000 --- a/xmake/plugins/project/vstudio/vs2008.lua +++ /dev/null @@ -1,36 +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 - 2019, TBOOX Open Source Group. --- --- @author ruki --- @file vs2008.lua --- - --- imports -import("impl.vs200x") - --- make -function make(outputdir) - - -- init vstudio info - local vsinfo = - { - vstudio_version = "2008" - , solution_version = "10" - } - - -- make project - vs200x.make(outputdir, vsinfo) -end diff --git a/xmake/plugins/project/vstudio/vs2010.lua b/xmake/plugins/project/vstudio/vs2010.lua deleted file mode 100644 index ed399691d..000000000 --- a/xmake/plugins/project/vstudio/vs2010.lua +++ /dev/null @@ -1,37 +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 - 2019, TBOOX Open Source Group. --- --- @author ruki --- @file vs2010.lua --- - --- imports -import("impl.vs201x") - --- make -function make(outputdir) - - -- init vstudio info - local vsinfo = - { - vstudio_version = "2010" - , filters_version = "4.0" - , solution_version = "11" - } - - -- make project - vs201x.make(outputdir, vsinfo) -end diff --git a/xmake/plugins/project/vstudio/vs2012.lua b/xmake/plugins/project/vstudio/vs2012.lua deleted file mode 100644 index 4d420336d..000000000 --- a/xmake/plugins/project/vstudio/vs2012.lua +++ /dev/null @@ -1,37 +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 - 2019, TBOOX Open Source Group. --- --- @author ruki --- @file vs2012.lua --- - --- imports -import("impl.vs201x") - --- make -function make(outputdir) - - -- init vstudio info - local vsinfo = - { - vstudio_version = "2012" - , filters_version = "4.0" - , solution_version = "12" - } - - -- make project - vs201x.make(outputdir, vsinfo) -end diff --git a/xmake/plugins/project/vstudio/vs2013.lua b/xmake/plugins/project/vstudio/vs2013.lua deleted file mode 100644 index f29cd1b66..000000000 --- a/xmake/plugins/project/vstudio/vs2013.lua +++ /dev/null @@ -1,37 +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 - 2019, TBOOX Open Source Group. --- --- @author ruki --- @file vs2013.lua --- - --- imports -import("impl.vs201x") - --- make -function make(outputdir) - - -- init vstudio info - local vsinfo = - { - vstudio_version = "2013" - , filters_version = "4.0" - , solution_version = "12" - } - - -- make project - vs201x.make(outputdir, vsinfo) -end diff --git a/xmake/plugins/project/vstudio/vs2015.lua b/xmake/plugins/project/vstudio/vs2015.lua deleted file mode 100644 index de00e0346..000000000 --- a/xmake/plugins/project/vstudio/vs2015.lua +++ /dev/null @@ -1,37 +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 - 2019, TBOOX Open Source Group. --- --- @author ruki --- @file vs2015.lua --- - --- imports -import("impl.vs201x") - --- make -function make(outputdir) - - -- init vstudio info - local vsinfo = - { - vstudio_version = "2015" - , filters_version = "4.0" - , solution_version = "12" - } - - -- make project - vs201x.make(outputdir, vsinfo) -end diff --git a/xmake/plugins/project/vstudio/vs2017.lua b/xmake/plugins/project/vstudio/vs2017.lua deleted file mode 100755 index 6ffa58e0f..000000000 --- a/xmake/plugins/project/vstudio/vs2017.lua +++ /dev/null @@ -1,37 +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 - 2019, TBOOX Open Source Group. --- --- @author ruki --- @file vs2017.lua --- - --- imports -import("impl.vs201x") - --- make -function make(outputdir) - - -- init vstudio info - local vsinfo = - { - vstudio_version = "2017" - , filters_version = "4.0" - , solution_version = "12" - } - - -- make project - vs201x.make(outputdir, vsinfo) -end diff --git a/xmake/plugins/project/vstudio/vs2019.lua b/xmake/plugins/project/vstudio/vs2019.lua deleted file mode 100755 index e45ca355a..000000000 --- a/xmake/plugins/project/vstudio/vs2019.lua +++ /dev/null @@ -1,37 +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 - 2019, TBOOX Open Source Group. --- --- @author ruki --- @file vs2019.lua --- - --- imports -import("impl.vs201x") - --- make -function make(outputdir) - - -- init vstudio info - local vsinfo = - { - vstudio_version = "2019" - , filters_version = "4.0" - , solution_version = "12" - } - - -- make project - vs201x.make(outputdir, vsinfo) -end diff --git a/xmake/plugins/project/vstudio/vs2003.lua b/xmake/plugins/project/vstudio/vsx.lua index 6acc282f9..ff8b83281 100644 --- a/xmake/plugins/project/vstudio/vs2003.lua +++ b/xmake/plugins/project/vstudio/vsx.lua @@ -15,22 +15,21 @@ -- Copyright (C) 2015 - 2019, TBOOX Open Source Group. -- -- @author ruki --- @file vs2003.lua +-- @file vsx.lua -- -- imports -import("impl.vs200x") +import("impl.vs201x") +import("impl.vsinfo") --- make -function make(outputdir) +-- make factory +function make(version) - -- init vstudio info - local vsinfo = - { - vstudio_version = "2003" - , solution_version = "8" - } + -- get vs version info + local info = vsinfo(version) - -- make project - vs200x.make(outputdir, vsinfo) + -- make + return function(outputdir) + vs201x.make(outputdir, info) + end end diff --git a/xmake/plugins/project/vsxmake/getinfo.lua b/xmake/plugins/project/vsxmake/getinfo.lua new file mode 100644 index 000000000..4333e71ca --- /dev/null +++ b/xmake/plugins/project/vsxmake/getinfo.lua @@ -0,0 +1,292 @@ +--!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 - 2019, TBOOX Open Source Group. +-- +-- @author OpportunityLiu +-- @file getinfo.lua +-- + +-- imports +import("core.base.option") +import("core.base.semver") +import("core.project.config") +import("core.project.project") +import("core.platform.platform") +import("core.platform.environment") +import("core.tool.compiler") +import("core.tool.linker") +import("lib.detect.find_tool") +import("actions.config.configheader", {alias = "generate_configheader", rootdir = os.programdir()}) + +function _make_dirs(dir) + if dir == nil then + return "" + end + if type(dir) == "string" then + dir = path.translate(dir) + if dir == "" then + return "" + end + if path.is_absolute(dir) then + if dir:startswith(project.directory()) then + return path.join("$(XmakeProjectDir)", path.relative(dir, project.directory())) + end + return dir + end + return path.join("$(XmakeProjectDir)", dir) + end + local r = {} + for k, v in ipairs(dir) do + r[k] = _make_dirs(v) + end + r = table.unique(r) + return table.concat(r, path.envsep()) +end + +function _get_values(target, name) + local values = table.wrap(target:get(name)) + for _, dep in irpairs(target:orderdeps()) do + local depinherit = target:extraconf("deps", dep:name(), "inherit") + if depinherit == nil or depinherit then + table.join2(values, dep:get(name, {interface = true})) + end + end + return values +end + +-- make target info +function _make_targetinfo(mode, arch, target) + + -- init target info + local targetinfo = { mode = mode, arch = arch, plat = config.get("plat"), vsarch = (arch == "x86" and "Win32" or arch) } + + -- write only if not default + -- use target:get("xxx") rather than target:xxx() + + -- save target kind + targetinfo.kind = target:get("kind") + + -- save target file + targetinfo.basename = target:get("basename") + targetinfo.filename = target:get("filename") + + -- save dirs + targetinfo.targetdir = _make_dirs(target:get("targetdir")) + targetinfo.buildir = _make_dirs(config.get("buildir")) + targetinfo.rundir = _make_dirs(target:get("rundir")) + targetinfo.configdir = _make_dirs(os.getenv("XMAKE_CONFIGDIR")) + targetinfo.configfiledir = _make_dirs(target:get("configdir")) + targetinfo.includedirs = _make_dirs(_get_values(target, "includedirs")) + targetinfo.linkdirs = _make_dirs(_get_values(target, "linkdirs")) + + -- save defines + targetinfo.defines = table.concat(_get_values(target, "defines"), ";") + targetinfo.languages = table.concat(_get_values(target, "languages"), ";") + + -- save runenvs + local runenvs = {} + for k, v in pairs(target:get("runenvs")) do + local defs = {} + for _, d in ipairs(v) do + table.insert(defs, vformat(d)) + end + table.insert(runenvs, format("%s=%s", k, table.concat(defs, path.envsep()))) + end + targetinfo.runenvs = table.concat(runenvs, "\n") + + -- use mfc? save the mfc runtime kind + if target:rule("win.sdk.mfc.shared_app") or target:rule("win.sdk.mfc.shared") then + targetinfo.mfckind = "Dynamic" + elseif target:rule("win.sdk.mfc.static_app") or target:rule("win.sdk.mfc.static") then + targetinfo.mfckind = "Static" + end + + -- use cuda? save the cuda runtime version + if target:rule("cuda") then + local nvcc = find_tool("nvcc", { version = true }) + local ver = semver.new(nvcc.version) + targetinfo.cudaver = ver:major() .. "." .. ver:minor() + end + + -- ok + return targetinfo +end + +function _make_vsinfo_modes() + local vsinfo_modes = {} + local modes = option.get("modes") + if modes then + for _, mode in ipairs(modes:split(',')) do + table.insert(vsinfo_modes, mode:trim()) + end + else + vsinfo_modes = project.modes() + end + if not vsinfo_modes or #vsinfo_modes == 0 then + vsinfo_modes = { config.mode() } + end + return vsinfo_modes +end + +function _make_vsinfo_archs() + local vsinfo_archs = {} + local archs = option.get("archs") + if archs then + for _, arch in ipairs(archs:split(',')) do + table.insert(vsinfo_archs, arch:trim()) + end + else + vsinfo_archs = platform.archs() + end + if not vsinfo_archs or #vsinfo_archs == 0 then + vsinfo_archs = { config.arch() } + end + return vsinfo_archs +end + +-- make vstudio project +function main(outputdir, vsinfo) + + -- enter project directory + local oldir = os.cd(project.directory()) + + -- init solution directory + vsinfo.solution_dir = path.absolute(path.join(outputdir, "vsxmake" .. vsinfo.vstudio_version)) + vsinfo.programdir = xmake.programdir() + vsinfo.projectdir = project.directory() + vsinfo.sln_projectfile = path.relative(project.file(), vsinfo.solution_dir) + local projectfile = path.filename(project.file()) + vsinfo.slnfile = path.filename(project.directory()) + -- write only if not default + if projectfile ~= "xmake.lua" then + vsinfo.projectfile = projectfile + vsinfo.slnfile = path.basename(projectfile) + end + + vsinfo.xmake_info = format("xmake version %s", xmake.version()) + vsinfo.solution_id = hash.uuid(project.directory() .. vsinfo.solution_dir) + vsinfo.vs_version = vsinfo.project_version .. ".0" + + -- init modes + vsinfo.modes = _make_vsinfo_modes() + -- init archs + vsinfo.archs = _make_vsinfo_archs() + + -- load targets + local targets = {} + vsinfo._sub2 = {} + for _, mode in ipairs(vsinfo.modes) do + vsinfo._sub2[mode] = {} + for _, arch in ipairs(vsinfo.archs) do + vsinfo._sub2[mode][arch] = { mode = mode, arch = arch } + + -- trace + print("checking for the %s.%s ...", mode, arch) + + -- reload config, project and platform + if mode ~= config.mode() or arch ~= config.arch() then + + -- modify config + config.set("as", nil, {force = true}) -- force to re-check as for ml/ml64 + config.set("mode", mode, {readonly = true, force = true}) + config.set("arch", arch, {readonly = true, force = true}) + + -- clear project to reload and recheck it + project.clear() + + -- check project options + project.check() + + -- reload platform + platform.load(config.plat()) + + -- re-generate configheader + generate_configheader() + end + + -- ensure to enter project directory + os.cd(project.directory()) + + -- enter environment (maybe check flags by calling tools) + environment.enter("toolchains") + + -- save targets + for targetname, target in pairs(project.targets()) do + if not target:isphony() then + + -- make target with the given mode and arch + targets[targetname] = targets[targetname] or {} + local _target = targets[targetname] + + -- init target info + _target.target = targetname + _target.vcxprojdir = path.join(vsinfo.solution_dir, targetname) + _target.target_id = hash.uuid(targetname) + _target.kind = target:targetkind() + _target.scriptdir = path.relative(target:scriptdir(), _target.vcxprojdir) + _target.projectdir = path.relative(project.directory(), _target.vcxprojdir) + local tgtdir = target:get("targetdir") + if tgtdir then _target.targetdir = path.relative(tgtdir, _target.vcxprojdir) end + _target._sub = _target._sub or {} + _target._sub[mode] = _target._sub[mode] or {} + _target._sub[mode][arch] = _make_targetinfo(mode, arch, target) + + -- save all sourcefiles and headerfiles + _target.sourcefiles = table.unique(table.join(_target.sourcefiles or {}, (target:sourcefiles()))) + _target.headerfiles = table.unique(table.join(_target.headerfiles or {}, (target:headerfiles()))) + + _target.deps = table.unique(table.join(_target.deps or {}, table.keys(target:deps()), nil)) + end + end + + -- leave environment + environment.leave("toolchains") + end + end + + -- leave project directory + os.cd(oldir) + for _,target in pairs(targets) do + target._sub2 = {} + local dirs = {} + for _,f in ipairs(target.sourcefiles) do + local dir = path.directory(f) + target._sub2[f] = + { + path = path.join("$(XmakeProjectDir)", f), + dir = dir + } + while dir ~= "." do + if not dirs[dir] then + dirs[dir] = + { + dir = dir, + dir_id = hash.uuid(dir) + } + end + dir = path.directory(dir) + end + end + target._sub3 = dirs + target.dirs = table.keys(dirs) + target._sub4 = {} + for _, v in ipairs(target.deps) do + target._sub4[v] = targets[v] + end + end + vsinfo.targets = table.keys(targets) + vsinfo._sub = targets + return vsinfo +end diff --git a/xmake/plugins/project/vsxmake/render.lua b/xmake/plugins/project/vsxmake/render.lua new file mode 100644 index 000000000..c672b30cd --- /dev/null +++ b/xmake/plugins/project/vsxmake/render.lua @@ -0,0 +1,74 @@ +--!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 - 2019, TBOOX Open Source Group. +-- +-- @author OpportunityLiu +-- @file render.lua +-- + +function _fill(opt, parmas) + return function(match) + local imp = match:match("^Import%((.+)%)$") + if imp then + local func, overload = os.files(path.join(opt.templatedir, imp .. "(*)")) + assert(overload == 1) + func = func[1] + local args = path.filename(func):match("%((.+)%)$"):split(",") + return _render(func, opt, args) + end + return opt.paramsprovider(match, parmas) or "<Not Provided>" + end +end + +function _expand(params) + local r = {""} + for _, v in ipairs(params) do + if type(v) == "string" then + for i, p in ipairs(r) do + r[i] = p .. ";" .. v + end + else + local newr = {} + for _, c in ipairs(v) do + local rcopy = {} + for i, p in ipairs(r) do + rcopy[i] = p .. ";" .. c + end + newr= table.join(newr, rcopy) + end + r = newr + end + end + for i, p in ipairs(r) do + r[i] = p:split(";") + end + return r +end + +function _render(templatepath, opt, args) + + local template = io.readfile(templatepath) + local params = _expand(opt.paramsprovider(args)) + local replaced = "" + for _, v in ipairs(params) do + replaced = replaced .. template:gsub(opt.pattern, _fill(opt, v)) + end + return replaced +end + +function main(templatepath, pattern, paramsprovider) + local opt = { pattern = pattern, paramsprovider = paramsprovider, templatedir = path.directory(templatepath) } + return _render(templatepath, opt, {}) +end
\ No newline at end of file diff --git a/xmake/plugins/project/vsxmake/vsproj/Xmake.props b/xmake/plugins/project/vsxmake/vsproj/Xmake.props new file mode 100644 index 000000000..02c36e28b --- /dev/null +++ b/xmake/plugins/project/vsxmake/vsproj/Xmake.props @@ -0,0 +1,139 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <PropertyGroup Label="XmakePropsInit"> + <!-- initialize this first to allow `Condition="'$(XmakeMode)|$(XmakeArch)' == 'release|x86'"` in custom props file --> + <XmakeMode Condition="'$(XmakeMode)' == ''">$(Configuration)</XmakeMode> + <XmakeMode Condition="'$(XmakeMode)' == ''">release</XmakeMode> + + <XmakeArch Condition="'$(XmakeArch)' == '' And '$(Platform.ToLower())' == 'win32'">x86</XmakeArch> + <XmakeArch Condition="'$(XmakeArch)' == '' And '$(Platform.ToLower())' != 'win32'">$(Platform)</XmakeArch> + <XmakeArch Condition="'$(XmakeArch)' == ''">auto</XmakeArch> + </PropertyGroup> + + <ImportGroup Label="CustomSettings"> + <Import Condition="Exists('$(MSBuildProjectDirectory)\Xmake.Custom.props')" + Project="$(MSBuildProjectDirectory)\Xmake.Custom.props" /> + <Import Condition="!Exists('$(MSBuildProjectDirectory)\Xmake.Custom.props') And Exists('$(MSBuildProjectDirectory)\..\Xmake.Custom.props')" + Project="$(MSBuildProjectDirectory)\..\Xmake.Custom.props" /> + </ImportGroup> + + <PropertyGroup Label="XmakePropsFallback"> + <XmakeBasename Condition="'$(XmakeBasename)' == ''">$(XmakeTarget)</XmakeBasename> + <XmakeBasename Condition="'$(XmakeBasename)' == ''">$(TargetName)</XmakeBasename> + <XmakeBasename Condition="'$(XmakeBasename)' == ''">$(MSBuildProjectName)</XmakeBasename> + + <XmakeKind Condition="'$(XmakeKind)' == ''">binary</XmakeKind> + <XmakePlat Condition="'$(XmakePlat)' == ''">windows</XmakePlat> + </PropertyGroup> + + <PropertyGroup Label="XmakePathsFallback"> + <XmakeBuilDir Condition="'$(XmakeBuilDir)' == ''">$(XmakeProjectDir)\build</XmakeBuilDir> + <XmakeTargetDir Condition="'$(XmakeTargetDir)' == ''">$(XmakeBuilDir)\$(XmakePlat)\$(XmakeArch)\$(XmakeMode)</XmakeTargetDir> + <XmakeConfigFileDir Condition="'$(XmakeConfigFileDir)' == ''">$(XmakeBuilDir)\$(XmakePlat)\$(XmakeArch)\$(XmakeMode)</XmakeConfigFileDir> + + <XmakeConfigDir Condition="'$(XmakeConfigDir)' == ''">$(XMAKE_CONFIGDIR)</XmakeConfigDir> + <XmakeConfigDir Condition="'$(XmakeConfigDir)' == ''">$(XmakeProjectDir)\.xmake</XmakeConfigDir> + + <XmakeRunDir Condition="'$(XmakeRunDir)' == ''">$(XmakeTargetDir)</XmakeRunDir> + </PropertyGroup> + + <PropertyGroup Label="XmakePathsResolve"> + <!-- resolve if they are relative paths --> + <XmakeProjectDir Condition="Exists('$(MSBuildProjectDirectory)\$(XmakeProjectDir)')">$([System.IO.Path]::GetFullPath('$(MSBuildProjectDirectory)\$(XmakeProjectDir)'))</XmakeProjectDir> + <XmakeScriptDir Condition="Exists('$(MSBuildProjectDirectory)\$(XmakeScriptDir)')">$([System.IO.Path]::GetFullPath('$(MSBuildProjectDirectory)\$(XmakeScriptDir)'))</XmakeScriptDir> + <XmakeBuilDir Condition="Exists('$(MSBuildProjectDirectory)\$(XmakeBuilDir)')">$([System.IO.Path]::GetFullPath('$(MSBuildProjectDirectory)\$(XmakeBuilDir)'))</XmakeBuilDir> + <XmakeTargetDir Condition="Exists('$(MSBuildProjectDirectory)\$(XmakeTargetDir)')">$([System.IO.Path]::GetFullPath('$(MSBuildProjectDirectory)\$(XmakeTargetDir)'))</XmakeTargetDir> + <XmakeConfigDir Condition="Exists('$(MSBuildProjectDirectory)\$(XmakeConfigDir)')">$([System.IO.Path]::GetFullPath('$(MSBuildProjectDirectory)\$(XmakeConfigDir)'))</XmakeConfigDir> + <XmakeConfigFileDir Condition="Exists('$(MSBuildProjectDirectory)\$(XmakeConfigFileDir)')">$([System.IO.Path]::GetFullPath('$(MSBuildProjectDirectory)\$(XmakeConfigFileDir)'))</XmakeConfigFileDir> + <XmakeRunDir Condition="Exists('$(MSBuildProjectDirectory)\$(XmakeRunDir)')">$([System.IO.Path]::GetFullPath('$(MSBuildProjectDirectory)\$(XmakeRunDir)'))</XmakeRunDir> + + <!-- normalize paths --> + <XmakeProjectDir>$([System.IO.Path]::GetFullPath('$(XmakeProjectDir)'))</XmakeProjectDir> + <XmakeScriptDir>$([System.IO.Path]::GetFullPath('$(XmakeScriptDir)'))</XmakeScriptDir> + <XmakeBuilDir>$([System.IO.Path]::GetFullPath('$(XmakeBuilDir)'))</XmakeBuilDir> + <XmakeTargetDir>$([System.IO.Path]::GetFullPath('$(XmakeTargetDir)'))</XmakeTargetDir> + <XmakeConfigDir>$([System.IO.Path]::GetFullPath('$(XmakeConfigDir)'))</XmakeConfigDir> + <XmakeConfigFileDir>$([System.IO.Path]::GetFullPath('$(XmakeConfigFileDir)'))</XmakeConfigFileDir> + <XmakeRunDir>$([System.IO.Path]::GetFullPath('$(XmakeRunDir)'))</XmakeRunDir> + </PropertyGroup> + + <PropertyGroup Label="XmakeFlagsFallback"> + <XmakeWarning Condition="'$(XmakeWarning)' == ''">true</XmakeWarning> + <XmakeVerbose Condition="'$(XmakeVerbose)' == ''">false</XmakeVerbose> + <XmakeDiagnosis Condition="'$(XmakeDiagnosis)' == ''">false</XmakeDiagnosis> + </PropertyGroup> + + <PropertyGroup Condition="'$(WindowsTargetPlatformVersion)' == ''"> + <WindowsTargetPlatformVersion Condition="'$(VisualStudioVersion)' == '14.0'">10.0.10240.0</WindowsTargetPlatformVersion> + <WindowsTargetPlatformVersion Condition="'$(VisualStudioVersion)' == '15.0'">10.0.14393.0</WindowsTargetPlatformVersion> + <WindowsTargetPlatformVersion Condition="'$(VisualStudioVersion)' == '16.0'">10.0.17763.0</WindowsTargetPlatformVersion> + <WindowsTargetPlatformVersion Condition="'$(WindowsTargetPlatformVersion)' == ''">10.0</WindowsTargetPlatformVersion> + </PropertyGroup> + <PropertyGroup Condition="'$(PlatformToolset)' == ''"> + <PlatformToolset Condition="'$(VisualStudioVersion)' == '10.0'">v100</PlatformToolset> + <PlatformToolset Condition="'$(VisualStudioVersion)' == '11.0'">v110</PlatformToolset> + <PlatformToolset Condition="'$(VisualStudioVersion)' == '12.0'">v120</PlatformToolset> + <PlatformToolset Condition="'$(VisualStudioVersion)' == '14.0'">v140</PlatformToolset> + <PlatformToolset Condition="'$(VisualStudioVersion)' == '15.0'">v141</PlatformToolset> + <PlatformToolset Condition="'$(VisualStudioVersion)' == '16.0'">v142</PlatformToolset> + </PropertyGroup> + + <PropertyGroup Label="AdditionalProps"> + <UseOfMfc Condition="'$(XmakeMfcKind)' != ''">$(XmakeMfcKind)</UseOfMfc> + <CharacterSet Condition="'$(CharacterSet)' == '' And ($(XmakeDefines.Contains(';UNICODE;')) Or $(XmakeDefines.EndsWith(';UNICODE')) Or $(XmakeDefines.StartsWith('UNICODE;')) Or $(XmakeDefines.Equals('UNICODE')))">Unicode</CharacterSet> + <CharacterSet Condition="'$(CharacterSet)' == ''">MultiByte</CharacterSet> + </PropertyGroup> + + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> + <Choose> + <When Condition="'$(XmakeKind)' == 'binary'"> + <PropertyGroup> + <ConfigurationType>Application</ConfigurationType> + </PropertyGroup> + </When> + <When Condition="'$(XmakeKind)' == 'shared'"> + <PropertyGroup> + <ConfigurationType>DynamicLibrary</ConfigurationType> + </PropertyGroup> + </When> + <When Condition="'$(XmakeKind)' == 'static'"> + <PropertyGroup> + <ConfigurationType>StaticLibrary</ConfigurationType> + </PropertyGroup> + </When> + </Choose> + + <ItemDefinitionGroup> + <ClCompile> + <PreprocessorDefinitions>%(PreprocessorDefinitions);$(XmakeDefines)</PreprocessorDefinitions> + <LanguageStandard Condition="'%(LanguageStandard)' == '' And $(XmakeLanguages.Contains('cxx17'))">stdcpp17</LanguageStandard> + <LanguageStandard Condition="'%(LanguageStandard)' == '' And $(XmakeLanguages.Contains('cxx14'))">stdcpp14</LanguageStandard> + <LanguageStandard Condition="'%(LanguageStandard)' == '' And $(XmakeLanguages.Contains('cxx11'))">stdcpp11</LanguageStandard> + </ClCompile> + </ItemDefinitionGroup> + + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> + + <ImportGroup Label="ExtensionSettings"> + <Import Condition="'$(XmakeCudaVersion)' != '' And Exists('$(VCTargetsPath)\BuildCustomizations\CUDA $(XmakeCudaVersion).props')" + Project="$(VCTargetsPath)\BuildCustomizations\CUDA $(XmakeCudaVersion).props" /> + </ImportGroup> + + <ImportGroup Label="PropertySheets"> + <Import Condition="Exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" + Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" /> + </ImportGroup> + + <PropertyGroup Label="GlobalsFallback"> + <TargetName Condition="'$(XmakeFilename)' == ''">$(XmakeBasename)</TargetName> + <TargetName Condition="'$(XmakeFilename)' != ''">$([System.IO.Path]::GetFileNameWithoutExtension('$(XmakeFilename)'))</TargetName> + <TargetExt Condition="'$(XmakeFilename)' != ''">$([System.IO.Path]::GetExtension('$(XmakeFilename)'))</TargetExt> + </PropertyGroup> + + <PropertyGroup Label="Path"> + <IncludePath>$(XmakeIncludeDir);$(XmakeConfigFileDir);$(IncludePath)</IncludePath> + <LibraryPath>$(XmakeLinkDir);$(LibraryPath)</LibraryPath> + <OutDir>$(XmakeTargetDir)</OutDir> + <IntDir>$(XmakeBuilDir)\.vs\$(TargetName)\$(XmakeArch)\$(XmakeMode)\</IntDir> + </PropertyGroup> +</Project> diff --git a/xmake/plugins/project/vsxmake/vsproj/Xmake.targets b/xmake/plugins/project/vsxmake/vsproj/Xmake.targets new file mode 100644 index 000000000..e87012146 --- /dev/null +++ b/xmake/plugins/project/vsxmake/vsproj/Xmake.targets @@ -0,0 +1,161 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> + <ImportGroup Label="ExtensionTargets"> + <Import Condition="'$(XmakeCudaVersion)' != '' And Exists('$(VCTargetsPath)\BuildCustomizations\CUDA $(XmakeCudaVersion).targets')" + Project="$(VCTargetsPath)\BuildCustomizations\CUDA $(XmakeCudaVersion).targets" /> + </ImportGroup> + + <PropertyGroup Label="XmakeInternal"> + <_XmakeProjectFlag Condition="'$(XmakeProjectFile)' != ''">-F "$(XmakeProjectFile)"</_XmakeProjectFlag> + <_XmakeProjectFlag Condition="'$(XmakeProjectFile)' == ''">-P .</_XmakeProjectFlag> + + <_XmakeCommonFlags>$(XmakeCommonFlags.Trim())</_XmakeCommonFlags> + <_XmakeCommonFlags Condition="$(XmakeVerbose)">$(_XmakeCommonFlags) -v</_XmakeCommonFlags> + <_XmakeCommonFlags Condition="$(XmakeDiagnosis)">$(_XmakeCommonFlags) -D</_XmakeCommonFlags> + <_XmakeCommonFlags>$(_XmakeCommonFlags) $(_XmakeProjectFlag)</_XmakeCommonFlags> + + <_XmakeConfigFlags>$(XmakeConfigFlags.Trim())</_XmakeConfigFlags> + <_XmakeConfigFlags>$(_XmakeConfigFlags) -p $(XmakePlat) -m $(XmakeMode) -a $(XmakeArch) -o "$([MSBuild]::MakeRelative('$(XmakeProjectDir)', '$(XmakeBuilDir)'))"</_XmakeConfigFlags> + + <_XmakeBuildFlags>$(XmakeBuildFlags.Trim())</_XmakeBuildFlags> + <_XmakeBuildFlags Condition="$(XmakeWarning)">$(_XmakeBuildFlags) -w</_XmakeBuildFlags> + + <_XmakeCleanFlags>$(XmakeCleanFlags.Trim())</_XmakeCleanFlags> + + <_XmakeBuildFlags>$(_XmakeBuildFlags.Trim())</_XmakeBuildFlags> + <_XmakeCleanFlags>$(_XmakeCleanFlags.Trim())</_XmakeCleanFlags> + <_XmakeConfigFlags>$(_XmakeConfigFlags.Trim())</_XmakeConfigFlags> + <_XmakeCommonFlags>$(_XmakeCommonFlags.Trim())</_XmakeCommonFlags> + + <_XmakeExecutable>"$([System.IO.Path]::GetFullPath('$(XmakeProgramDir)\xmake.exe'))"</_XmakeExecutable> + <_XmakeEnv>pushd "$(XmakeProjectDir)" +set XMAKE_CONFIGDIR=$(XmakeConfigDir)</_XmakeEnv> + </PropertyGroup> + + <Target Name="_XmakeProjCheck"> + <Warning Condition="'$(XmakeCudaVersion)' != '' And !Exists('$(VCTargetsPath)\BuildCustomizations\CUDA $(XmakeCudaVersion).targets')" + Text="File '$(VCTargetsPath)\BuildCustomizations\CUDA $(XmakeCudaVersion).targets' not found" /> + <Warning Condition="'$(XmakeCudaVersion)' != '' And !Exists('$(VCTargetsPath)\BuildCustomizations\CUDA $(XmakeCudaVersion).props')" + Text="File '$(VCTargetsPath)\BuildCustomizations\CUDA $(XmakeCudaVersion).props' not found" /> + <Error Condition="!Exists('$(XmakeProgramDir)\xmake.exe')" + Text="xmake.exe not found at '$(XmakeProgramDir)', please set XMAKE_PROGRAM_DIR in environments or XmakeProgramDir in vcxproj file" /> + <Error Condition="'$(XmakeProjectFile)' == '' And !Exists('$(XmakeProjectDir)\xmake.lua')" + Text="xmake.lua not found at '$(XmakeProjectDir)', please set XmakeProjectDir in vcxproj file" /> + <Error Condition="'$(XmakeProjectFile)' != '' And !Exists('$(XmakeProjectDir)\$(XmakeProjectFile)')" + Text="$(XmakeProjectFile) not found at '$(XmakeProjectDir)', please set XmakeProjectDir in vcxproj file" /> + </Target> + <Target Name="_XmakeConfig" DependsOnTargets="_XmakeProjCheck"> + <Message Text="$xmake config $(_XmakeCommonFlags) $(_XmakeConfigFlags) $(XmakeTarget)" Importance="High" /> + <Exec Command="$(_XmakeEnv) +$(_XmakeExecutable) config $(_XmakeCommonFlags) $(_XmakeConfigFlags) $(XmakeTarget)" EchoOff="true"/> + </Target> + <Target Name="_XmakeReconfig" DependsOnTargets="_XmakeProjCheck"> + <Message Text="$xmake config $(_XmakeCommonFlags) -c $(_XmakeConfigFlags) $(XmakeTarget)" Importance="High" /> + <Exec Command="$(_XmakeEnv) +$(_XmakeExecutable) config $(_XmakeCommonFlags) -c $(_XmakeConfigFlags) $(XmakeTarget)" EchoOff="true"/> + </Target> + <Target Name="_XmakeBuild" DependsOnTargets="_XmakeProjCheck"> + <Message Text="$xmake build $(_XmakeCommonFlags) $(_XmakeBuildFlags) $(XmakeTarget)" Importance="High" /> + <Exec Command="$(_XmakeEnv) +$(_XmakeExecutable) build $(_XmakeCommonFlags) $(_XmakeBuildFlags) $(XmakeTarget)" EchoOff="true"/> + </Target> + <Target Name="_XmakeClean" DependsOnTargets="_XmakeProjCheck"> + <Message Text="$xmake clean $(_XmakeCommonFlags) -a $(_XmakeCleanFlags) $(XmakeTarget)" Importance="High" /> + <Exec Command="$(_XmakeEnv) +$(_XmakeExecutable) clean $(_XmakeCommonFlags) -a $(_XmakeCleanFlags) $(XmakeTarget)" EchoOff="true"/> + </Target> + + <Target Name="Show"> + <Message Text=" +MSBuild Properties: + Xmake Props: + XmakeTarget: $(XmakeTarget) + 'XmakePlat|Mode|Arch': '$(XmakePlat)|$(XmakeMode)|$(XmakeArch)' + XmakeBasename: $(XmakeBasename) + XmakeFilename: $(XmakeFilename) + XmakeKind: $(XmakeKind) + XmakeCudaVersion: $(XmakeCudaVersion) + XmakeMfcKind: $(XmakeMfcKind) + XmakeDefines: $(XmakeDefines) + XmakeLanguages: $(XmakeLanguages) + Xmake Path: + XmakeProjectDir: $(XmakeProjectDir) + XmakeScriptDir: $(XmakeScriptDir) + XmakeBuilDir: $(XmakeBuilDir) + XmakeConfigDir: $(XmakeConfigDir) + XmakeIncludeDir: $(XmakeIncludeDir) + XmakeLinkDir: $(XmakeLinkDir) + Xmake Flags: + XmakeWarning: $(XmakeWarning) + XmakeVerbose: $(XmakeVerbose) + XmakeDiagnosis: $(XmakeDiagnosis) + XmakeCommonFlags: $(XmakeCommonFlags) + XmakeConfigFlags: $(XmakeConfigFlags) + XmakeBuildFlags: $(XmakeBuildFlags) + XmakeCleanFlags: $(XmakeCleanFlags) + Xmake Internal: + _XmakeCommonFlags: $(_XmakeCommonFlags) + _XmakeConfigFlags: $(_XmakeConfigFlags) + _XmakeBuildFlags: $(_XmakeBuildFlags) + _XmakeCleanFlags: $(_XmakeCleanFlags) + _XmakeExecutable: $(_XmakeExecutable) + _XmakeEnv: $(_XmakeEnv) + Vs Props: + 'Configuration|Platform': '$(Configuration)|$(Platform)' + VisualStudioVersion: $(VisualStudioVersion) + MSBuildProjectDirectory: $(MSBuildProjectDirectory) + MSBuildProjectName: $(MSBuildProjectName) + OutDir: $(OutDir) + IntDir: $(IntDir) + TargetName: $(TargetName) + TargetExt: $(TargetExt) + PlatformToolset: $(PlatformToolset) + CharacterSet: $(CharacterSet) + UseOfMfc: $(UseOfMfc) + WindowsTargetPlatformVersion: $(WindowsTargetPlatformVersion) + PreprocessorDefinitions: %(ClCompile.PreprocessorDefinitions) + LanguageStandard: %(ClCompile.LanguageStandard) + " Importance="High" /> + </Target> + + <Target Name="BeforeBuild" /> + <Target Name="AfterBuild" /> + <Target Name="Build" Condition="'$(DesignTimeBuild)' != 'true'"> + <CallTarget Targets="Show" Condition="$(XmakeDiagnosis)" /> + <CallTarget Targets="BeforeBuild" /> + <CallTarget Targets="_XmakeConfig;_XmakeBuild" /> + <CallTarget Targets="AfterBuild" /> + </Target> + + <Target Name="BeforeClean" /> + <Target Name="AfterClean" /> + <Target Name="Clean" Condition="'$(DesignTimeBuild)' != 'true'"> + <CallTarget Targets="Show" Condition="$(XmakeDiagnosis)" /> + <CallTarget Targets="BeforeClean" /> + <CallTarget Targets="_XmakeClean;_XmakeReconfig" /> + <CallTarget Targets="AfterClean" /> + </Target> + + <Target Name="BeforeRebuild" /> + <Target Name="AfterRebuild" /> + <Target Name="Rebuild" Condition="'$(DesignTimeBuild)' != 'true'"> + <CallTarget Targets="Show" Condition="$(XmakeDiagnosis)" /> + <CallTarget Targets="BeforeRebuild" /> + <CallTarget Targets="BeforeClean" /> + <CallTarget Targets="_XmakeClean;_XmakeReconfig" /> + <CallTarget Targets="AfterClean" /> + <CallTarget Targets="BeforeBuild" /> + <CallTarget Targets="_XmakeBuild" /> + <CallTarget Targets="AfterBuild" /> + <CallTarget Targets="AfterRebuild" /> + </Target> + + <ImportGroup Label="CustomTargets"> + <Import Condition="Exists('$(MSBuildProjectDirectory)\Xmake.Custom.targets')" + Project="$(MSBuildProjectDirectory)\Xmake.Custom.targets" /> + <Import Condition="!Exists('$(MSBuildProjectDirectory)\Xmake.Custom.targets') And Exists('$(MSBuildProjectDirectory)\..\Xmake.Custom.targets')" + Project="$(MSBuildProjectDirectory)\..\Xmake.Custom.targets" /> + </ImportGroup> +</Project> diff --git a/xmake/plugins/project/vsxmake/vsproj/templates/#target#.vcxproj.user b/xmake/plugins/project/vsxmake/vsproj/templates/#target#.vcxproj.user new file mode 100644 index 000000000..399b00e30 --- /dev/null +++ b/xmake/plugins/project/vsxmake/vsproj/templates/#target#.vcxproj.user @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <PropertyGroup> + <LocalDebuggerCommandArguments></LocalDebuggerCommandArguments> + <LocalDebuggerWorkingDirectory>$(XmakeRunDir)</LocalDebuggerWorkingDirectory> + <LocalDebuggerEnvironment>$(XmakeRunEnvs) +$(LocalDebuggerEnvironment)</LocalDebuggerEnvironment> + <LocalDebuggerMergeEnvironment>true</LocalDebuggerMergeEnvironment> + </PropertyGroup> +</Project>
\ No newline at end of file diff --git a/xmake/plugins/project/vsxmake/vsproj/templates/Xmake.Custom.props b/xmake/plugins/project/vsxmake/vsproj/templates/Xmake.Custom.props new file mode 100644 index 000000000..6f47fe7a0 --- /dev/null +++ b/xmake/plugins/project/vsxmake/vsproj/templates/Xmake.Custom.props @@ -0,0 +1,35 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <!-- inherit parent settings --> + <Import Condition="Exists('$(MSBuildThisFileDirectory)\..\Xmake.Custom.props')" + Project="$(MSBuildThisFileDirectory)\..\Xmake.Custom.props" /> + + <PropertyGroup Label="XmakePaths"> + <!-- set environment XMAKE_CONFIGDIR for xmake tasks --> + <!-- + <XmakeConfigDir Condition="'$(XmakeMode)|$(XmakeArch)' == 'release|x86'">$(XmakeProjectDir)\.xmake</XmakeConfigDir> + <XmakeBuilDir>$(XmakeProjectDir)\build</XmakeBuilDir> + --> + </PropertyGroup> + + <PropertyGroup Label="XmakeFlags"> + <!-- Configure these flags to customize xmake build process --> + <!-- + Inherit parents: + <XmakeCleanFlags>$(XmakeCleanflags) -D</XmakeCleanFlags> + Override parents: + <XmakeCleanFlags>-D</XmakeCleanFlags> + Respect parents: + <XmakeCleanFlags Condition=" '$(XmakeCleanFlags)' == '' ">-D</XmakeCleanFlags> + + For -w, -v and -D, use <XmakeWarning>, <XmakeVerbose> and <XmakeDiagnosis> is more convenient. + --> + <XmakeWarning Condition="'$(XmakeWarning)' == ''">true</XmakeWarning> + <XmakeVerbose Condition="'$(XmakeVerbose)' == ''">false</XmakeVerbose> + <XmakeDiagnosis Condition="'$(XmakeDiagnosis)' == ''">false</XmakeDiagnosis> + <XmakeCleanFlags>$(XmakeCleanflags)</XmakeCleanFlags> + <XmakeBuildFlags>$(XmakeBuildFlags)</XmakeBuildFlags> + <XmakeConfigFlags>$(XmakeConfigFlags)</XmakeConfigFlags> + <XmakeCommonFlags>$(XmakeCommonFlags)</XmakeCommonFlags> + </PropertyGroup> +</Project> diff --git a/xmake/plugins/project/vsxmake/vsproj/templates/Xmake.Custom.targets b/xmake/plugins/project/vsxmake/vsproj/templates/Xmake.Custom.targets new file mode 100644 index 000000000..c63cbed32 --- /dev/null +++ b/xmake/plugins/project/vsxmake/vsproj/templates/Xmake.Custom.targets @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <!-- inherit parent settings --> + <Import Condition="Exists('$(MSBuildThisFileDirectory)\..\Xmake.Custom.targets')" + Project="$(MSBuildThisFileDirectory)\..\Xmake.Custom.targets" /> + + <!-- Override these targets to customize your build workflow --> + <!-- + If you uncomment targets below, + targets with same name that comes from ../Xmake.Custom.targets will be overrided. + + You can also define your own targets and call them like: + <Target Name="BeforeBuild"> + <CallTarget Targets="CustomStep1;CustomStep2" /> + </Target> + + To find task that you can used in custom targets, + see: https://docs.microsoft.com/en-us/visualstudio/msbuild/msbuild-task-reference + --> + + <!-- <Target Name="BeforeRebuild"></Target> --> + <!-- <Target Name="AfterRebuild"></Target> --> + <!-- <Target Name="BeforeBuild"></Target> --> + <!-- <Target Name="AfterBuild"></Target> --> + <!-- <Target Name="BeforeClean"></Target> --> + <!-- <Target Name="AfterClean"></Target> --> +</Project> diff --git a/xmake/plugins/project/vsxmake/vsproj/templates/sln/ProjConfig(target,mode,arch) b/xmake/plugins/project/vsxmake/vsproj/templates/sln/ProjConfig(target,mode,arch) new file mode 100644 index 000000000..427703018 --- /dev/null +++ b/xmake/plugins/project/vsxmake/vsproj/templates/sln/ProjConfig(target,mode,arch) @@ -0,0 +1,2 @@ + {#target_id#}.#mode#|#arch#.ActiveCfg = #mode#|#vsarch# + {#target_id#}.#mode#|#arch#.Build.0 = #mode#|#vsarch# diff --git a/xmake/plugins/project/vsxmake/vsproj/templates/sln/Project(target) b/xmake/plugins/project/vsxmake/vsproj/templates/sln/Project(target) new file mode 100644 index 000000000..11e743c8a --- /dev/null +++ b/xmake/plugins/project/vsxmake/vsproj/templates/sln/Project(target) @@ -0,0 +1,2 @@ +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "#target#", "#target#\#target#.vcxproj", "{#target_id#}" +EndProject diff --git a/xmake/plugins/project/vsxmake/vsproj/templates/sln/SlnConfig(mode,arch) b/xmake/plugins/project/vsxmake/vsproj/templates/sln/SlnConfig(mode,arch) new file mode 100644 index 000000000..b1784b846 --- /dev/null +++ b/xmake/plugins/project/vsxmake/vsproj/templates/sln/SlnConfig(mode,arch) @@ -0,0 +1 @@ + #mode#|#arch# = #mode#|#arch# diff --git a/xmake/plugins/project/vsxmake/vsproj/templates/sln/vsxmake.sln b/xmake/plugins/project/vsxmake/vsproj/templates/sln/vsxmake.sln new file mode 100644 index 000000000..bc2872afe --- /dev/null +++ b/xmake/plugins/project/vsxmake/vsproj/templates/sln/vsxmake.sln @@ -0,0 +1,34 @@ +Microsoft Visual Studio Solution File, Format Version #solution_version#.0 +# Visual Studio Version #vs_version# +# +# #xmake_info# +# +# This file is auto generated by xmake. +# +# Please DO NOT EDIT since all your modification will lost after re-generation. +# See https://github.com/xmake-io/xmake/pull/472 for more infomation. +# +VisualStudioVersion = #vs_version# +MinimumVisualStudioVersion = 10.0 +#Import(Project)# +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Properties", "Properties", "{007754BD-BB1F-452F-A0D8-13EF216C5ED9}" + ProjectSection(SolutionItems) = preProject + Xmake.Custom.props = Xmake.Custom.props + Xmake.Custom.targets = Xmake.Custom.targets + #sln_projectfile# = #sln_projectfile# + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution +#Import(SlnConfig)# + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution +#Import(ProjConfig)# + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {#solution_id#} + EndGlobalSection +EndGlobal diff --git a/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj.filters/#target#.vcxproj.filters b/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj.filters/#target#.vcxproj.filters new file mode 100644 index 000000000..48428a006 --- /dev/null +++ b/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj.filters/#target#.vcxproj.filters @@ -0,0 +1,43 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +#xmake_info# + + This file is auto generated by xmake. + + Please DO NOT EDIT since all your modification will lost after re-generation. + See https://github.com/xmake-io/xmake/pull/472 for more infomation. +--> +<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <ItemGroup> + <Filter Include="Properties"> + <UniqueIdentifier>{CC7C6180-942D-056E-3227-E6A2B3FB19CD}</UniqueIdentifier> + </Filter> +#Import(Filter)# + </ItemGroup> + <ItemGroup> + <None Include="Xmake.Custom.props"> + <Filter>Properties</Filter> + </None> + <None Include="Xmake.Custom.targets"> + <Filter>Properties</Filter> + </None> + <None Include="$(XmakeScriptDir)\xmake.lua"> + <Filter>Properties</Filter> + </None> + </ItemGroup> + <ItemGroup> +#Import(File.c)# + </ItemGroup> + <ItemGroup> +#Import(File.cxx)# + </ItemGroup> + <ItemGroup> +#Import(File.cu)# + </ItemGroup> + <ItemGroup> +#Import(File.obj)# + </ItemGroup> + <ItemGroup> +#Import(File.rc)# + </ItemGroup> +</Project> diff --git a/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj.filters/File.c(filec) b/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj.filters/File.c(filec) new file mode 100644 index 000000000..d33f87944 --- /dev/null +++ b/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj.filters/File.c(filec) @@ -0,0 +1,3 @@ + <ClCompile Include="#path#"> + <Filter>#dir#</Filter> + </ClCompile> diff --git a/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj.filters/File.cu(filecu) b/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj.filters/File.cu(filecu) new file mode 100644 index 000000000..643bb220f --- /dev/null +++ b/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj.filters/File.cu(filecu) @@ -0,0 +1,3 @@ + <CudaCompile Include="#path#"> + <Filter>#dir#</Filter> + </CudaCompile> diff --git a/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj.filters/File.cxx(filecxx) b/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj.filters/File.cxx(filecxx) new file mode 100644 index 000000000..d33f87944 --- /dev/null +++ b/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj.filters/File.cxx(filecxx) @@ -0,0 +1,3 @@ + <ClCompile Include="#path#"> + <Filter>#dir#</Filter> + </ClCompile> diff --git a/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj.filters/File.obj(fileobj) b/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj.filters/File.obj(fileobj) new file mode 100644 index 000000000..adacd3b67 --- /dev/null +++ b/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj.filters/File.obj(fileobj) @@ -0,0 +1,3 @@ + <Object Include="#path#"> + <Filter>#dir#</Filter> + </Object> diff --git a/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj.filters/File.rc(filerc) b/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj.filters/File.rc(filerc) new file mode 100644 index 000000000..a46047781 --- /dev/null +++ b/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj.filters/File.rc(filerc) @@ -0,0 +1,3 @@ + <ResourceCompile Include="#path#"> + <Filter>#dir#</Filter> + </ResourceCompile> diff --git a/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj.filters/Filter(dir) b/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj.filters/Filter(dir) new file mode 100644 index 000000000..6f97fa98d --- /dev/null +++ b/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj.filters/Filter(dir) @@ -0,0 +1,3 @@ + <Filter Include="#dir#"> + <UniqueIdentifier>{#dir_id#}</UniqueIdentifier> + </Filter> diff --git a/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj/#target#.vcxproj b/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj/#target#.vcxproj new file mode 100644 index 000000000..734c2a9cb --- /dev/null +++ b/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj/#target#.vcxproj @@ -0,0 +1,56 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +#xmake_info# + + This file is auto generated by xmake. + + Please DO NOT EDIT since all your modification will lost after re-generation. + If you would like to have any customization, + edit Xmake.Custom.props and Xmake.Custom.targets instead. + + See https://github.com/xmake-io/xmake/pull/472 for more infomation. +--> +<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <ItemGroup Label="ProjectConfigurations"> +#Import(ProjectConfiguration)# + </ItemGroup> + <PropertyGroup Label="Globals"> + <ProjectGuid>{#target_id#}</ProjectGuid> + <XmakeProgramDir Condition="'$(XmakeProgramDir)' == ''">$(XMAKE_PROGRAM_DIR)</XmakeProgramDir> + <XmakeProgramDir Condition="'$(XmakeProgramDir)' == ''">#programdir#</XmakeProgramDir> + <Configuration Condition="'$(Configuration)' == ''">release</Configuration> + <Platform Condition="'$(Platform)' == ''">Win32</Platform> + <XmakeScriptDir>#scriptdir#</XmakeScriptDir> + <XmakeProjectDir>#projectdir#</XmakeProjectDir> + <XmakeProjectFile>#projectfile#</XmakeProjectFile> + <XmakeTarget>#target#</XmakeTarget> + </PropertyGroup> +#Import(XmakeConfig)# +#Import(XmakePath)# + <Import Project="$(XmakeProgramDir)\plugins\project\vsxmake\vsproj\xmake.props" /> + <ItemGroup> + <None Include="Xmake.Custom.props" /> + <None Include="Xmake.Custom.targets" /> + <None Condition="'$(XmakeScriptDir)' != '$(XmakeProjectDir)' And Exists('$(XmakeScriptDir)\xmake.lua')" + Include="$(XmakeScriptDir)\xmake.lua" /> + </ItemGroup> + <ItemGroup> +#Import(File.c)# + </ItemGroup> + <ItemGroup> +#Import(File.cxx)# + </ItemGroup> + <ItemGroup> +#Import(File.cu)# + </ItemGroup> + <ItemGroup> +#Import(File.obj)# + </ItemGroup> + <ItemGroup> +#Import(File.rc)# + </ItemGroup> + <!-- <ItemGroup> +#Import(ProjectRef)# + </ItemGroup> --> + <Import Project="$(XmakeProgramDir)\plugins\project\vsxmake\vsproj\xmake.targets" /> +</Project> diff --git a/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj/File.c(filec) b/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj/File.c(filec) new file mode 100644 index 000000000..36e16832a --- /dev/null +++ b/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj/File.c(filec) @@ -0,0 +1,3 @@ + <ClCompile Include="#path#"> + <CompileAs>CompileAsC</CompileAs> + </ClCompile> diff --git a/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj/File.cu(filecu) b/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj/File.cu(filecu) new file mode 100644 index 000000000..7b3f0a6fe --- /dev/null +++ b/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj/File.cu(filecu) @@ -0,0 +1 @@ + <CudaCompile Include="#path#" /> diff --git a/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj/File.cxx(filecxx) b/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj/File.cxx(filecxx) new file mode 100644 index 000000000..076adfd5a --- /dev/null +++ b/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj/File.cxx(filecxx) @@ -0,0 +1,3 @@ + <ClCompile Include="#path#"> + <CompileAs>CompileAsCpp</CompileAs> + </ClCompile> diff --git a/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj/File.obj(fileobj) b/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj/File.obj(fileobj) new file mode 100644 index 000000000..1e7cd6f45 --- /dev/null +++ b/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj/File.obj(fileobj) @@ -0,0 +1 @@ + <Object Include="#path#" /> diff --git a/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj/File.rc(filerc) b/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj/File.rc(filerc) new file mode 100644 index 000000000..25d1c58ab --- /dev/null +++ b/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj/File.rc(filerc) @@ -0,0 +1 @@ + <ResourceCompile Include="#path#" /> diff --git a/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj/ProjectConfiguration(mode,arch) b/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj/ProjectConfiguration(mode,arch) new file mode 100644 index 000000000..f2169767f --- /dev/null +++ b/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj/ProjectConfiguration(mode,arch) @@ -0,0 +1,4 @@ + <ProjectConfiguration Include="#mode#|#arch#"> + <Configuration>#mode#</Configuration> + <Platform>#vsarch#</Platform> + </ProjectConfiguration> diff --git a/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj/ProjectRef(dep) b/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj/ProjectRef(dep) new file mode 100644 index 000000000..7804e4cba --- /dev/null +++ b/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj/ProjectRef(dep) @@ -0,0 +1,3 @@ + <ProjectReference Include="..\#target#\#target#.vcxproj"> + <Project>{#target_id#}</Project> + </ProjectReference> diff --git a/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj/XmakeConfig(mode,arch) b/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj/XmakeConfig(mode,arch) new file mode 100644 index 000000000..da73700f4 --- /dev/null +++ b/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj/XmakeConfig(mode,arch) @@ -0,0 +1,13 @@ + <PropertyGroup Label="XmakeConfig" Condition="'$(Configuration)|$(Platform)'=='#mode#|#vsarch#'"> + <XmakeBasename>#basename#</XmakeBasename> + <XmakeFilename>#filename#</XmakeFilename> + <XmakeMode>#mode#</XmakeMode> + <XmakePlat>#plat#</XmakePlat> + <XmakeArch>#arch#</XmakeArch> + <XmakeKind>#kind#</XmakeKind> + <XmakeDefines>#defines#</XmakeDefines> + <XmakeLanguages>#languages#</XmakeLanguages> + <XmakeCudaVersion>#cudaver#</XmakeCudaVersion> + <XmakeMfcKind>#mfckind#</XmakeMfcKind> + <XmakeRunEnvs>#runenvs#</XmakeRunEnvs> + </PropertyGroup> diff --git a/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj/XmakePath(mode,arch) b/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj/XmakePath(mode,arch) new file mode 100644 index 000000000..2c8adc429 --- /dev/null +++ b/xmake/plugins/project/vsxmake/vsproj/templates/vcxproj/XmakePath(mode,arch) @@ -0,0 +1,9 @@ + <PropertyGroup Label="XmakePath" Condition="'$(Configuration)|$(Platform)'=='#mode#|#vsarch#'"> + <XmakeBuilDir>#buildir#</XmakeBuilDir> + <XmakeConfigDir>#configdir#</XmakeConfigDir> + <XmakeConfigFileDir>#configfiledir#</XmakeConfigFileDir> + <XmakeTargetDir>#targetdir#</XmakeTargetDir> + <XmakeIncludeDir>#includedirs#</XmakeIncludeDir> + <XmakeLinkDir>#linkdirs#</XmakeLinkDir> + <XmakeRunDir>#rundir#</XmakeRunDir> + </PropertyGroup> diff --git a/xmake/plugins/project/vsxmake/vsxmake.lua b/xmake/plugins/project/vsxmake/vsxmake.lua new file mode 100644 index 000000000..19ec2bfa6 --- /dev/null +++ b/xmake/plugins/project/vsxmake/vsxmake.lua @@ -0,0 +1,158 @@ +--!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 - 2019, TBOOX Open Source Group. +-- +-- @author OpportunityLiu +-- @file vsxmake.lua +-- + +-- imports +import("core.base.hashset") +import("vstudio.impl.vsinfo", { rootdir = path.directory(os.scriptdir()) }) +import("render") +import("getinfo") + +local template_root = path.join(os.scriptdir(), "vsproj", "templates") +local template_sln = path.join(template_root, "sln", "vsxmake.sln") +local template_vcx = path.join(template_root, "vcxproj", "#target#.vcxproj") + +local template_fil = path.join(template_root, "vcxproj.filters", "#target#.vcxproj.filters") +local template_usr = path.join(template_root, "#target#.vcxproj.user") +local template_props = path.join(template_root, "Xmake.Custom.props") +local template_targets = path.join(template_root, "Xmake.Custom.targets") + +function _filter_files(files, exts) + local extset = hashset.from(exts) + local f = {} + for _, file in ipairs(files) do + local ext = path.extension(file) + if extset:has(ext) then + table.insert(f, file) + end + end + return f +end + +function _buildparams(info, target, default) + + local function getprop(match, opt) + local i = info + local r = info[match] + if target then + opt = table.join(target, opt) + end + for _,k in ipairs(opt) do + local v = (i._sub or {})[k] or (i._sub2 or {})[k] or (i._sub3 or {})[k] or (i._sub4 or {})[k]or i[k] + if v == nil then + raise("key '" .. k .. "' not found") + end + i = v + r = i[match] or r + end + + return r or default + end + + local function listconfig(args) + for _, k in ipairs(args) do + args[k] = true + end + local r = {} + if args.target then + table.insert(r, info.targets) + end + if args.mode then + table.insert(r, info.modes) + end + if args.arch then + table.insert(r, info.archs) + end + if args.dir then + table.insert(r, info._sub[target].dirs) + end + if args.dep then + table.insert(r, info._sub[target].deps) + end + if args.filec then + local files = info._sub[target].sourcefiles + table.insert(r, _filter_files(files, {".c"})) + elseif args.filecxx then + local files = info._sub[target].sourcefiles + table.insert(r, _filter_files(files, {".cpp", ".cc", ".cxx"})) + elseif args.filecu then + local files = info._sub[target].sourcefiles + table.insert(r, _filter_files(files, {".cu"})) + elseif args.fileobj then + local files = info._sub[target].sourcefiles + table.insert(r, _filter_files(files, {".obj", ".o"})) + elseif args.filerc then + local files = info._sub[target].sourcefiles + table.insert(r, _filter_files(files, {".rc"})) + end + return r + end + + return function(match, opt) + if type(match) == "table" then + return listconfig(match) + end + return getprop(match, opt) + end +end + +function _trycp(file, target, targetname) + targetname = targetname or path.filename(file) + local targetfile = path.join(target, targetname) + if os.isfile(targetfile) then + dprint("skipped file %s", path.relative(targetfile)) + return + end + os.cp(file,targetfile) +end + +-- make +function make(version) + + return function(outputdir) + local info = getinfo(outputdir, vsinfo(version)) + local paramsprovidersln = _buildparams(info) + + -- write solution file + local sln = path.join(info.solution_dir, info.slnfile .. "_vsxmake" .. info.vstudio_version .. ".sln") + io.writefile(sln, render(template_sln, "#([A-Za-z0-9_,%.%*%(%)]+)#", paramsprovidersln)) + + -- add solution custom file + _trycp(template_props, info.solution_dir) + _trycp(template_targets, info.solution_dir) + + for _, target in ipairs(info.targets) do + local paramsprovidertarget = _buildparams(info, target, "<!-- nil -->") + local proj_dir = info._sub[target].vcxprojdir + + -- write project file + local proj = path.join(proj_dir, target .. ".vcxproj") + io.writefile(proj, render(template_vcx, "#([A-Za-z0-9_,%.%*%(%)]+)#", paramsprovidertarget)) + + local projfil = path.join(proj_dir, target .. ".vcxproj.filters") + io.writefile(projfil, render(template_fil, "#([A-Za-z0-9_,%.%*%(%)]+)#", paramsprovidertarget)) + + -- add project custom file + _trycp(template_props, proj_dir) + _trycp(template_targets, proj_dir) + -- add project user file + _trycp(template_usr, proj_dir, target .. ".vcxproj.user") + end + end +end diff --git a/xmake/plugins/project/xmake.lua b/xmake/plugins/project/xmake.lua index 717c41b0d..023d3d87d 100644 --- a/xmake/plugins/project/xmake.lua +++ b/xmake/plugins/project/xmake.lua @@ -42,8 +42,10 @@ task("project") , " - makefile" , " - compile_flags" , " - compile_commands (clang compilation database with json format)" - , " - vs2002, vs2003, vs2005, vs2008, vs2010, vs2012, vs2013, vs2015, vs2017" } - , {'m', "modes", "kv", nil, "Set the project modes." + , " - vs2002, vs2003, vs2005, vs2008" + , " - vs2010, vs2012, vs2013, vs2015, vs2017, vs2019" + , " - vsxmake2010 ~ vsmake2019" } + , {'m', "modes", "kv", nil, "Set the project modes." , " .e.g " , " - xmake project -k makefile" , " - xmake project -k compile_commands" |
