From b975efbeb8091ee9e6ff10bd3a55a58cde80ff7c Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 3 Jun 2025 00:41:00 +0800 Subject: add multiversion vsxmake policy #6519 --- xmake/core/project/policy.lua | 4 +++- xmake/plugins/project/vsxmake/getinfo.lua | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/xmake/core/project/policy.lua b/xmake/core/project/policy.lua index 0c79be649..d6f0a063d 100644 --- a/xmake/core/project/policy.lua +++ b/xmake/core/project/policy.lua @@ -178,7 +178,9 @@ function policy.policies() -- private: it will disable fetch remote package repositories ["network.mode"] = {description = "Set the network mode", type = "string"}, -- Set the compatibility version, e.g. 2.0, 3.0 - ["compatibility.version"] = {description = "Set the compatibility version", type = "string", default = "3.0", values = {"2.0", "3.0"}} + ["compatibility.version"] = {description = "Set the compatibility version", type = "string", default = "3.0", values = {"2.0", "3.0"}, + -- Enable or disable multiverison solution output + ["generator.vsxmake.multiversion"] = {description = "Enable or disable multiverison solution output", default = true, type = "boolean"}} } policy._POLICIES = policies end diff --git a/xmake/plugins/project/vsxmake/getinfo.lua b/xmake/plugins/project/vsxmake/getinfo.lua index ae69fbb58..f8871af24 100644 --- a/xmake/plugins/project/vsxmake/getinfo.lua +++ b/xmake/plugins/project/vsxmake/getinfo.lua @@ -393,7 +393,11 @@ function main(outputdir, vsinfo) local oldir = os.cd(project.directory()) -- init solution directory - vsinfo.solution_dir = path.absolute(path.join(outputdir, "vsxmake" .. vsinfo.vstudio_version)) + if project.policy("generator.vsxmake.multiversion") then + vsinfo.solution_dir = path.absolute(path.join(outputdir, "vsxmake" .. vsinfo.vstudio_version)) + else + vsinfo.solution_dir = path.absolute(outputdir) + end vsinfo.programdir = _make_dirs(xmake.programdir()) vsinfo.programfile = xmake.programfile() vsinfo.projectdir = project.directory() -- cgit v1.3.1 From b51ce4ebec27a4ca3b10f29eb4bbfe3024c5f9fd Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 3 Jun 2025 00:43:18 +0800 Subject: fix error --- xmake/core/project/policy.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xmake/core/project/policy.lua b/xmake/core/project/policy.lua index d6f0a063d..010ae61cf 100644 --- a/xmake/core/project/policy.lua +++ b/xmake/core/project/policy.lua @@ -178,9 +178,9 @@ function policy.policies() -- private: it will disable fetch remote package repositories ["network.mode"] = {description = "Set the network mode", type = "string"}, -- Set the compatibility version, e.g. 2.0, 3.0 - ["compatibility.version"] = {description = "Set the compatibility version", type = "string", default = "3.0", values = {"2.0", "3.0"}, + ["compatibility.version"] = {description = "Set the compatibility version", type = "string", default = "3.0", values = {"2.0", "3.0"}}, -- Enable or disable multiverison solution output - ["generator.vsxmake.multiversion"] = {description = "Enable or disable multiverison solution output", default = true, type = "boolean"}} + ["generator.vsxmake.multiversion"] = {description = "Enable or disable multiverison solution output", default = true, type = "boolean"} } policy._POLICIES = policies end -- cgit v1.3.1 From 618f7752fd27fd65fa6ceece235e4aaf32c499d1 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 3 Jun 2025 23:49:24 +0800 Subject: modify policy --- xmake/core/project/policy.lua | 4 ++-- xmake/plugins/project/vsxmake/getinfo.lua | 9 +++++---- xmake/plugins/project/vsxmake/vsxmake.lua | 4 ++-- xmake/scripts/vsxmake/vsproj/templates/sln/Project(target) | 2 +- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/xmake/core/project/policy.lua b/xmake/core/project/policy.lua index 010ae61cf..948674159 100644 --- a/xmake/core/project/policy.lua +++ b/xmake/core/project/policy.lua @@ -179,8 +179,8 @@ function policy.policies() ["network.mode"] = {description = "Set the network mode", type = "string"}, -- Set the compatibility version, e.g. 2.0, 3.0 ["compatibility.version"] = {description = "Set the compatibility version", type = "string", default = "3.0", values = {"2.0", "3.0"}}, - -- Enable or disable multiverison solution output - ["generator.vsxmake.multiversion"] = {description = "Enable or disable multiverison solution output", default = true, type = "boolean"} + -- Generate the solution file in root output directory + ["generator.vsxmake.root_sln"] = {description = "Generate the solution file in root output directory", default = false, type = "boolean"} } policy._POLICIES = policies end diff --git a/xmake/plugins/project/vsxmake/getinfo.lua b/xmake/plugins/project/vsxmake/getinfo.lua index f8871af24..09c12ce0e 100644 --- a/xmake/plugins/project/vsxmake/getinfo.lua +++ b/xmake/plugins/project/vsxmake/getinfo.lua @@ -393,10 +393,11 @@ function main(outputdir, vsinfo) local oldir = os.cd(project.directory()) -- init solution directory - if project.policy("generator.vsxmake.multiversion") then - vsinfo.solution_dir = path.absolute(path.join(outputdir, "vsxmake" .. vsinfo.vstudio_version)) - else + vsinfo.vcxproj_rootdir = path.absolute(path.join(outputdir, "vsxmake" .. vsinfo.vstudio_version)) + if project.policy("generator.vsxmake.root_sln") then vsinfo.solution_dir = path.absolute(outputdir) + else + vsinfo.solution_dir = vsinfo.vcxproj_rootdir end vsinfo.programdir = _make_dirs(xmake.programdir()) vsinfo.programfile = xmake.programfile() @@ -495,7 +496,7 @@ function main(outputdir, vsinfo) -- init target info _target.target = targetname - _target.vcxprojdir = path.join(vsinfo.solution_dir, targetname) + _target.vcxprojdir = path.join(vsinfo.vcxproj_rootdir, targetname) _target.target_id = hash.uuid4(targetname) _target.kind = target:kind() _target.absscriptdir = target:scriptdir() diff --git a/xmake/plugins/project/vsxmake/vsxmake.lua b/xmake/plugins/project/vsxmake/vsxmake.lua index 2b3ded5d6..d5cd5e078 100644 --- a/xmake/plugins/project/vsxmake/vsxmake.lua +++ b/xmake/plugins/project/vsxmake/vsxmake.lua @@ -235,8 +235,8 @@ function make(version) _writefileifneeded(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) + _trycp(template_props, info.vcxproj_rootdir) + _trycp(template_targets, info.vcxproj_rootdir) for _, target in ipairs(info.targets) do local paramsprovidertarget = _buildparams(info, target, "") diff --git a/xmake/scripts/vsxmake/vsproj/templates/sln/Project(target) b/xmake/scripts/vsxmake/vsproj/templates/sln/Project(target) index 11e743c8a..69071bd68 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("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "#target#", "#vcxprojdir#\#target#.vcxproj", "{#target_id#}" EndProject -- cgit v1.3.1 From 113b866ec72198a84b81611f1d17bf7c351459b9 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 3 Jun 2025 23:49:40 +0800 Subject: update comments --- xmake/core/project/policy.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/xmake/core/project/policy.lua b/xmake/core/project/policy.lua index 948674159..361ed059d 100644 --- a/xmake/core/project/policy.lua +++ b/xmake/core/project/policy.lua @@ -180,6 +180,7 @@ function policy.policies() -- Set the compatibility version, e.g. 2.0, 3.0 ["compatibility.version"] = {description = "Set the compatibility version", type = "string", default = "3.0", values = {"2.0", "3.0"}}, -- Generate the solution file in root output directory + -- @see https://github.com/xmake-io/xmake/issues/6519 ["generator.vsxmake.root_sln"] = {description = "Generate the solution file in root output directory", default = false, type = "boolean"} } policy._POLICIES = policies -- cgit v1.3.1 From 57c4e3b1c16bbf59b3e7d9787768f20894d00437 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 3 Jun 2025 23:51:31 +0800 Subject: improve path --- xmake/plugins/project/vsxmake/getinfo.lua | 1 + xmake/scripts/vsxmake/vsproj/templates/sln/Project(target) | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/xmake/plugins/project/vsxmake/getinfo.lua b/xmake/plugins/project/vsxmake/getinfo.lua index 09c12ce0e..7108c57a9 100644 --- a/xmake/plugins/project/vsxmake/getinfo.lua +++ b/xmake/plugins/project/vsxmake/getinfo.lua @@ -497,6 +497,7 @@ function main(outputdir, vsinfo) -- init target info _target.target = targetname _target.vcxprojdir = path.join(vsinfo.vcxproj_rootdir, targetname) + _target.vcxprojdir_relative_sln = path.join(_target.vcxprojdir, vsinfo.solution_dir) _target.target_id = hash.uuid4(targetname) _target.kind = target:kind() _target.absscriptdir = target:scriptdir() diff --git a/xmake/scripts/vsxmake/vsproj/templates/sln/Project(target) b/xmake/scripts/vsxmake/vsproj/templates/sln/Project(target) index 69071bd68..87d435af2 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#", "#vcxprojdir#\#target#.vcxproj", "{#target_id#}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "#target#", "#vcxprojdir_relative_sln#\#target#.vcxproj", "{#target_id#}" EndProject -- cgit v1.3.1 From 08b1b83e2ea26ff9cba52df62ec6e41376f9177e Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 3 Jun 2025 23:51:48 +0800 Subject: fix path --- xmake/plugins/project/vsxmake/getinfo.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xmake/plugins/project/vsxmake/getinfo.lua b/xmake/plugins/project/vsxmake/getinfo.lua index 7108c57a9..d9c4b4b6b 100644 --- a/xmake/plugins/project/vsxmake/getinfo.lua +++ b/xmake/plugins/project/vsxmake/getinfo.lua @@ -497,7 +497,7 @@ function main(outputdir, vsinfo) -- init target info _target.target = targetname _target.vcxprojdir = path.join(vsinfo.vcxproj_rootdir, targetname) - _target.vcxprojdir_relative_sln = path.join(_target.vcxprojdir, vsinfo.solution_dir) + _target.vcxprojdir_relative_sln = path.relative(_target.vcxprojdir, vsinfo.solution_dir) _target.target_id = hash.uuid4(targetname) _target.kind = target:kind() _target.absscriptdir = target:scriptdir() -- cgit v1.3.1