From e9348954997cf946f1667ed672d7f2db24185b0f Mon Sep 17 00:00:00 2001 From: Kethers <49612587+Kethers@users.noreply.github.com> Date: Mon, 11 Dec 2023 02:30:09 +0800 Subject: [PATCH 01/12] Init CSharp proj support for VS solution --- xmake/languages/csharp/check_main.lua | 41 +++ xmake/languages/csharp/load.lua | 129 +++++++++ xmake/languages/csharp/xmake.lua | 137 +++++++++ xmake/plugins/project/vsxmake/getinfo.lua | 23 ++ xmake/plugins/project/vsxmake/langtype.lua | 66 +++++ xmake/plugins/project/vsxmake/vsxmake.lua | 26 +- xmake/rules/csharp/xmake.lua | 52 ++++ .../vsxmake/vsproj/Xmake.CSharp.targets | 265 ++++++++++++++++++ .../scripts/vsxmake/vsproj/Xmake.Common.props | 176 ++++++++++++ xmake/scripts/vsxmake/vsproj/Xmake.props | 4 +- .../vsproj/templates/csproj/#target#.csproj | 48 ++++ .../vsproj/templates/csproj/File.cs(filecs) | 1 + .../vsproj/templates/csproj/ProjectRef(dep) | 3 + .../templates/csproj/XmakeConfig(mode,arch) | 29 ++ .../templates/csproj/XmakePath(mode,arch) | 7 + .../vsproj/templates/sln/Project(target) | 2 +- 16 files changed, 1000 insertions(+), 9 deletions(-) create mode 100644 xmake/languages/csharp/check_main.lua create mode 100644 xmake/languages/csharp/load.lua create mode 100644 xmake/languages/csharp/xmake.lua create mode 100644 xmake/plugins/project/vsxmake/langtype.lua create mode 100644 xmake/rules/csharp/xmake.lua create mode 100644 xmake/scripts/vsxmake/vsproj/Xmake.CSharp.targets create mode 100644 xmake/scripts/vsxmake/vsproj/Xmake.Common.props create mode 100644 xmake/scripts/vsxmake/vsproj/templates/csproj/#target#.csproj create mode 100644 xmake/scripts/vsxmake/vsproj/templates/csproj/File.cs(filecs) create mode 100644 xmake/scripts/vsxmake/vsproj/templates/csproj/ProjectRef(dep) create mode 100644 xmake/scripts/vsxmake/vsproj/templates/csproj/XmakeConfig(mode,arch) create mode 100644 xmake/scripts/vsxmake/vsproj/templates/csproj/XmakePath(mode,arch) diff --git a/xmake/languages/csharp/check_main.lua b/xmake/languages/csharp/check_main.lua new file mode 100644 index 00000000000..55d00e2ded4 --- /dev/null +++ b/xmake/languages/csharp/check_main.lua @@ -0,0 +1,41 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file check_main.lua +-- + + +-- check it +function main(sourcefile) + + -- load source code + local sourcecode = io.readfile(sourcefile) + + -- remove comment first + sourcecode = sourcecode:gsub("/%*.-%*/", "") + sourcecode = sourcecode:gsub("//.-\n", "\n") + + -- find int main(int argc, char** argv) {} + if sourcecode:find("%s+main%s*%(.-%)") then + return true + end + + -- no main function + return false +end + + diff --git a/xmake/languages/csharp/load.lua b/xmake/languages/csharp/load.lua new file mode 100644 index 00000000000..932769a7cb7 --- /dev/null +++ b/xmake/languages/csharp/load.lua @@ -0,0 +1,129 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file load.lua +-- + +-- get apis +function _get_apis() + local apis = {} + apis.values = { + -- target.add_xxx + "target.add_links" + , "target.add_syslinks" + , "target.add_cflags" + , "target.add_cxflags" + , "target.add_cxxflags" + , "target.add_ldflags" + , "target.add_arflags" + , "target.add_shflags" + , "target.add_defines" + , "target.add_undefines" + , "target.add_frameworks" + , "target.add_rpathdirs" -- @note do not translate path, it's usually an absolute path or contains $ORIGIN/@loader_path + , "target.add_forceincludes" + -- option.add_xxx + , "option.add_cincludes" + , "option.add_cxxincludes" + , "option.add_cfuncs" + , "option.add_cxxfuncs" + , "option.add_ctypes" + , "option.add_cxxtypes" + , "option.add_links" + , "option.add_syslinks" + , "option.add_cflags" + , "option.add_cxflags" + , "option.add_cxxflags" + , "option.add_ldflags" + , "option.add_arflags" + , "option.add_shflags" + , "option.add_defines" + , "option.add_undefines" + , "option.add_frameworks" + , "option.add_rpathdirs" + -- package.add_xxx + , "package.add_links" + , "package.add_syslinks" + , "package.add_cflags" + , "package.add_cxflags" + , "package.add_cxxflags" + , "package.add_ldflags" + , "package.add_arflags" + , "package.add_shflags" + , "package.add_defines" + , "package.add_undefines" + , "package.add_frameworks" + , "package.add_rpathdirs" + , "package.add_linkdirs" + , "package.add_includedirs" --@note we need not uses paths for package, see https://github.com/xmake-io/xmake/issues/717 + , "package.add_sysincludedirs" + , "package.add_frameworkdirs" + -- toolchain.add_xxx + , "toolchain.add_links" + , "toolchain.add_syslinks" + , "toolchain.add_cflags" + , "toolchain.add_cxflags" + , "toolchain.add_cxxflags" + , "toolchain.add_ldflags" + , "toolchain.add_arflags" + , "toolchain.add_shflags" + , "toolchain.add_defines" + , "toolchain.add_undefines" + , "toolchain.add_frameworks" + , "toolchain.add_rpathdirs" + , "toolchain.add_linkdirs" + , "toolchain.add_includedirs" + , "toolchain.add_sysincludedirs" + , "toolchain.add_frameworkdirs" + } + apis.groups = { + -- target.add_xxx + "target.add_linkorders" + , "target.add_linkgroups" + -- package.add_xxx + , "package.add_linkorders" + , "package.add_linkgroups" + } + apis.paths = { + -- target.set_xxx + "target.set_pcheader" + , "target.set_pcxxheader" + -- target.add_xxx + , "target.add_headerfiles" + , "target.add_linkdirs" + , "target.add_includedirs" + , "target.add_sysincludedirs" + , "target.add_frameworkdirs" + -- option.add_xxx + , "option.add_linkdirs" + , "option.add_includedirs" + , "option.add_sysincludedirs" + , "option.add_frameworkdirs" + } + apis.dictionary = { + -- option.add_xxx + "option.add_csnippets" + , "option.add_cxxsnippets" + } + return apis +end + +function main() + return {apis = _get_apis()} +end + + diff --git a/xmake/languages/csharp/xmake.lua b/xmake/languages/csharp/xmake.lua new file mode 100644 index 00000000000..361755004de --- /dev/null +++ b/xmake/languages/csharp/xmake.lua @@ -0,0 +1,137 @@ +language("csharp") + add_rules("csharp") + set_sourcekinds {cs = {".cs"}} + -- set_sourceflags {cs = {"csflags"}} + -- TODO: set kinds and flags + set_targetkinds {binary = "ld", static = "ar", shared = "sh"} + set_targetflags {binary = "ldflags", static = "arflags", shared = "shflags"} + set_langkinds {cs = "cs"} + set_mixingkinds("cs") + + on_load("load") + -- may not have main function entry when used as scripting language + -- on_check_main("check_main") + + set_nameflags { + object = { + "config.includedirs" + , "config.frameworkdirs" + , "config.frameworks" + , "target.symbols" + , "target.warnings" + , "target.fpmodels" + , "target.optimize:check" + , "target.vectorexts:check" + , "target.languages" + , "target.runtimes" + , "target.includedirs" + , "target.defines" + , "target.undefines" + , "target.frameworkdirs" + , "target.frameworks" + , "target.exceptions" + , "target.encodings" + , "target.pcheader" + , "target.pcxxheader" + , "target.forceincludes" + , "toolchain.includedirs" + , "toolchain.defines" + , "toolchain.undefines" + , "toolchain.frameworkdirs" + , "toolchain.frameworks" + , "target.sysincludedirs" + , "toolchain.sysincludedirs" + } + , binary = { + "config.linkdirs" + , "config.frameworkdirs" + , "target.linkdirs" + , "target.frameworkdirs" + , "target.rpathdirs" + , "target.strip" + , "target.symbols" + , "target.optimize:check" + , "target.runtimes" + , "toolchain.linkdirs" + , "toolchain.rpathdirs" + , "toolchain.frameworkdirs" + , "config.links" + , "target.linkgroups" -- we must move it before target.links, because we need sort correct order for package and its deps + , "target.links" + , "toolchain.links" + , "config.frameworks" + , "target.frameworks" + , "toolchain.frameworks" + , "config.syslinks" + , "target.syslinks" + , "toolchain.syslinks" + } + , shared = { + "config.linkdirs" + , "config.frameworkdirs" + , "target.linkdirs" + , "target.frameworkdirs" + , "target.rpathdirs" + , "target.strip" + , "target.symbols" + , "target.optimize:check" + , "target.runtimes" + , "toolchain.linkdirs" + , "toolchain.rpathdirs" + , "toolchain.frameworkdirs" + , "config.links" + , "target.links" + , "target.linkgroups" + , "toolchain.links" + , "config.frameworks" + , "target.frameworks" + , "toolchain.frameworks" + , "config.syslinks" + , "target.syslinks" + , "toolchain.syslinks" + } + , static = { + "target.strip" + , "target.symbols" + } + } + + set_menu { + config = + { + {category = "Cross Complation Configuration/Compiler Configuration" } + , {nil, "cc", "kv", nil, "The C Compiler" } + , {nil, "cxx", "kv", nil, "The C++ Compiler" } + , {nil, "cpp", "kv", nil, "The C Preprocessor" } + + , {category = "Cross Complation Configuration/Linker Configuration" } + , {nil, "ld", "kv", nil, "The Linker" } + , {nil, "ar", "kv", nil, "The Static Library Linker" } + , {nil, "sh", "kv", nil, "The Shared Library Linker" } + , {nil, "ranlib", "kv", nil, "The Static Library Index Generator" } + + , {category = "Cross Complation Configuration/Compiler Flags Configuration" } + , {nil, "cflags", "kv", nil, "The C Compiler Flags" } + , {nil, "cxflags", "kv", nil, "The C/C++ compiler Flags" } + , {nil, "cxxflags", "kv", nil, "The C++ Compiler Flags" } + + , {category = "Cross Complation Configuration/Linker Flags Configuration" } + , {nil, "ldflags", "kv", nil, "The Binary Linker Flags" } + , {nil, "arflags", "kv", nil, "The Static Library Linker Flags" } + , {nil, "shflags", "kv", nil, "The Shared Library Linker Flags" } + + , {category = "Cross Complation Configuration/Builtin Flags Configuration" } + , {nil, "links", "kv", nil, "The Link Libraries" } + , {nil, "syslinks", "kv", nil, "The System Link Libraries" } + , {nil, "linkdirs", "kv", nil, "The Link Search Directories" } + , {nil, "includedirs", "kv", nil, "The Include Search Directories" } + , {nil, "frameworks", "kv", nil, "The Frameworks" } + , {nil, "frameworkdirs", "kv", nil, "The Frameworks Search Directories" } + } + } + + + + + + diff --git a/xmake/plugins/project/vsxmake/getinfo.lua b/xmake/plugins/project/vsxmake/getinfo.lua index e992c1bd488..a52e1f1b92e 100644 --- a/xmake/plugins/project/vsxmake/getinfo.lua +++ b/xmake/plugins/project/vsxmake/getinfo.lua @@ -36,6 +36,8 @@ import("private.action.run.runenvs") import("private.action.require.install", {alias = "install_requires"}) import("actions.config.configfiles", {alias = "generate_configfiles", rootdir = os.programdir()}) import("vstudio.impl.vsutils", {rootdir = path.join(os.programdir(), "plugins", "project")}) +import("detect.sdks.find_dotnet") +import("langtype") -- strip dot directories, e.g. ..\..\.. => .. -- @see https://github.com/xmake-io/xmake/issues/2039 @@ -143,6 +145,11 @@ function _make_targetinfo(mode, arch, target) -- save defines targetinfo.defines = _make_arrs(_get_values_from_target(target, "defines")) + -- save symbols, optimize, strip info + targetinfo.symbols = tostring(target:get("symbols")) + targetinfo.optimize = tostring(target:get("optimize")) + targetinfo.strip = tostring(target:get("strip")) + -- save flags targetinfo.cflags = _make_arrs(_get_flags_from_target(target, "cflags"), " ") targetinfo.cxflags = _make_arrs(_get_flags_from_target(target, "cxflags"), " ") @@ -486,6 +493,7 @@ function main(outputdir, vsinfo) -- init target info _target.target = targetname _target.vcxprojdir = path.join(vsinfo.solution_dir, targetname) + _target.csprojdir = path.join(vsinfo.solution_dir, targetname) _target.target_id = hash.uuid4(targetname) _target.kind = target:kind() _target.absscriptdir = target:scriptdir() @@ -496,10 +504,25 @@ function main(outputdir, vsinfo) _target._targets = _target._targets or {} _target._targets[mode] = _target._targets[mode] or {} local targetinfo = _make_targetinfo(mode, arch, target) + _target.languages = targetinfo.languages; + _target.symbols = targetinfo.symbols; + _target.optimize = targetinfo.optimize; + _target.strip = targetinfo.strip; + if langtype.isc(_target.languages) or langtype.iscpp(_target.languages) then + _target.tool_id = "8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942" + _target.proj_extension = "vcxproj" + elseif langtype.iscsharp(_target.languages) then + _target.tool_id = "FAE04EC0-301F-11D3-BF4B-00C04F79EFBC" + _target.proj_extension = "csproj" + end _target._targets[mode][arch] = targetinfo _target.sdkver = targetinfo.sdkver _target.default = targetinfo.default + -- dotnet + local dotnet = find_dotnet() + _target.dotnetsdkver = dotnet.sdkver + -- 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()))) diff --git a/xmake/plugins/project/vsxmake/langtype.lua b/xmake/plugins/project/vsxmake/langtype.lua new file mode 100644 index 00000000000..7e1d1648c28 --- /dev/null +++ b/xmake/plugins/project/vsxmake/langtype.lua @@ -0,0 +1,66 @@ +-- Copy from cl.lua +local _g = {} +_g.cxxmaps = +{ + cxx11 = "-std:c++11" +, gnuxx11 = "-std:c++11" +, cxx14 = "-std:c++14" +, gnuxx14 = "-std:c++14" +, cxx17 = "-std:c++17" +, gnuxx17 = "-std:c++17" +, cxx1z = "-std:c++17" +, gnuxx1z = "-std:c++17" +, cxx20 = {"-std:c++20", "-std:c++latest"} +, gnuxx20 = {"-std:c++20", "-std:c++latest"} +, cxx2a = {"-std:c++20", "-std:c++latest"} +, gnuxx2a = {"-std:c++20", "-std:c++latest"} +, cxx23 = {"-std:c++23", "-std:c++latest"} +, gnuxx23 = {"-std:c++23", "-std:c++latest"} +, cxx2b = {"-std:c++23", "-std:c++latest"} +, gnuxx2b = {"-std:c++23", "-std:c++latest"} +, cxxlatest = "-std:c++latest" +, gnuxxlatest = "-std:c++latest" +} + +_g.cmaps = +{ + -- stdc + c99 = "-TP" -- compile as c++ files because older msvc only support c89 +, gnu99 = "-TP" +, c11 = {"-std:c11", "-TP"} +, gnu11 = {"-std:c11", "-TP"} +, c17 = {"-std:c17", "-TP"} +, gnu17 = {"-std:c17", "-TP"} +, clatest = {"-std:c17", "-std:c11"} +, gnulatest = {"-std:c17", "-std:c11"} +} + +_g.csmaps = +{ + csharp = "-TP" +, +} + +function iscsharp(language) + if language and _g.csmaps[language] then + return true + end + + return false +end + +function isc(language) + if language and _g.cmaps[language] then + return true + end + + return false +end + +function iscpp(language) + if language and _g.cxxmaps[language] then + return true + end + + return false +end \ No newline at end of file diff --git a/xmake/plugins/project/vsxmake/vsxmake.lua b/xmake/plugins/project/vsxmake/vsxmake.lua index b7999449e91..0116ce834ec 100644 --- a/xmake/plugins/project/vsxmake/vsxmake.lua +++ b/xmake/plugins/project/vsxmake/vsxmake.lua @@ -24,12 +24,14 @@ import("core.base.hashset") import("vstudio.impl.vsinfo", { rootdir = path.directory(os.scriptdir()) }) import("render") import("getinfo") +import("langtype") import("core.project.config") import("core.cache.localcache") local template_root = path.join(os.programdir(), "scripts", "vsxmake", "vsproj", "templates") local template_sln = path.join(template_root, "sln", "vsxmake.sln") local template_vcx = path.join(template_root, "vcxproj", "#target#.vcxproj") +local template_cs = path.join(template_root, "csproj", "#target#.csproj") local template_fil = path.join(template_root, "vcxproj.filters", "#target#.vcxproj.filters") local template_props = path.join(template_root, "Xmake.Custom.props") @@ -124,6 +126,9 @@ function _buildparams(info, target, default) elseif args.filecxx then local files = info._targets[target].sourcefiles table.insert(r, _filter_files(files, {".cpp", ".cc", ".cxx"})) + elseif args.filecs then + local files = info._targets[target].sourcefiles + table.insert(r, _filter_files(files, {".cs"})) elseif args.filempp then local files = info._targets[target].sourcefiles table.insert(r, _filter_files(files, {".mpp", ".mxx", ".cppm", ".ixx"})) @@ -234,15 +239,24 @@ function make(version) for _, target in ipairs(info.targets) do local paramsprovidertarget = _buildparams(info, target, "") - local proj_dir = info._targets[target].vcxprojdir + local proj_dir; + local target_lang = info._targets[target].languages; + if langtype.isc(target_lang) or langtype.iscpp(target_lang) then + proj_dir = info._targets[target].vcxprojdir - -- write project file - local proj = path.join(proj_dir, target .. ".vcxproj") - _writefileifneeded(proj, render(template_vcx, "#([A-Za-z0-9_,%.%*%(%)]+)#", "@([^@]+)@", paramsprovidertarget)) + -- write project file + local proj = path.join(proj_dir, target .. ".vcxproj") + _writefileifneeded(proj, render(template_vcx, "#([A-Za-z0-9_,%.%*%(%)]+)#", "@([^@]+)@", paramsprovidertarget)) - local projfil = path.join(proj_dir, target .. ".vcxproj.filters") - _writefileifneeded(projfil, render(template_fil, "#([A-Za-z0-9_,%.%*%(%)]+)#", "@([^@]+)@", paramsprovidertarget)) + local projfil = path.join(proj_dir, target .. ".vcxproj.filters") + _writefileifneeded(projfil, render(template_fil, "#([A-Za-z0-9_,%.%*%(%)]+)#", "@([^@]+)@", paramsprovidertarget)) + elseif langtype.iscsharp(target_lang) then + proj_dir = info._targets[target].csprojdir + local proj = path.join(proj_dir, target .. ".csproj") + _writefileifneeded(proj, render(template_cs, "#([A-Za-z0-9_,%.%*%(%)]+)#", "@([^@]+)@", paramsprovidertarget)) + end + -- add project custom file _trycp(template_props, proj_dir) _trycp(template_targets, proj_dir) diff --git a/xmake/rules/csharp/xmake.lua b/xmake/rules/csharp/xmake.lua new file mode 100644 index 00000000000..f6455a34a68 --- /dev/null +++ b/xmake/rules/csharp/xmake.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-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file xmake.lua +-- + +rule("csharp.build") + set_sourcekinds("cs") + on_build_file(function (target, sourcefile) + os.execv("dotnet", {"build", sourcefile, "-o", target:targetdir()}) + end) + on_clean(function (target, sourcefile) + os.execv("dotnet", {"clean", sourcefile, "-o", target:targetdir()}) + end) + on_link(function () end) + +rule("csharp") + + -- add build rules + add_deps("csharp.build") + + -- inherit links and linkdirs of all dependent targets by default + add_deps("utils.inherit.links") + + -- support `add_files("src/*.o")` and `add_files("src/*.a")` to merge object and archive files to target + add_deps("utils.merge.object", "utils.merge.archive") + + -- we attempt to extract symbols to the independent file and + -- strip self-target binary if `set_symbols("debug")` and `set_strip("all")` are enabled + add_deps("utils.symbols.extract") + + -- add platform rules + add_deps("platform.wasm") + add_deps("platform.windows") + + -- add linker rules + add_deps("linker") + diff --git a/xmake/scripts/vsxmake/vsproj/Xmake.CSharp.targets b/xmake/scripts/vsxmake/vsproj/Xmake.CSharp.targets new file mode 100644 index 00000000000..e5919822f24 --- /dev/null +++ b/xmake/scripts/vsxmake/vsproj/Xmake.CSharp.targets @@ -0,0 +1,265 @@ + + + + + + + $(XmakeBuilDir) + $(XmakeTargetDir) + $(XmakeConfigDir) + $(XmakeConfigFileDir) + $(XmakeRunDir) + + + $([System.IO.Path]::GetFullPath('$(MSBuildProjectDirectory)\$(XmakeBuilDirResolved)')) + $([System.IO.Path]::GetFullPath('$(MSBuildProjectDirectory)\$(XmakeTargetDirResolved)')) + $([System.IO.Path]::GetFullPath('$(MSBuildProjectDirectory)\$(XmakeConfigDirResolved)')) + $([System.IO.Path]::GetFullPath('$(MSBuildProjectDirectory)\$(XmakeConfigFileDirResolved)')) + $([System.IO.Path]::GetFullPath('$(MSBuildProjectDirectory)\$(XmakeRunDirResolved)')) + + + $([System.IO.Path]::GetFullPath('$(XmakeBuilDirResolved)/')) + $([System.IO.Path]::GetFullPath('$(XmakeTargetDirResolved)/')) + $([System.IO.Path]::GetFullPath('$(XmakeConfigDirResolved)/')) + $([System.IO.Path]::GetFullPath('$(XmakeConfigFileDirResolved)/')) + $([System.IO.Path]::GetFullPath('$(XmakeRunDirResolved)/')) + + + $([System.IO.Path]::GetFullPath('$(XmakeProgramDir)/')) + $([System.IO.Path]::GetFullPath('$(XmakeProjectDir)/')) + $([System.IO.Path]::GetFullPath('$(XmakeScriptDir)/')) + + + + <_XmakeProjectFlag Condition="'$(XmakeProjectFile)' != ''">-F "$(XmakeProjectFile)" + <_XmakeProjectFlag Condition="'$(XmakeProjectFile)' == ''">-P . + + <_XmakeCommonFlags>$(XmakeCommonFlags.Trim()) + <_XmakeCommonFlags Condition="$(XmakeVerbose)">-v $(_XmakeCommonFlags.Trim()) + <_XmakeCommonFlags Condition="$(XmakeDiagnosis)">-D $(_XmakeCommonFlags.Trim()) + <_XmakeCommonFlags>-y $(_XmakeCommonFlags.Trim()) $(_XmakeProjectFlag) + + <_XmakeOutFlag>-o "$([MSBuild]::MakeRelative('$(XmakeProjectDirResolved)', '$(XmakeBuilDirResolved)').TrimEnd('\').TrimEnd('/'))" + + <_XmakeConfigFlags>$(XmakeConfigFlags.Trim()) + <_XmakeConfigFlags>-p $(XmakePlat) -m $(XmakeMode) -a $(XmakeArch) $(_XmakeOutFlag) $(_XmakeConfigFlags.Trim()) + + <_XmakeBuildFlags>$(XmakeBuildFlags.Trim()) + <_XmakeBuildFlags Condition="$(XmakeWarning)">-w $(_XmakeBuildFlags.Trim()) + + <_XmakeBuildFileFlags>$(_XmakeBuildFlags.Trim()) + <_XmakeBuildFileFlags Condition="$(XmakeRebuildFile)">$(_XmakeBuildFileFlags.Trim()) -r + + <_XmakeCleanFlags>$(XmakeCleanFlags.Trim()) + <_XmakeCleanFlags Condition="$(XmakeCleanAll)">-a $(_XmakeCleanFlags.Trim()) + + <_XmakeBuildFlags>$(_XmakeBuildFlags.Trim()) + <_XmakeBuildFileFlags>$(_XmakeBuildFileFlags.Trim()) + <_XmakeCleanFlags>$(_XmakeCleanFlags.Trim()) + <_XmakeConfigFlags>$(_XmakeConfigFlags.Trim()) + <_XmakeCommonFlags>$(_XmakeCommonFlags.Trim()) + <_XmakeTarget>"$(XmakeTarget.Trim())" + + <_XmakeExecutable>"$([System.IO.Path]::GetFullPath('$(XmakeProgramDirResolved)xmake.exe'))" + <_XmakeEnv> + pushd $(XmakeProjectDirResolved) + set XMAKE_CONFIGDIR=$(XmakeConfigDirResolved.TrimEnd('\').TrimEnd('/')) + set XMAKE_PROGRAM_DIR=$(XmakeProgramDirResolved.TrimEnd('\').TrimEnd('/')) + set XMAKE_SKIP_HISTORY=1 + set XMAKE_IN_VSTUDIO=1 + + <_XmakeEnv Condition="$(XmakeDiagnosis)"> + $(_XmakeEnv) + echo XMAKE_CONFIGDIR=%25XMAKE_CONFIGDIR%25 + echo XMAKE_PROGRAM_DIR=%25XMAKE_PROGRAM_DIR%25 + echo CD=%25CD%25 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --files="@(File)" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/xmake/scripts/vsxmake/vsproj/Xmake.Common.props b/xmake/scripts/vsxmake/vsproj/Xmake.Common.props new file mode 100644 index 00000000000..46b237eaaf1 --- /dev/null +++ b/xmake/scripts/vsxmake/vsproj/Xmake.Common.props @@ -0,0 +1,176 @@ + + + + + + $(Configuration) + release + + x86 + $(Platform) + x86 + + + + + + + + + + $(XmakeTarget) + $(AssemblyName) + $(MSBuildProjectName) + + binary + windows + + + + $(XmakeProjectDir)\build + $(XmakeBuilDir)\$(XmakePlat)\$(XmakeArch)\$(XmakeMode) + $(XmakeBuilDir)\$(XmakePlat)\$(XmakeArch)\$(XmakeMode) + + $(XMAKE_CONFIGDIR) + $(XmakeProjectDir) + + $(XmakeTargetDir) + + + + true + true + false + false + false + + + + $(XmakeWindowsSdkVersion) + + + + + + $(XmakeMfcKind) + Unicode + MultiByte + + + + + + + Exe + + + + + Library + + + + + + + Project + + + + + + + + + $(XmakeBasename) + $([System.IO.Path]::GetFileNameWithoutExtension('$(XmakeFilename)')) + $([System.IO.Path]::GetExtension('$(XmakeFilename)')) + + + + $(XmakeLinkDirs);$(LibraryPath) + $(XmakeTargetDir)\ + $(XmakeBuilDir)\.vs\$(AssemblyName)\$(XmakeArch)\$(XmakeMode)\ + $(BaseIntermediateOutputPath) + $(XmakeSourceDirs);$(SourcePath) + + + + $(XmakeDefines) + + + + prompt + 4 + + + + $(XmakeArch) + + + + + + full + true + + + + + none + false + + + + + embedded + true + + + + + portable + true + + + + + + false + true + + + + $(XmakeRunDir) + $(XmakeRunEnvs) +$(LocalDebuggerEnvironment) + $(XmakeRunArgs) + true + $(XmakeRunDir) + $(XmakeRunEnvs) +$(RemoteDebuggerEnvironment) + $(XmakeRunArgs) + + + + + + + + + + + + + diff --git a/xmake/scripts/vsxmake/vsproj/Xmake.props b/xmake/scripts/vsxmake/vsproj/Xmake.props index 3e3a3329825..a5b240f76f4 100644 --- a/xmake/scripts/vsxmake/vsproj/Xmake.props +++ b/xmake/scripts/vsxmake/vsproj/Xmake.props @@ -105,7 +105,7 @@ stdcpp14 stdcpp17 stdcpp17 - stdcpplatest + stdcpp20 stdcpplatest stdcpplatest stdcpplatest @@ -114,7 +114,7 @@ stdcpp14 stdcpp17 stdcpp17 - stdcpplatest + stdcpp20 stdcpplatest stdcpplatest stdcpplatest diff --git a/xmake/scripts/vsxmake/vsproj/templates/csproj/#target#.csproj b/xmake/scripts/vsxmake/vsproj/templates/csproj/#target#.csproj new file mode 100644 index 00000000000..e119ddb1c80 --- /dev/null +++ b/xmake/scripts/vsxmake/vsproj/templates/csproj/#target#.csproj @@ -0,0 +1,48 @@ + + + + + $(XMAKE_PROGRAM_DIR) + #programdir# + + +#Import(XmakeConfig)# +#Import(XmakePath)# + + debug + x64 + {#target_id#} + Properties + #target# + #target# + v#dotnetsdkver# + 512 + true + #scriptdir# + #projectdir# + #projectfile# + #target# + + + + + +#Import(File.cs)# + + + + + + \ No newline at end of file diff --git a/xmake/scripts/vsxmake/vsproj/templates/csproj/File.cs(filecs) b/xmake/scripts/vsxmake/vsproj/templates/csproj/File.cs(filecs) new file mode 100644 index 00000000000..f1f9c063a13 --- /dev/null +++ b/xmake/scripts/vsxmake/vsproj/templates/csproj/File.cs(filecs) @@ -0,0 +1 @@ + diff --git a/xmake/scripts/vsxmake/vsproj/templates/csproj/ProjectRef(dep) b/xmake/scripts/vsxmake/vsproj/templates/csproj/ProjectRef(dep) new file mode 100644 index 00000000000..33434eca34a --- /dev/null +++ b/xmake/scripts/vsxmake/vsproj/templates/csproj/ProjectRef(dep) @@ -0,0 +1,3 @@ + + {#target_id#} + diff --git a/xmake/scripts/vsxmake/vsproj/templates/csproj/XmakeConfig(mode,arch) b/xmake/scripts/vsxmake/vsproj/templates/csproj/XmakeConfig(mode,arch) new file mode 100644 index 00000000000..e74b012594c --- /dev/null +++ b/xmake/scripts/vsxmake/vsproj/templates/csproj/XmakeConfig(mode,arch) @@ -0,0 +1,29 @@ + + #basename# + #filename# + #mode# + #symbols# + #optimize# + #strip# + #plat# + #arch# + #kind# + #default# + #defines# + #languages# + #subsystem# + #cudaver# + #sdkver# + #dotnetsdkver# + #mfckind# + #runenvs# + #runargs# + #configflags# + #includedirs# + #linkdirs# + #sourcedirs# + #pcheaderfile# + #cflags# + #cxflags# + #cxxflags# + diff --git a/xmake/scripts/vsxmake/vsproj/templates/csproj/XmakePath(mode,arch) b/xmake/scripts/vsxmake/vsproj/templates/csproj/XmakePath(mode,arch) new file mode 100644 index 00000000000..9afa8460fa1 --- /dev/null +++ b/xmake/scripts/vsxmake/vsproj/templates/csproj/XmakePath(mode,arch) @@ -0,0 +1,7 @@ + + #buildir# + #configdir# + #configfiledir# + #targetdir# + #rundir# + diff --git a/xmake/scripts/vsxmake/vsproj/templates/sln/Project(target) b/xmake/scripts/vsxmake/vsproj/templates/sln/Project(target) index 11e743c8a6d..6d8c005abb3 100644 --- a/xmake/scripts/vsxmake/vsproj/templates/sln/Project(target) +++ b/xmake/scripts/vsxmake/vsproj/templates/sln/Project(target) @@ -1,2 +1,2 @@ -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "#target#", "#target#\#target#.vcxproj", "{#target_id#}" +Project("{#tool_id#}") = "#target#", "#target#\#target#.#proj_extension#", "{#target_id#}" EndProject From bf5c764c88f68fc8b98d56aa219f30e63ae712ac Mon Sep 17 00:00:00 2001 From: Kethers <49612587+Kethers@users.noreply.github.com> Date: Mon, 11 Dec 2023 02:30:31 +0800 Subject: [PATCH 02/12] fix csproj dependency build error, remove cuda and vc relevant things --- xmake/scripts/vsxmake/vsproj/Xmake.CSharp.targets | 12 +----------- xmake/scripts/vsxmake/vsproj/Xmake.Common.props | 5 ----- .../vsxmake/vsproj/templates/csproj/#target#.csproj | 4 ++-- 3 files changed, 3 insertions(+), 18 deletions(-) diff --git a/xmake/scripts/vsxmake/vsproj/Xmake.CSharp.targets b/xmake/scripts/vsxmake/vsproj/Xmake.CSharp.targets index e5919822f24..026c8473863 100644 --- a/xmake/scripts/vsxmake/vsproj/Xmake.CSharp.targets +++ b/xmake/scripts/vsxmake/vsproj/Xmake.CSharp.targets @@ -77,10 +77,6 @@ - - @@ -251,9 +244,6 @@ MSBuild Properties: - - - diff --git a/xmake/scripts/vsxmake/vsproj/Xmake.Common.props b/xmake/scripts/vsxmake/vsproj/Xmake.Common.props index 46b237eaaf1..ce33754fe7f 100644 --- a/xmake/scripts/vsxmake/vsproj/Xmake.Common.props +++ b/xmake/scripts/vsxmake/vsproj/Xmake.Common.props @@ -81,11 +81,6 @@ - - - - $(XmakeBasename) $([System.IO.Path]::GetFileNameWithoutExtension('$(XmakeFilename)')) diff --git a/xmake/scripts/vsxmake/vsproj/templates/csproj/#target#.csproj b/xmake/scripts/vsxmake/vsproj/templates/csproj/#target#.csproj index e119ddb1c80..ff0dc28501f 100644 --- a/xmake/scripts/vsxmake/vsproj/templates/csproj/#target#.csproj +++ b/xmake/scripts/vsxmake/vsproj/templates/csproj/#target#.csproj @@ -15,9 +15,7 @@ $(XMAKE_PROGRAM_DIR) #programdir# - #Import(XmakeConfig)# -#Import(XmakePath)# debug x64 @@ -33,6 +31,8 @@ #projectfile# #target# + +#Import(XmakePath)# From 3586f803112f6b421be45dae5eacce10f83d844b Mon Sep 17 00:00:00 2001 From: Kethers <49612587+Kethers@users.noreply.github.com> Date: Mon, 11 Dec 2023 02:31:52 +0800 Subject: [PATCH 03/12] Add project reference in .csproj, VS editor C# IntelliSense works fine now --- xmake/scripts/vsxmake/vsproj/templates/csproj/#target#.csproj | 4 ++-- xmake/scripts/vsxmake/vsproj/templates/csproj/ProjectRef(dep) | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/xmake/scripts/vsxmake/vsproj/templates/csproj/#target#.csproj b/xmake/scripts/vsxmake/vsproj/templates/csproj/#target#.csproj index ff0dc28501f..906f493bd65 100644 --- a/xmake/scripts/vsxmake/vsproj/templates/csproj/#target#.csproj +++ b/xmake/scripts/vsxmake/vsproj/templates/csproj/#target#.csproj @@ -41,8 +41,8 @@ - + \ No newline at end of file diff --git a/xmake/scripts/vsxmake/vsproj/templates/csproj/ProjectRef(dep) b/xmake/scripts/vsxmake/vsproj/templates/csproj/ProjectRef(dep) index 33434eca34a..dfccc2095bd 100644 --- a/xmake/scripts/vsxmake/vsproj/templates/csproj/ProjectRef(dep) +++ b/xmake/scripts/vsxmake/vsproj/templates/csproj/ProjectRef(dep) @@ -1,3 +1,4 @@ - + {#target_id#} + {#target#} From 9ce9c62ebd6c7947e637ed49445676f273b529fb Mon Sep 17 00:00:00 2001 From: Kethers <49612587+Kethers@users.noreply.github.com> Date: Fri, 15 Dec 2023 22:40:06 +0800 Subject: [PATCH 04/12] Use MSBuild for compiling .csproj and modified the obj dir --- xmake/languages/csharp/check_main.lua | 2 +- xmake/plugins/project/vstudio/impl/vsinfo.lua | 7 +++++ xmake/plugins/project/vsxmake/getinfo.lua | 29 ++++++++++--------- xmake/rules/csharp/xmake.lua | 14 ++++++--- .../vsxmake/vsproj/Xmake.CSharp.targets | 2 ++ .../scripts/vsxmake/vsproj/Xmake.Common.props | 11 +++---- .../vsproj/templates/csproj/#target#.csproj | 4 +-- .../templates/csproj/XmakeConfig(mode,arch) | 2 +- .../templates/csproj/XmakePath(mode,arch) | 1 + 9 files changed, 44 insertions(+), 28 deletions(-) diff --git a/xmake/languages/csharp/check_main.lua b/xmake/languages/csharp/check_main.lua index 55d00e2ded4..c0a2f66640b 100644 --- a/xmake/languages/csharp/check_main.lua +++ b/xmake/languages/csharp/check_main.lua @@ -30,7 +30,7 @@ function main(sourcefile) sourcecode = sourcecode:gsub("//.-\n", "\n") -- find int main(int argc, char** argv) {} - if sourcecode:find("%s+main%s*%(.-%)") then + if sourcecode:find("%s+Main%s*%(.-%)") then return true end diff --git a/xmake/plugins/project/vstudio/impl/vsinfo.lua b/xmake/plugins/project/vstudio/impl/vsinfo.lua index e210f670572..d969c8a3767 100644 --- a/xmake/plugins/project/vstudio/impl/vsinfo.lua +++ b/xmake/plugins/project/vstudio/impl/vsinfo.lua @@ -46,6 +46,7 @@ local vsinfo = , filters_version = "4.0" , solution_version = "11" , toolset_version = "v100" + , dotnetframework_ver = "4.0" } , [2012] = { vstudio_version = "2012" @@ -53,6 +54,7 @@ local vsinfo = , filters_version = "4.0" , solution_version = "12" , toolset_version = "v110" + , dotnetframework_ver = "4.5" } , [2013] = { vstudio_version = "2013" @@ -60,6 +62,7 @@ local vsinfo = , filters_version = "4.0" , solution_version = "12" , toolset_version = "v120" + , dotnetframework_ver = "4.5" } , [2015] = { vstudio_version = "2015" @@ -68,6 +71,7 @@ local vsinfo = , solution_version = "12" , toolset_version = "v140" , sdk_version = "10.0.10240.0" + , dotnetframework_ver = "4.5" } , [2017] = { vstudio_version = "2017" @@ -76,6 +80,7 @@ local vsinfo = , solution_version = "12" , toolset_version = "v141" , sdk_version = "10.0.14393.0" + , dotnetframework_ver = "4.5.2" } , [2019] = { vstudio_version = "2019" @@ -84,6 +89,7 @@ local vsinfo = , solution_version = "12" , toolset_version = "v142" , sdk_version = "10.0.17763.0" + , dotnetframework_ver = "4.7.2" } , [2022] = { vstudio_version = "2022" @@ -92,6 +98,7 @@ local vsinfo = , solution_version = "12" , toolset_version = "v143" , sdk_version = "10.0.19041.0" + , dotnetframework_ver = "4.7.2" } } diff --git a/xmake/plugins/project/vsxmake/getinfo.lua b/xmake/plugins/project/vsxmake/getinfo.lua index a52e1f1b92e..f2da439801f 100644 --- a/xmake/plugins/project/vsxmake/getinfo.lua +++ b/xmake/plugins/project/vsxmake/getinfo.lua @@ -36,7 +36,6 @@ import("private.action.run.runenvs") import("private.action.require.install", {alias = "install_requires"}) import("actions.config.configfiles", {alias = "generate_configfiles", rootdir = os.programdir()}) import("vstudio.impl.vsutils", {rootdir = path.join(os.programdir(), "plugins", "project")}) -import("detect.sdks.find_dotnet") import("langtype") -- strip dot directories, e.g. ..\..\.. => .. @@ -134,6 +133,7 @@ function _make_targetinfo(mode, arch, target) -- save dirs targetinfo.targetdir = _make_dirs(target:get("targetdir")) targetinfo.buildir = _make_dirs(config.get("buildir")) + targetinfo.objectdir = _make_dirs(target:get("objectdir")) targetinfo.rundir = _make_dirs(target:get("rundir")) targetinfo.configdir = _make_dirs(os.getenv("XMAKE_CONFIGDIR")) targetinfo.configfiledir = _make_dirs(target:get("configdir")) @@ -494,15 +494,8 @@ function main(outputdir, vsinfo) _target.target = targetname _target.vcxprojdir = path.join(vsinfo.solution_dir, targetname) _target.csprojdir = path.join(vsinfo.solution_dir, targetname) - _target.target_id = hash.uuid4(targetname) - _target.kind = target:kind() - _target.absscriptdir = target:scriptdir() - _target.scriptdir = path.relative(target:scriptdir(), _target.vcxprojdir) - _target.projectdir = path.relative(project.directory(), _target.vcxprojdir) - local targetdir = target:get("targetdir") - if targetdir then _target.targetdir = path.relative(targetdir, _target.vcxprojdir) end - _target._targets = _target._targets or {} - _target._targets[mode] = _target._targets[mode] or {} + local xxprojdir = _target.vcxprojdir + local targetinfo = _make_targetinfo(mode, arch, target) _target.languages = targetinfo.languages; _target.symbols = targetinfo.symbols; @@ -511,17 +504,27 @@ function main(outputdir, vsinfo) if langtype.isc(_target.languages) or langtype.iscpp(_target.languages) then _target.tool_id = "8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942" _target.proj_extension = "vcxproj" + xxprojdir = _target.vcxprojdir elseif langtype.iscsharp(_target.languages) then _target.tool_id = "FAE04EC0-301F-11D3-BF4B-00C04F79EFBC" _target.proj_extension = "csproj" + xxprojdir = _target.csprojdir end + + _target.target_id = hash.uuid4(targetname) + _target.kind = target:kind() + _target.absscriptdir = target:scriptdir() + _target.scriptdir = path.relative(target:scriptdir(), xxprojdir) + _target.projectdir = path.relative(project.directory(), xxprojdir) + local targetdir = target:get("targetdir") + if targetdir then _target.targetdir = path.relative(targetdir, xxprojdir) end + _target._targets = _target._targets or {} + _target._targets[mode] = _target._targets[mode] or {} _target._targets[mode][arch] = targetinfo _target.sdkver = targetinfo.sdkver _target.default = targetinfo.default - -- dotnet - local dotnet = find_dotnet() - _target.dotnetsdkver = dotnet.sdkver + _target.dotnetframeworkver = vsinfo.dotnetframework_ver -- save all sourcefiles and headerfiles _target.sourcefiles = table.unique(table.join(_target.sourcefiles or {}, (target:sourcefiles()))) diff --git a/xmake/rules/csharp/xmake.lua b/xmake/rules/csharp/xmake.lua index f6455a34a68..2824472a6cb 100644 --- a/xmake/rules/csharp/xmake.lua +++ b/xmake/rules/csharp/xmake.lua @@ -20,12 +20,18 @@ rule("csharp.build") set_sourcekinds("cs") - on_build_file(function (target, sourcefile) - os.execv("dotnet", {"build", sourcefile, "-o", target:targetdir()}) + -- TODO: now csharp builds is using MSBuild.exe, below code does nothing + -- if you want this file to be used, go to #target#.csproj file and replace + -- $(MSBuildToolsPath)\Microsoft.CSharp.targets + -- $(XmakeProgramDir)\scripts\vsxmake\vsproj\Xmake.CSharp.targets + on_build(function(target) + end) - on_clean(function (target, sourcefile) - os.execv("dotnet", {"clean", sourcefile, "-o", target:targetdir()}) + + on_clean(function(target) + end) + on_link(function () end) rule("csharp") diff --git a/xmake/scripts/vsxmake/vsproj/Xmake.CSharp.targets b/xmake/scripts/vsxmake/vsproj/Xmake.CSharp.targets index 026c8473863..7e4ee3f69fd 100644 --- a/xmake/scripts/vsxmake/vsproj/Xmake.CSharp.targets +++ b/xmake/scripts/vsxmake/vsproj/Xmake.CSharp.targets @@ -83,6 +83,8 @@ Text="xmake.lua not found at '$(XmakeProjectDirResolved)', please set XmakeProjectDir in csproj file" /> + diff --git a/xmake/scripts/vsxmake/vsproj/Xmake.Common.props b/xmake/scripts/vsxmake/vsproj/Xmake.Common.props index ce33754fe7f..9ef748d4eba 100644 --- a/xmake/scripts/vsxmake/vsproj/Xmake.Common.props +++ b/xmake/scripts/vsxmake/vsproj/Xmake.Common.props @@ -51,10 +51,6 @@ $(XmakeWindowsSdkVersion) - - $(XmakeMfcKind) Unicode @@ -88,9 +84,10 @@ - $(XmakeLinkDirs);$(LibraryPath) + $(XmakeTargetDir)\ - $(XmakeBuilDir)\.vs\$(AssemblyName)\$(XmakeArch)\$(XmakeMode)\ + $(XmakeObjectDir)\ + $(XmakeBuilDir)\.vs\$(AssemblyName)\$(XmakeArch)\$(XmakeMode)\ $(BaseIntermediateOutputPath) $(XmakeSourceDirs);$(SourcePath) @@ -121,7 +118,7 @@ false - + embedded true diff --git a/xmake/scripts/vsxmake/vsproj/templates/csproj/#target#.csproj b/xmake/scripts/vsxmake/vsproj/templates/csproj/#target#.csproj index 906f493bd65..6c85432b633 100644 --- a/xmake/scripts/vsxmake/vsproj/templates/csproj/#target#.csproj +++ b/xmake/scripts/vsxmake/vsproj/templates/csproj/#target#.csproj @@ -23,7 +23,7 @@ Properties #target# #target# - v#dotnetsdkver# + v#dotnetframeworkver# 512 true #scriptdir# @@ -44,5 +44,5 @@ #Import(ProjectRef)# - + \ No newline at end of file diff --git a/xmake/scripts/vsxmake/vsproj/templates/csproj/XmakeConfig(mode,arch) b/xmake/scripts/vsxmake/vsproj/templates/csproj/XmakeConfig(mode,arch) index e74b012594c..f1281649cc4 100644 --- a/xmake/scripts/vsxmake/vsproj/templates/csproj/XmakeConfig(mode,arch) +++ b/xmake/scripts/vsxmake/vsproj/templates/csproj/XmakeConfig(mode,arch) @@ -14,7 +14,7 @@ #subsystem# #cudaver# #sdkver# - #dotnetsdkver# + #dotnetframeworkver# #mfckind# #runenvs# #runargs# diff --git a/xmake/scripts/vsxmake/vsproj/templates/csproj/XmakePath(mode,arch) b/xmake/scripts/vsxmake/vsproj/templates/csproj/XmakePath(mode,arch) index 9afa8460fa1..5dd3618d2f7 100644 --- a/xmake/scripts/vsxmake/vsproj/templates/csproj/XmakePath(mode,arch) +++ b/xmake/scripts/vsxmake/vsproj/templates/csproj/XmakePath(mode,arch) @@ -3,5 +3,6 @@ #configdir# #configfiledir# #targetdir# + #objectdir# #rundir# From 4b62543dd575d9198b6f94b3aeff849a7c701013 Mon Sep 17 00:00:00 2001 From: Kethers <49612587+Kethers@users.noreply.github.com> Date: Fri, 15 Dec 2023 22:45:36 +0800 Subject: [PATCH 05/12] fix: set_objectdir not works with vsxmake --- xmake/scripts/vsxmake/vsproj/Xmake.props | 3 ++- .../vsxmake/vsproj/templates/vcxproj/XmakePath(mode,arch) | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/xmake/scripts/vsxmake/vsproj/Xmake.props b/xmake/scripts/vsxmake/vsproj/Xmake.props index a5b240f76f4..682b376492f 100644 --- a/xmake/scripts/vsxmake/vsproj/Xmake.props +++ b/xmake/scripts/vsxmake/vsproj/Xmake.props @@ -165,7 +165,8 @@ $(XmakeLinkDirs);$(LibraryPath) $(XmakeTargetDir)\ - $(XmakeBuilDir)\.vs\$(TargetName)\$(XmakeArch)\$(XmakeMode)\ + $(XmakeObjectDir)\ + $(XmakeBuilDir)\.vs\$(TargetName)\$(XmakeArch)\$(XmakeMode)\ $(XmakeSourceDirs);$(SourcePath) diff --git a/xmake/scripts/vsxmake/vsproj/templates/vcxproj/XmakePath(mode,arch) b/xmake/scripts/vsxmake/vsproj/templates/vcxproj/XmakePath(mode,arch) index 9afa8460fa1..5dd3618d2f7 100644 --- a/xmake/scripts/vsxmake/vsproj/templates/vcxproj/XmakePath(mode,arch) +++ b/xmake/scripts/vsxmake/vsproj/templates/vcxproj/XmakePath(mode,arch) @@ -3,5 +3,6 @@ #configdir# #configfiledir# #targetdir# + #objectdir# #rundir# From 864dfd9daf1d71e37012991186b7238d864939b8 Mon Sep 17 00:00:00 2001 From: Kethers <49612587+Kethers@users.noreply.github.com> Date: Fri, 15 Dec 2023 22:51:53 +0800 Subject: [PATCH 06/12] Add project Reference in .vcxproj --- .../scripts/vsxmake/vsproj/templates/vcxproj/#target#.vcxproj | 4 ++-- .../scripts/vsxmake/vsproj/templates/vcxproj/ProjectRef(dep) | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/xmake/scripts/vsxmake/vsproj/templates/vcxproj/#target#.vcxproj b/xmake/scripts/vsxmake/vsproj/templates/vcxproj/#target#.vcxproj index b194ce86cf8..53135827f07 100644 --- a/xmake/scripts/vsxmake/vsproj/templates/vcxproj/#target#.vcxproj +++ b/xmake/scripts/vsxmake/vsproj/templates/vcxproj/#target#.vcxproj @@ -48,8 +48,8 @@ #Import(File.rc)# #Import(File.ui)# - + diff --git a/xmake/scripts/vsxmake/vsproj/templates/vcxproj/ProjectRef(dep) b/xmake/scripts/vsxmake/vsproj/templates/vcxproj/ProjectRef(dep) index 33434eca34a..dfccc2095bd 100644 --- a/xmake/scripts/vsxmake/vsproj/templates/vcxproj/ProjectRef(dep) +++ b/xmake/scripts/vsxmake/vsproj/templates/vcxproj/ProjectRef(dep) @@ -1,3 +1,4 @@ - + {#target_id#} + {#target#} From 81b8de55638e10ea687db705d8a190e76b67c3e2 Mon Sep 17 00:00:00 2001 From: Kethers <838859010@qq.com> Date: Sat, 16 Dec 2023 02:15:57 +0800 Subject: [PATCH 07/12] Add License info in csharp relevant file --- xmake/languages/csharp/check_main.lua | 4 ++-- xmake/languages/csharp/xmake.lua | 22 ++++++++++++++++++++-- xmake/plugins/project/vsxmake/langtype.lua | 20 ++++++++++++++++++++ xmake/rules/csharp/xmake.lua | 2 +- 4 files changed, 43 insertions(+), 5 deletions(-) diff --git a/xmake/languages/csharp/check_main.lua b/xmake/languages/csharp/check_main.lua index c0a2f66640b..291d69e3e1d 100644 --- a/xmake/languages/csharp/check_main.lua +++ b/xmake/languages/csharp/check_main.lua @@ -14,7 +14,7 @@ -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- --- @author ruki +-- @author Kethers -- @file check_main.lua -- @@ -29,7 +29,7 @@ function main(sourcefile) sourcecode = sourcecode:gsub("/%*.-%*/", "") sourcecode = sourcecode:gsub("//.-\n", "\n") - -- find int main(int argc, char** argv) {} + -- find static void Main(string[] args) {} if sourcecode:find("%s+Main%s*%(.-%)") then return true end diff --git a/xmake/languages/csharp/xmake.lua b/xmake/languages/csharp/xmake.lua index 361755004de..8a6ccf91a9c 100644 --- a/xmake/languages/csharp/xmake.lua +++ b/xmake/languages/csharp/xmake.lua @@ -1,8 +1,26 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author Kethers +-- @file xmake.lua +-- + language("csharp") add_rules("csharp") set_sourcekinds {cs = {".cs"}} - -- set_sourceflags {cs = {"csflags"}} - -- TODO: set kinds and flags set_targetkinds {binary = "ld", static = "ar", shared = "sh"} set_targetflags {binary = "ldflags", static = "arflags", shared = "shflags"} set_langkinds {cs = "cs"} diff --git a/xmake/plugins/project/vsxmake/langtype.lua b/xmake/plugins/project/vsxmake/langtype.lua index 7e1d1648c28..18e99b08134 100644 --- a/xmake/plugins/project/vsxmake/langtype.lua +++ b/xmake/plugins/project/vsxmake/langtype.lua @@ -1,3 +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-present, TBOOX Open Source Group. +-- +-- @author Kethers +-- @file langtype.lua +-- + -- Copy from cl.lua local _g = {} _g.cxxmaps = diff --git a/xmake/rules/csharp/xmake.lua b/xmake/rules/csharp/xmake.lua index 2824472a6cb..f6cac3d3f9e 100644 --- a/xmake/rules/csharp/xmake.lua +++ b/xmake/rules/csharp/xmake.lua @@ -14,7 +14,7 @@ -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- --- @author ruki +-- @author Kethers -- @file xmake.lua -- From 8aec760f7b88fd186afa9369f5a69007c97e62fc Mon Sep 17 00:00:00 2001 From: Kethers <838859010@qq.com> Date: Sun, 17 Dec 2023 14:39:39 +0800 Subject: [PATCH 08/12] Unused apis clean up and some code reformat --- xmake/languages/csharp/load.lua | 25 ---- xmake/languages/csharp/xmake.lua | 12 +- xmake/plugins/project/vstudio/impl/vsinfo.lua | 118 +++++++++--------- xmake/plugins/project/vsxmake/getinfo.lua | 8 +- xmake/rules/csharp/xmake.lua | 4 +- .../templates/csproj/XmakeConfig(mode,arch) | 4 - 6 files changed, 65 insertions(+), 106 deletions(-) diff --git a/xmake/languages/csharp/load.lua b/xmake/languages/csharp/load.lua index 932769a7cb7..7b7e2e95a73 100644 --- a/xmake/languages/csharp/load.lua +++ b/xmake/languages/csharp/load.lua @@ -25,9 +25,6 @@ function _get_apis() -- target.add_xxx "target.add_links" , "target.add_syslinks" - , "target.add_cflags" - , "target.add_cxflags" - , "target.add_cxxflags" , "target.add_ldflags" , "target.add_arflags" , "target.add_shflags" @@ -55,29 +52,9 @@ function _get_apis() , "option.add_undefines" , "option.add_frameworks" , "option.add_rpathdirs" - -- package.add_xxx - , "package.add_links" - , "package.add_syslinks" - , "package.add_cflags" - , "package.add_cxflags" - , "package.add_cxxflags" - , "package.add_ldflags" - , "package.add_arflags" - , "package.add_shflags" - , "package.add_defines" - , "package.add_undefines" - , "package.add_frameworks" - , "package.add_rpathdirs" - , "package.add_linkdirs" - , "package.add_includedirs" --@note we need not uses paths for package, see https://github.com/xmake-io/xmake/issues/717 - , "package.add_sysincludedirs" - , "package.add_frameworkdirs" -- toolchain.add_xxx , "toolchain.add_links" , "toolchain.add_syslinks" - , "toolchain.add_cflags" - , "toolchain.add_cxflags" - , "toolchain.add_cxxflags" , "toolchain.add_ldflags" , "toolchain.add_arflags" , "toolchain.add_shflags" @@ -116,8 +93,6 @@ function _get_apis() } apis.dictionary = { -- option.add_xxx - "option.add_csnippets" - , "option.add_cxxsnippets" } return apis end diff --git a/xmake/languages/csharp/xmake.lua b/xmake/languages/csharp/xmake.lua index 8a6ccf91a9c..ca6b55e016f 100644 --- a/xmake/languages/csharp/xmake.lua +++ b/xmake/languages/csharp/xmake.lua @@ -117,22 +117,12 @@ language("csharp") set_menu { config = { - {category = "Cross Complation Configuration/Compiler Configuration" } - , {nil, "cc", "kv", nil, "The C Compiler" } - , {nil, "cxx", "kv", nil, "The C++ Compiler" } - , {nil, "cpp", "kv", nil, "The C Preprocessor" } - - , {category = "Cross Complation Configuration/Linker Configuration" } + {category = "Cross Complation Configuration/Linker Configuration" } , {nil, "ld", "kv", nil, "The Linker" } , {nil, "ar", "kv", nil, "The Static Library Linker" } , {nil, "sh", "kv", nil, "The Shared Library Linker" } , {nil, "ranlib", "kv", nil, "The Static Library Index Generator" } - , {category = "Cross Complation Configuration/Compiler Flags Configuration" } - , {nil, "cflags", "kv", nil, "The C Compiler Flags" } - , {nil, "cxflags", "kv", nil, "The C/C++ compiler Flags" } - , {nil, "cxxflags", "kv", nil, "The C++ Compiler Flags" } - , {category = "Cross Complation Configuration/Linker Flags Configuration" } , {nil, "ldflags", "kv", nil, "The Binary Linker Flags" } , {nil, "arflags", "kv", nil, "The Static Library Linker Flags" } diff --git a/xmake/plugins/project/vstudio/impl/vsinfo.lua b/xmake/plugins/project/vstudio/impl/vsinfo.lua index d969c8a3767..3ce9d88cb22 100644 --- a/xmake/plugins/project/vstudio/impl/vsinfo.lua +++ b/xmake/plugins/project/vstudio/impl/vsinfo.lua @@ -21,84 +21,84 @@ local vsinfo = { [2002] = - { vstudio_version = "2002" - , solution_version = "7" - , project_version = "7.0" + { vstudio_version = "2002" + , solution_version = "7" + , project_version = "7.0" } , [2003] = - { vstudio_version = "2003" - , solution_version = "8" - , project_version = "7.1" + { vstudio_version = "2003" + , solution_version = "8" + , project_version = "7.1" } , [2005] = - { vstudio_version = "2005" - , solution_version = "9" - , project_version = "8.0" - } + { vstudio_version = "2005" + , solution_version = "9" + , project_version = "8.0" + } , [2008] = - { vstudio_version = "2008" - , solution_version = "10" - , project_version = "9.0" + { 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" - , dotnetframework_ver = "4.0" + { vstudio_version = "2010" + , project_version = "4" + , filters_version = "4.0" + , solution_version = "11" + , toolset_version = "v100" + , dotnetframework_version = "4.0" } , [2012] = - { vstudio_version = "2012" - , project_version = "4" - , filters_version = "4.0" - , solution_version = "12" - , toolset_version = "v110" - , dotnetframework_ver = "4.5" + { vstudio_version = "2012" + , project_version = "4" + , filters_version = "4.0" + , solution_version = "12" + , toolset_version = "v110" + , dotnetframework_version = "4.5" } , [2013] = - { vstudio_version = "2013" - , project_version = "12" - , filters_version = "4.0" - , solution_version = "12" - , toolset_version = "v120" - , dotnetframework_ver = "4.5" + { vstudio_version = "2013" + , project_version = "12" + , filters_version = "4.0" + , solution_version = "12" + , toolset_version = "v120" + , dotnetframework_version = "4.5" } , [2015] = - { vstudio_version = "2015" - , project_version = "14" - , filters_version = "4.0" - , solution_version = "12" - , toolset_version = "v140" - , sdk_version = "10.0.10240.0" - , dotnetframework_ver = "4.5" + { vstudio_version = "2015" + , project_version = "14" + , filters_version = "4.0" + , solution_version = "12" + , toolset_version = "v140" + , sdk_version = "10.0.10240.0" + , dotnetframework_version = "4.5" } , [2017] = - { vstudio_version = "2017" - , project_version = "15" - , filters_version = "4.0" - , solution_version = "12" - , toolset_version = "v141" - , sdk_version = "10.0.14393.0" - , dotnetframework_ver = "4.5.2" + { vstudio_version = "2017" + , project_version = "15" + , filters_version = "4.0" + , solution_version = "12" + , toolset_version = "v141" + , sdk_version = "10.0.14393.0" + , dotnetframework_version = "4.5.2" } , [2019] = - { vstudio_version = "2019" - , project_version = "16" - , filters_version = "4.0" - , solution_version = "12" - , toolset_version = "v142" - , sdk_version = "10.0.17763.0" - , dotnetframework_ver = "4.7.2" + { vstudio_version = "2019" + , project_version = "16" + , filters_version = "4.0" + , solution_version = "12" + , toolset_version = "v142" + , sdk_version = "10.0.17763.0" + , dotnetframework_version = "4.7.2" } , [2022] = - { vstudio_version = "2022" - , project_version = "17" - , filters_version = "4.0" - , solution_version = "12" - , toolset_version = "v143" - , sdk_version = "10.0.19041.0" - , dotnetframework_ver = "4.7.2" + { vstudio_version = "2022" + , project_version = "17" + , filters_version = "4.0" + , solution_version = "12" + , toolset_version = "v143" + , sdk_version = "10.0.19041.0" + , dotnetframework_version = "4.7.2" } } diff --git a/xmake/plugins/project/vsxmake/getinfo.lua b/xmake/plugins/project/vsxmake/getinfo.lua index f2da439801f..3787070f6be 100644 --- a/xmake/plugins/project/vsxmake/getinfo.lua +++ b/xmake/plugins/project/vsxmake/getinfo.lua @@ -146,9 +146,9 @@ function _make_targetinfo(mode, arch, target) targetinfo.defines = _make_arrs(_get_values_from_target(target, "defines")) -- save symbols, optimize, strip info - targetinfo.symbols = tostring(target:get("symbols")) - targetinfo.optimize = tostring(target:get("optimize")) - targetinfo.strip = tostring(target:get("strip")) + targetinfo.symbols = target:get("symbols") + targetinfo.optimize = target:get("optimize") + targetinfo.strip = target:get("strip") -- save flags targetinfo.cflags = _make_arrs(_get_flags_from_target(target, "cflags"), " ") @@ -524,7 +524,7 @@ function main(outputdir, vsinfo) _target.sdkver = targetinfo.sdkver _target.default = targetinfo.default - _target.dotnetframeworkver = vsinfo.dotnetframework_ver + _target.dotnetframeworkver = vsinfo.dotnetframework_version -- save all sourcefiles and headerfiles _target.sourcefiles = table.unique(table.join(_target.sourcefiles or {}, (target:sourcefiles()))) diff --git a/xmake/rules/csharp/xmake.lua b/xmake/rules/csharp/xmake.lua index f6cac3d3f9e..2bacc08dd25 100644 --- a/xmake/rules/csharp/xmake.lua +++ b/xmake/rules/csharp/xmake.lua @@ -29,10 +29,8 @@ rule("csharp.build") end) on_clean(function(target) - + end) - - on_link(function () end) rule("csharp") diff --git a/xmake/scripts/vsxmake/vsproj/templates/csproj/XmakeConfig(mode,arch) b/xmake/scripts/vsxmake/vsproj/templates/csproj/XmakeConfig(mode,arch) index f1281649cc4..17dc9ff279a 100644 --- a/xmake/scripts/vsxmake/vsproj/templates/csproj/XmakeConfig(mode,arch) +++ b/xmake/scripts/vsxmake/vsproj/templates/csproj/XmakeConfig(mode,arch) @@ -22,8 +22,4 @@ #includedirs# #linkdirs# #sourcedirs# - #pcheaderfile# - #cflags# - #cxflags# - #cxxflags# From cec4d81ddf3686d42f9531e18ff1f1bd03a1b4eb Mon Sep 17 00:00:00 2001 From: Kethers <838859010@qq.com> Date: Sun, 17 Dec 2023 15:28:29 +0800 Subject: [PATCH 09/12] Use sourcekind to differentiate project type --- xmake/plugins/project/vsxmake/getinfo.lua | 23 +++--- xmake/plugins/project/vsxmake/langtype.lua | 86 ---------------------- xmake/plugins/project/vsxmake/vsxmake.lua | 7 +- 3 files changed, 16 insertions(+), 100 deletions(-) delete mode 100644 xmake/plugins/project/vsxmake/langtype.lua diff --git a/xmake/plugins/project/vsxmake/getinfo.lua b/xmake/plugins/project/vsxmake/getinfo.lua index 3787070f6be..3070badb5ca 100644 --- a/xmake/plugins/project/vsxmake/getinfo.lua +++ b/xmake/plugins/project/vsxmake/getinfo.lua @@ -36,7 +36,6 @@ import("private.action.run.runenvs") import("private.action.require.install", {alias = "install_requires"}) import("actions.config.configfiles", {alias = "generate_configfiles", rootdir = os.programdir()}) import("vstudio.impl.vsutils", {rootdir = path.join(os.programdir(), "plugins", "project")}) -import("langtype") -- strip dot directories, e.g. ..\..\.. => .. -- @see https://github.com/xmake-io/xmake/issues/2039 @@ -497,18 +496,22 @@ function main(outputdir, vsinfo) local xxprojdir = _target.vcxprojdir local targetinfo = _make_targetinfo(mode, arch, target) - _target.languages = targetinfo.languages; _target.symbols = targetinfo.symbols; _target.optimize = targetinfo.optimize; _target.strip = targetinfo.strip; - if langtype.isc(_target.languages) or langtype.iscpp(_target.languages) then - _target.tool_id = "8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942" - _target.proj_extension = "vcxproj" - xxprojdir = _target.vcxprojdir - elseif langtype.iscsharp(_target.languages) then - _target.tool_id = "FAE04EC0-301F-11D3-BF4B-00C04F79EFBC" - _target.proj_extension = "csproj" - xxprojdir = _target.csprojdir + for _, sourcebatch in pairs(target:sourcebatches()) do + local sourcekind = sourcebatch.sourcekind + if sourcekind == "cc" or sourcekind == "cxx" then + _target.tool_id = "8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942" + _target.proj_extension = "vcxproj" + xxprojdir = _target.vcxprojdir + break + elseif sourcekind == "cs" then + _target.tool_id = "FAE04EC0-301F-11D3-BF4B-00C04F79EFBC" + _target.proj_extension = "csproj" + xxprojdir = _target.csprojdir + break + end end _target.target_id = hash.uuid4(targetname) diff --git a/xmake/plugins/project/vsxmake/langtype.lua b/xmake/plugins/project/vsxmake/langtype.lua deleted file mode 100644 index 18e99b08134..00000000000 --- a/xmake/plugins/project/vsxmake/langtype.lua +++ /dev/null @@ -1,86 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author Kethers --- @file langtype.lua --- - --- Copy from cl.lua -local _g = {} -_g.cxxmaps = -{ - cxx11 = "-std:c++11" -, gnuxx11 = "-std:c++11" -, cxx14 = "-std:c++14" -, gnuxx14 = "-std:c++14" -, cxx17 = "-std:c++17" -, gnuxx17 = "-std:c++17" -, cxx1z = "-std:c++17" -, gnuxx1z = "-std:c++17" -, cxx20 = {"-std:c++20", "-std:c++latest"} -, gnuxx20 = {"-std:c++20", "-std:c++latest"} -, cxx2a = {"-std:c++20", "-std:c++latest"} -, gnuxx2a = {"-std:c++20", "-std:c++latest"} -, cxx23 = {"-std:c++23", "-std:c++latest"} -, gnuxx23 = {"-std:c++23", "-std:c++latest"} -, cxx2b = {"-std:c++23", "-std:c++latest"} -, gnuxx2b = {"-std:c++23", "-std:c++latest"} -, cxxlatest = "-std:c++latest" -, gnuxxlatest = "-std:c++latest" -} - -_g.cmaps = -{ - -- stdc - c99 = "-TP" -- compile as c++ files because older msvc only support c89 -, gnu99 = "-TP" -, c11 = {"-std:c11", "-TP"} -, gnu11 = {"-std:c11", "-TP"} -, c17 = {"-std:c17", "-TP"} -, gnu17 = {"-std:c17", "-TP"} -, clatest = {"-std:c17", "-std:c11"} -, gnulatest = {"-std:c17", "-std:c11"} -} - -_g.csmaps = -{ - csharp = "-TP" -, -} - -function iscsharp(language) - if language and _g.csmaps[language] then - return true - end - - return false -end - -function isc(language) - if language and _g.cmaps[language] then - return true - end - - return false -end - -function iscpp(language) - if language and _g.cxxmaps[language] then - return true - end - - return false -end \ No newline at end of file diff --git a/xmake/plugins/project/vsxmake/vsxmake.lua b/xmake/plugins/project/vsxmake/vsxmake.lua index 0116ce834ec..fbfbdcc5d04 100644 --- a/xmake/plugins/project/vsxmake/vsxmake.lua +++ b/xmake/plugins/project/vsxmake/vsxmake.lua @@ -24,7 +24,6 @@ import("core.base.hashset") import("vstudio.impl.vsinfo", { rootdir = path.directory(os.scriptdir()) }) import("render") import("getinfo") -import("langtype") import("core.project.config") import("core.cache.localcache") @@ -240,8 +239,8 @@ function make(version) for _, target in ipairs(info.targets) do local paramsprovidertarget = _buildparams(info, target, "") local proj_dir; - local target_lang = info._targets[target].languages; - if langtype.isc(target_lang) or langtype.iscpp(target_lang) then + local proj_extension = info._targets[target].proj_extension; + if proj_extension == "vcxproj" then proj_dir = info._targets[target].vcxprojdir -- write project file @@ -250,7 +249,7 @@ function make(version) local projfil = path.join(proj_dir, target .. ".vcxproj.filters") _writefileifneeded(projfil, render(template_fil, "#([A-Za-z0-9_,%.%*%(%)]+)#", "@([^@]+)@", paramsprovidertarget)) - elseif langtype.iscsharp(target_lang) then + elseif proj_extension == "csproj" then proj_dir = info._targets[target].csprojdir local proj = path.join(proj_dir, target .. ".csproj") From eddd355c65282e11617d2c756c5842f1080775ec Mon Sep 17 00:00:00 2001 From: ruki Date: Sun, 17 Dec 2023 21:24:24 +0800 Subject: [PATCH 10/12] Update load.lua --- xmake/languages/csharp/load.lua | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/xmake/languages/csharp/load.lua b/xmake/languages/csharp/load.lua index 7b7e2e95a73..2579dce88fe 100644 --- a/xmake/languages/csharp/load.lua +++ b/xmake/languages/csharp/load.lua @@ -34,17 +34,8 @@ function _get_apis() , "target.add_rpathdirs" -- @note do not translate path, it's usually an absolute path or contains $ORIGIN/@loader_path , "target.add_forceincludes" -- option.add_xxx - , "option.add_cincludes" - , "option.add_cxxincludes" - , "option.add_cfuncs" - , "option.add_cxxfuncs" - , "option.add_ctypes" - , "option.add_cxxtypes" , "option.add_links" , "option.add_syslinks" - , "option.add_cflags" - , "option.add_cxflags" - , "option.add_cxxflags" , "option.add_ldflags" , "option.add_arflags" , "option.add_shflags" @@ -91,9 +82,6 @@ function _get_apis() , "option.add_sysincludedirs" , "option.add_frameworkdirs" } - apis.dictionary = { - -- option.add_xxx - } return apis end From 6e17c8214790ae73c4608e36dd24b8840ac22059 Mon Sep 17 00:00:00 2001 From: Kethers <49612587+Kethers@users.noreply.github.com> Date: Fri, 29 Dec 2023 17:51:38 +0800 Subject: [PATCH 11/12] Initially add C# support for VS proj generator --- xmake/plugins/project/vstudio/impl/vs200x.lua | 14 +- .../project/vstudio/impl/vs200x_solution.lua | 22 +- xmake/plugins/project/vstudio/impl/vs201x.lua | 17 +- .../project/vstudio/impl/vs201x_solution.lua | 18 +- .../project/vstudio/impl/vs_csproj.lua | 214 ++++++++++++++++++ .../vsproj/templates/csproj/#target#.csproj | 2 +- .../vsproj/templates/csproj/ProjectRef(dep) | 2 +- .../vsproj/templates/vcxproj/ProjectRef(dep) | 2 +- 8 files changed, 276 insertions(+), 15 deletions(-) create mode 100644 xmake/plugins/project/vstudio/impl/vs_csproj.lua diff --git a/xmake/plugins/project/vstudio/impl/vs200x.lua b/xmake/plugins/project/vstudio/impl/vs200x.lua index d1f220c8aac..409d73a4930 100644 --- a/xmake/plugins/project/vstudio/impl/vs200x.lua +++ b/xmake/plugins/project/vstudio/impl/vs200x.lua @@ -22,6 +22,7 @@ import("core.project.project") import("vs200x_solution") import("vs200x_vcproj") +import("vs_csproj") -- make vstudio project function make(outputdir, vsinfo) @@ -44,8 +45,17 @@ function make(outputdir, vsinfo) -- make vsprojs for _, target in pairs(project.targets()) do - if not target:is_phony() then - vs200x_vcproj.make(vsinfo, target) + for _, sourcebatch in pairs(target:sourcebatches()) do + local sourcekind = sourcebatch.sourcekind + if sourcekind == "cc" or sourcekind == "cxx" then + if not target:is_phony() then + vs200x_vcproj.make(vsinfo, target) + end + break + elseif sourcekind == "cs" then + vs_csproj.make(vsinfo, target) + break + end end end diff --git a/xmake/plugins/project/vstudio/impl/vs200x_solution.lua b/xmake/plugins/project/vstudio/impl/vs200x_solution.lua index 48b10445f57..b0a0987979f 100644 --- a/xmake/plugins/project/vstudio/impl/vs200x_solution.lua +++ b/xmake/plugins/project/vstudio/impl/vs200x_solution.lua @@ -31,15 +31,29 @@ end -- make projects function _make_projects(slnfile, vsinfo) - -- the vstudio tool uuid for vc project - local vctool = "8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942" - -- make all targets for targetname, target in pairs(project.targets()) do + + tool_id = "" -- the vstudio tool uuid for project + proj_extension = "" + + for _, sourcebatch in pairs(target:sourcebatches()) do + local sourcekind = sourcebatch.sourcekind + if sourcekind == "cc" or sourcekind == "cxx" then + tool_id = "8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942" + proj_extension = "vcxproj" + break + elseif sourcekind == "cs" then + tool_id = "FAE04EC0-301F-11D3-BF4B-00C04F79EFBC" + proj_extension = "csproj" + break + end + end + if not target:is_phony() then -- enter project - slnfile:enter("Project(\"{%s}\") = \"%s\", \"%s\\%s.vcproj\", \"{%s}\"", vctool, targetname, targetname, targetname, hash.uuid4(targetname)) + slnfile:enter("Project(\"{%s}\") = \"%s\", \"%s\\%s.%s\", \"{%s}\"", tool_id, targetname, targetname, targetname, proj_extension, hash.uuid4(targetname)) -- add dependences for _, dep in ipairs(target:get("deps")) do diff --git a/xmake/plugins/project/vstudio/impl/vs201x.lua b/xmake/plugins/project/vstudio/impl/vs201x.lua index a8b48dada5f..0d071270010 100644 --- a/xmake/plugins/project/vstudio/impl/vs201x.lua +++ b/xmake/plugins/project/vstudio/impl/vs201x.lua @@ -32,6 +32,7 @@ import("core.tool.toolchain") import("vs201x_solution") import("vs201x_vcxproj") import("vs201x_vcxproj_filters") +import("vs_csproj") import("vsutils") import("core.cache.memcache") import("core.cache.localcache") @@ -288,7 +289,7 @@ function _make_targetinfo(mode, arch, target, vcxprojdir) for _, sourcebatch in table.orderpairs(sourcebatches) do local sourcekind = sourcebatch.sourcekind local rulename = sourcebatch.rulename - if sourcekind then + if sourcekind and sourcekind ~= "cs" then -- TODO: temp, delete it when cs flags are done for idx, sourcefile in ipairs(sourcebatch.sourcefiles) do local compflags = compiler.compflags(sourcefile, {target = target, sourcekind = sourcekind}) if not firstcompflags and (rulename == "c.build" or rulename == "c++.build" or rulename == "cuda.build") then @@ -567,10 +568,18 @@ function make(outputdir, vsinfo) -- make solution vs201x_solution.make(vsinfo) - -- make .vcxproj + -- make .vcxproj and .csproj for _, target in table.orderpairs(targets) do - vs201x_vcxproj.make(vsinfo, target) - vs201x_vcxproj_filters.make(vsinfo, target) + for _, targetinfo in ipairs(target.info) do + if targetinfo.sourcekinds and table.contains(targetinfo.sourcekinds, "cc", "cxx") then + vs201x_vcxproj.make(vsinfo, target) + vs201x_vcxproj_filters.make(vsinfo, target) + break + elseif targetinfo.sourcekinds and table.contains(targetinfo.sourcekinds, "cs") then + vs_csproj.make(vsinfo, target) + break + end + end end -- clear local cache diff --git a/xmake/plugins/project/vstudio/impl/vs201x_solution.lua b/xmake/plugins/project/vstudio/impl/vs201x_solution.lua index 82ede489a75..4f8b5d14360 100644 --- a/xmake/plugins/project/vstudio/impl/vs201x_solution.lua +++ b/xmake/plugins/project/vstudio/impl/vs201x_solution.lua @@ -35,7 +35,6 @@ function _make_projects(slnfile, vsinfo) -- make all targets local groups = {} local targets = {} - local vctool = "8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942" for targetname, target in table.orderpairs(project.targets()) do -- we need to set startup project for default or binary target -- @see https://github.com/xmake-io/xmake/issues/1249 @@ -53,8 +52,23 @@ function _make_projects(slnfile, vsinfo) end end for _, target in ipairs(targets) do + tool_id = "" + proj_extension = "" + for _, sourcebatch in pairs(target:sourcebatches()) do + local sourcekind = sourcebatch.sourcekind + if sourcekind == "cc" or sourcekind == "cxx" then + tool_id = "8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942" + proj_extension = "vcxproj" + break + elseif sourcekind == "cs" then + tool_id = "FAE04EC0-301F-11D3-BF4B-00C04F79EFBC" + proj_extension = "csproj" + break + end + end + local targetname = target:name() - slnfile:enter("Project(\"{%s}\") = \"%s\", \"%s\\%s.vcxproj\", \"{%s}\"", vctool, targetname, targetname, targetname, hash.uuid4(targetname)) + slnfile:enter("Project(\"{%s}\") = \"%s\", \"%s\\%s.%s\", \"{%s}\"", tool_id, targetname, targetname, targetname, proj_extension, hash.uuid4(targetname)) for _, dep in ipairs(target:get("deps")) do slnfile:enter("ProjectSection(ProjectDependencies) = postProject") slnfile:print("{%s} = {%s}", hash.uuid4(dep), hash.uuid4(dep)) diff --git a/xmake/plugins/project/vstudio/impl/vs_csproj.lua b/xmake/plugins/project/vstudio/impl/vs_csproj.lua new file mode 100644 index 00000000000..cff20ca687d --- /dev/null +++ b/xmake/plugins/project/vstudio/impl/vs_csproj.lua @@ -0,0 +1,214 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author Kethers +-- @file vs_csproj.lua +-- + +-- imports +import("core.base.option") +import("core.base.hashset") +import("core.project.rule") +import("core.project.config") +import("core.project.project") +import("core.language.language") +import("core.tool.toolchain") +import("private.utils.batchcmds") +import("vsfile") +import("vsutils") +import("plugins.project.vsxmake.getinfo", {rootdir = os.programdir()}) + + +function _make_dirs(dir, csprojdir) + dir = dir:trim() + if #dir == 0 then + return "" + end + dir = path.translate(dir) + if not path.is_absolute(dir) then + dir = path.relative(path.absolute(dir), csprojdir) + end + return dir +end + +-- make header +function _make_header(csprojfile, vsinfo) + csprojfile:print("") + csprojfile:enter("", assert(vsinfo.project_version)) +end + +function _make_configurations(csprojfile, vsinfo, target) + -- the target name + local targetname = target.name + + -- init configuration type + local output_types = + { + binary = "Exe" + -- , winexe = "WinExe" TODO: this kind doesn't exist yet + , shared = "Library" + } + + -- import Microsoft.Common.props + csprojfile:print("") + + -- make Globals + csprojfile:enter("") + csprojfile:print("debug") + csprojfile:print("x64") + csprojfile:print("{%s}", hash.uuid4(targetname)) + csprojfile:print("%s", output_types[target.kind] or "Unknown") + csprojfile:print("Properties") + csprojfile:print("%s", targetname) + csprojfile:print("%s", targetname) + csprojfile:print("v%s", vsinfo.dotnetframework_version) + csprojfile:print("512") + csprojfile:print("true") + csprojfile:leave("") + + -- make Configuration + for _, targetinfo in ipairs(target.info) do + local mode = targetinfo.mode + local arch = targetinfo.arch + + symbols = vsinfo._targets[targetname]._targets[mode][arch].symbols or "" + optimize = vsinfo._targets[targetname]._targets[mode][arch].optimize or "" + + debugtype = "portable" + debugsymbols = "true" + if (symbols == "debug") then + debugtype = "full" + debugsymbols = "true" + elseif (symbols == "hidden") then + debugtype = "none" + debugsymbols = "false" + elseif (string.find(symbols, "debug") and string.find(symbols, "embed")) then + debugtype = "embedded" + debugsymbols = "true" + end + + if optimize == "" or optimize == "none" then + optimize = "false" + else + optimize = "true" + end + + csprojfile:enter("", mode, arch) + csprojfile:print("%s", debugtype) + csprojfile:print("%s", debugsymbols) + csprojfile:print("%s", optimize) + csprojfile:print("%s", _make_dirs(targetinfo.targetdir, target.project_dir)) + csprojfile:print("%s", _make_dirs(targetinfo.objectdir, target.project_dir)) + csprojfile:print("%$(BaseIntermediateOutputPath)") + csprojfile:print("%s", vsinfo._targets[targetname]._targets[mode][arch].defines) + csprojfile:print("prompt") + csprojfile:print("4") + csprojfile:leave("") + end +end + +-- make source files +function _make_source_files(csprojfile, vsinfo, target) + -- make source file infos + local sourceinfos = {} + for _, targetinfo in ipairs(target.info) do + for _, sourcebatch in pairs(targetinfo.sourcebatches) do + local sourcekind = sourcebatch.sourcekind + local rulename = sourcebatch.rulename + if (sourcekind == "cs") then + local objectfiles = sourcebatch.objectfiles + for idx, sourcefile in ipairs(sourcebatch.sourcefiles) do + local objectfile = objectfiles[idx] + -- local flags = targetinfo.sourceflags[sourcefile] -- TODO: cs flags doesn't exist yet + sourceinfos[sourcefile] = sourceinfos[sourcefile] or {} + table.insert(sourceinfos[sourcefile], {targetinfo = targetinfo, mode = targetinfo.mode, arch = targetinfo.arch, sourcekind = sourcekind, objectfile = objectfile, flags = flags, compargv = targetinfo.compargvs[sourcefile]}) + end + end + end + end + + -- make source files + csprojfile:enter("") + for sourcefile, sourceinfo in table.orderpairs(sourceinfos) do + if #sourceinfo == #target.info then + csprojfile:print("", path.relative(path.absolute(sourcefile), target.project_dir)) + end + end + csprojfile:leave("") +end + +-- make project references +function _make_project_references(csprojfile, vsinfo, target) + local deps = vsinfo._targets[target.name]._deps + + csprojfile:enter("") + + for depname, dep in table.orderpairs(deps) do + proj_extension = dep.proj_extension + csprojfile:enter(" ", depname, depname, proj_extension) + csprojfile:print("{%s}", dep.target_id) + csprojfile:print("%s", depname) + csprojfile:leave("") + end + + csprojfile:leave("") +end + +-- make tailer +function _make_tailer(csprojfile, vsinfo, target) + -- import Microsoft.CSharp.targets + csprojfile:print("") + + csprojfile:leave("") +end + +-- make csproj +function make(vsinfo, target) + + -- TODO: getinfo will leads to repeat MSVC checking output, try not to use it + local info = getinfo(option.get("outputdir"), vsinfo) + + -- the target name + local targetname = target.name + + -- the csproj directory + local csprojdir = target.project_dir + + -- open csproj file + local csprojpath = path.join(csprojdir, targetname .. ".csproj") + local csprojfile = vsfile.open(csprojpath, "w") + + -- init indent character + vsfile.indentchar(' ') + + -- make headers + _make_header(csprojfile, info) + + -- make Configurations + _make_configurations(csprojfile, info, target) + + -- make source files + _make_source_files(csprojfile, info, target) + + -- make project references + _make_project_references(csprojfile, info, target) + + -- make tailer + _make_tailer(csprojfile, info, target) + + -- exit solution file + csprojfile:close() +end \ No newline at end of file diff --git a/xmake/scripts/vsxmake/vsproj/templates/csproj/#target#.csproj b/xmake/scripts/vsxmake/vsproj/templates/csproj/#target#.csproj index 6c85432b633..cf4a87b85c0 100644 --- a/xmake/scripts/vsxmake/vsproj/templates/csproj/#target#.csproj +++ b/xmake/scripts/vsxmake/vsproj/templates/csproj/#target#.csproj @@ -10,7 +10,7 @@ See https://github.com/xmake-io/xmake/pull/472 for more infomation. --> - + $(XMAKE_PROGRAM_DIR) #programdir# diff --git a/xmake/scripts/vsxmake/vsproj/templates/csproj/ProjectRef(dep) b/xmake/scripts/vsxmake/vsproj/templates/csproj/ProjectRef(dep) index dfccc2095bd..52deb3110b7 100644 --- a/xmake/scripts/vsxmake/vsproj/templates/csproj/ProjectRef(dep) +++ b/xmake/scripts/vsxmake/vsproj/templates/csproj/ProjectRef(dep) @@ -1,4 +1,4 @@ {#target_id#} - {#target#} + #target# diff --git a/xmake/scripts/vsxmake/vsproj/templates/vcxproj/ProjectRef(dep) b/xmake/scripts/vsxmake/vsproj/templates/vcxproj/ProjectRef(dep) index dfccc2095bd..52deb3110b7 100644 --- a/xmake/scripts/vsxmake/vsproj/templates/vcxproj/ProjectRef(dep) +++ b/xmake/scripts/vsxmake/vsproj/templates/vcxproj/ProjectRef(dep) @@ -1,4 +1,4 @@ {#target_id#} - {#target#} + #target# From c5f852316bc1cb59bea1e67dfff0c7b4570621d8 Mon Sep 17 00:00:00 2001 From: Kethers <49612587+Kethers@users.noreply.github.com> Date: Sat, 30 Dec 2023 00:34:15 +0800 Subject: [PATCH 12/12] Remove getinfo in vs201x_csproj.lua, revert vs200x relevant files --- xmake/plugins/project/vstudio/impl/vs200x.lua | 14 +--- .../project/vstudio/impl/vs200x_solution.lua | 22 ++---- xmake/plugins/project/vstudio/impl/vs201x.lua | 72 +++++++++++++++---- .../impl/{vs_csproj.lua => vs201x_csproj.lua} | 33 ++++----- 4 files changed, 80 insertions(+), 61 deletions(-) rename xmake/plugins/project/vstudio/impl/{vs_csproj.lua => vs201x_csproj.lua} (88%) diff --git a/xmake/plugins/project/vstudio/impl/vs200x.lua b/xmake/plugins/project/vstudio/impl/vs200x.lua index 409d73a4930..d1f220c8aac 100644 --- a/xmake/plugins/project/vstudio/impl/vs200x.lua +++ b/xmake/plugins/project/vstudio/impl/vs200x.lua @@ -22,7 +22,6 @@ import("core.project.project") import("vs200x_solution") import("vs200x_vcproj") -import("vs_csproj") -- make vstudio project function make(outputdir, vsinfo) @@ -45,17 +44,8 @@ function make(outputdir, vsinfo) -- make vsprojs for _, target in pairs(project.targets()) do - for _, sourcebatch in pairs(target:sourcebatches()) do - local sourcekind = sourcebatch.sourcekind - if sourcekind == "cc" or sourcekind == "cxx" then - if not target:is_phony() then - vs200x_vcproj.make(vsinfo, target) - end - break - elseif sourcekind == "cs" then - vs_csproj.make(vsinfo, target) - break - end + if not target:is_phony() then + vs200x_vcproj.make(vsinfo, target) end end diff --git a/xmake/plugins/project/vstudio/impl/vs200x_solution.lua b/xmake/plugins/project/vstudio/impl/vs200x_solution.lua index b0a0987979f..48b10445f57 100644 --- a/xmake/plugins/project/vstudio/impl/vs200x_solution.lua +++ b/xmake/plugins/project/vstudio/impl/vs200x_solution.lua @@ -31,29 +31,15 @@ end -- make projects function _make_projects(slnfile, vsinfo) + -- the vstudio tool uuid for vc project + local vctool = "8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942" + -- make all targets for targetname, target in pairs(project.targets()) do - - tool_id = "" -- the vstudio tool uuid for project - proj_extension = "" - - for _, sourcebatch in pairs(target:sourcebatches()) do - local sourcekind = sourcebatch.sourcekind - if sourcekind == "cc" or sourcekind == "cxx" then - tool_id = "8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942" - proj_extension = "vcxproj" - break - elseif sourcekind == "cs" then - tool_id = "FAE04EC0-301F-11D3-BF4B-00C04F79EFBC" - proj_extension = "csproj" - break - end - end - if not target:is_phony() then -- enter project - slnfile:enter("Project(\"{%s}\") = \"%s\", \"%s\\%s.%s\", \"{%s}\"", tool_id, targetname, targetname, targetname, proj_extension, hash.uuid4(targetname)) + slnfile:enter("Project(\"{%s}\") = \"%s\", \"%s\\%s.vcproj\", \"{%s}\"", vctool, targetname, targetname, targetname, hash.uuid4(targetname)) -- add dependences for _, dep in ipairs(target:get("deps")) do diff --git a/xmake/plugins/project/vstudio/impl/vs201x.lua b/xmake/plugins/project/vstudio/impl/vs201x.lua index 0d071270010..a8f89e08fe7 100644 --- a/xmake/plugins/project/vstudio/impl/vs201x.lua +++ b/xmake/plugins/project/vstudio/impl/vs201x.lua @@ -32,7 +32,7 @@ import("core.tool.toolchain") import("vs201x_solution") import("vs201x_vcxproj") import("vs201x_vcxproj_filters") -import("vs_csproj") +import("vs201x_csproj") import("vsutils") import("core.cache.memcache") import("core.cache.localcache") @@ -80,6 +80,30 @@ function _clear_cache() localcache.save() end +function _make_arrs(arr, sep) + if arr == nil then + return "" + end + if type(arr) == "string" then + return vsutils.escape(arr) + end + local r = {} + for k, v in ipairs(arr) do + r[k] = _make_arrs(v, sep) + end + r = table.unique(r) + return table.concat(r, sep or ";") +end + +-- get values from target +function _get_values_from_target(target, name) + local values = {} + for _, value in ipairs((target:get_from(name, "*"))) do + table.join2(values, value) + end + return table.unique(values) +end + -- get command string function _get_command_string(cmd, vcxprojdir) local kind = cmd.kind @@ -254,8 +278,13 @@ function _make_targetinfo(mode, arch, target, vcxprojdir) -- save languages targetinfo.languages = table.wrap(target:get("languages")) - -- save symbols - targetinfo.symbols = target:get("symbols") + -- save defines + targetinfo.defines = _make_arrs(_get_values_from_target(target, "defines")) + + -- save symbols, optimize, strip info + targetinfo.symbols = target:get("symbols") + targetinfo.optimize = target:get("optimize") + targetinfo.strip = target:get("strip") -- save target kind targetinfo.targetkind = target:kind() @@ -532,11 +561,24 @@ function make(outputdir, vsinfo) _target.info = _target.info or {} table.insert(_target.info, _make_targetinfo(mode, arch, target, _target.project_dir)) + for _, sourcebatch in pairs(target:sourcebatches()) do + local sourcekind = sourcebatch.sourcekind + if sourcekind == "cc" or sourcekind == "cxx" then + _target.proj_extension = "vcxproj" + break + elseif sourcekind == "cs" then + _target.proj_extension = "csproj" + break + end + end + -- 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.extrafiles = table.unique(table.join(_target.extrafiles or {}, (target:extrafiles()))) + _target.deps = table.unique(table.join(_target.deps or {}, table.orderkeys(target:deps()), nil)) + -- sort them to stabilize generation table.sort(_target.sourcefiles) table.sort(_target.headerfiles) @@ -565,20 +607,26 @@ function make(outputdir, vsinfo) end end + -- make [deptargetname, deptarget] pairs (_deps) + for _, target in table.orderpairs(targets) do + target._deps = {} + for _, v in ipairs(target.deps) do + target._deps[v] = targets[v] + end + end + -- make solution vs201x_solution.make(vsinfo) -- make .vcxproj and .csproj for _, target in table.orderpairs(targets) do - for _, targetinfo in ipairs(target.info) do - if targetinfo.sourcekinds and table.contains(targetinfo.sourcekinds, "cc", "cxx") then - vs201x_vcxproj.make(vsinfo, target) - vs201x_vcxproj_filters.make(vsinfo, target) - break - elseif targetinfo.sourcekinds and table.contains(targetinfo.sourcekinds, "cs") then - vs_csproj.make(vsinfo, target) - break - end + if target.proj_extension == "vcxproj" then + vs201x_vcxproj.make(vsinfo, target) + vs201x_vcxproj_filters.make(vsinfo, target) + break + elseif target.proj_extension == "csproj" then + vs201x_csproj.make(vsinfo, target) + break end end diff --git a/xmake/plugins/project/vstudio/impl/vs_csproj.lua b/xmake/plugins/project/vstudio/impl/vs201x_csproj.lua similarity index 88% rename from xmake/plugins/project/vstudio/impl/vs_csproj.lua rename to xmake/plugins/project/vstudio/impl/vs201x_csproj.lua index cff20ca687d..2fcb6a55663 100644 --- a/xmake/plugins/project/vstudio/impl/vs_csproj.lua +++ b/xmake/plugins/project/vstudio/impl/vs201x_csproj.lua @@ -15,7 +15,7 @@ -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author Kethers --- @file vs_csproj.lua +-- @file vs201x_csproj.lua -- -- imports @@ -84,8 +84,8 @@ function _make_configurations(csprojfile, vsinfo, target) local mode = targetinfo.mode local arch = targetinfo.arch - symbols = vsinfo._targets[targetname]._targets[mode][arch].symbols or "" - optimize = vsinfo._targets[targetname]._targets[mode][arch].optimize or "" + symbols = targetinfo.symbols or "" + optimize = targetinfo.optimize or "" debugtype = "portable" debugsymbols = "true" @@ -113,7 +113,7 @@ function _make_configurations(csprojfile, vsinfo, target) csprojfile:print("%s", _make_dirs(targetinfo.targetdir, target.project_dir)) csprojfile:print("%s", _make_dirs(targetinfo.objectdir, target.project_dir)) csprojfile:print("%$(BaseIntermediateOutputPath)") - csprojfile:print("%s", vsinfo._targets[targetname]._targets[mode][arch].defines) + csprojfile:print("%s", targetinfo.defines) csprojfile:print("prompt") csprojfile:print("4") csprojfile:leave("") @@ -152,15 +152,13 @@ end -- make project references function _make_project_references(csprojfile, vsinfo, target) - local deps = vsinfo._targets[target.name]._deps - csprojfile:enter("") - for depname, dep in table.orderpairs(deps) do - proj_extension = dep.proj_extension - csprojfile:enter(" ", depname, depname, proj_extension) - csprojfile:print("{%s}", dep.target_id) - csprojfile:print("%s", depname) + for deptargetname, deptarget in table.orderpairs(target._deps) do + proj_extension = deptarget.proj_extension or "" + csprojfile:enter(" ", deptargetname, deptargetname, proj_extension) + csprojfile:print("{%s}", hash.uuid4(deptargetname)) + csprojfile:print("%s", deptargetname) csprojfile:leave("") end @@ -178,9 +176,6 @@ end -- make csproj function make(vsinfo, target) - -- TODO: getinfo will leads to repeat MSVC checking output, try not to use it - local info = getinfo(option.get("outputdir"), vsinfo) - -- the target name local targetname = target.name @@ -195,19 +190,19 @@ function make(vsinfo, target) vsfile.indentchar(' ') -- make headers - _make_header(csprojfile, info) + _make_header(csprojfile, vsinfo) -- make Configurations - _make_configurations(csprojfile, info, target) + _make_configurations(csprojfile, vsinfo, target) -- make source files - _make_source_files(csprojfile, info, target) + _make_source_files(csprojfile, vsinfo, target) -- make project references - _make_project_references(csprojfile, info, target) + _make_project_references(csprojfile, vsinfo, target) -- make tailer - _make_tailer(csprojfile, info, target) + _make_tailer(csprojfile, vsinfo, target) -- exit solution file csprojfile:close()