diff options
| author | ruki <[email protected]> | 2022-06-06 22:05:08 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-06-06 22:05:08 +0800 |
| commit | 31e6c06bbda24d8b2e704705d4acf716d6c28a1d (patch) | |
| tree | 99ee228f536d77b3e40d8ddf6f8d823a27f8df43 | |
| parent | b19dec5ac1139bcf551165fd1838902bdaa449b8 (diff) | |
| parent | 259e08de4b887f91e598f2d62f460c80633f48d9 (diff) | |
Merge pull request #2433 from Domain/vs_default
Non-default target can be built in vs
5 files changed, 45 insertions, 17 deletions
diff --git a/xmake/plugins/project/vsxmake/getinfo.lua b/xmake/plugins/project/vsxmake/getinfo.lua index a64381cd0..26e066145 100644 --- a/xmake/plugins/project/vsxmake/getinfo.lua +++ b/xmake/plugins/project/vsxmake/getinfo.lua @@ -508,6 +508,7 @@ function main(outputdir, vsinfo) local targetinfo = _make_targetinfo(mode, arch, target) _target._targets[mode][arch] = targetinfo _target.sdkver = targetinfo.sdkver + _target.default = targetinfo.default -- save all sourcefiles and headerfiles _target.sourcefiles = table.unique(table.join(_target.sourcefiles or {}, (target:sourcefiles()))) diff --git a/xmake/plugins/project/vsxmake/render.lua b/xmake/plugins/project/vsxmake/render.lua index d599f1dde..6fb1cbc57 100644 --- a/xmake/plugins/project/vsxmake/render.lua +++ b/xmake/plugins/project/vsxmake/render.lua @@ -32,6 +32,33 @@ function _fill(opt, params) end end +function _cfill(opt, params) + return function(match) + local tmp = match:split(";", {strict = true}) + assert(#tmp == 2 or #tmp == 3) + + local cond = tmp[1] + local value1 = tmp[2] + local value2 = "" + + if #tmp == 3 then + value2 = tmp[3] + end + + tmp = cond:split("=") + assert(#tmp == 2) + + local k = tmp[1]:trim() + local v = tmp[2]:trim() + + if opt.paramsprovider(k, params) == v then + return value1 + end + + return value2 + end +end + function _expand(params) local r = {""} for _, v in ipairs(params) do @@ -46,7 +73,7 @@ function _expand(params) for i, p in ipairs(r) do rcopy[i] = p .. "\0" .. c end - newr = table.join(newr, rcopy) + newr = table.join(newr, rcopy) end r = newr end @@ -58,17 +85,17 @@ function _expand(params) end function _render(templatepath, opt, args) - local template = io.readfile(templatepath) local params = _expand(opt.paramsprovider(args)) local replaced = "" for _, v in ipairs(params) do - replaced = replaced .. template:gsub(opt.pattern, _fill(opt, v)) + local tmpl = template:gsub(opt.cpattern, _cfill(opt, v)) + replaced = replaced .. tmpl:gsub(opt.pattern, _fill(opt, v)) end return replaced end -function main(templatepath, pattern, paramsprovider) - local opt = { pattern = pattern, paramsprovider = paramsprovider, templatedir = path.directory(templatepath) } +function main(templatepath, pattern, cpattern, paramsprovider) + local opt = { pattern = pattern, cpattern = cpattern, paramsprovider = paramsprovider, templatedir = path.directory(templatepath) } return _render(templatepath, opt, {}) end diff --git a/xmake/plugins/project/vsxmake/vsproj/Xmake.targets b/xmake/plugins/project/vsxmake/vsproj/Xmake.targets index 2315d2d28..ad5777293 100644 --- a/xmake/plugins/project/vsxmake/vsproj/Xmake.targets +++ b/xmake/plugins/project/vsxmake/vsproj/Xmake.targets @@ -93,19 +93,19 @@ Text="$(XmakeProjectFile) not found at '$(XmakeProjectDirResolved)', please set XmakeProjectDir in vcxproj file" /> </Target> <Target Name="_XmakeConfig" DependsOnTargets="_XmakeProjCheck"> - <Message Text="$xmake config $(_XmakeCommonFlags) $(_XmakeConfigFlags)" Importance="High" Condition="'$(XmakeDefault)' != 'false'" /> + <Message Text="$xmake config $(_XmakeCommonFlags) $(_XmakeConfigFlags)" Importance="High" /> <Exec Command="$(_XmakeEnv) - $(_XmakeExecutable) config $(_XmakeCommonFlags) $(_XmakeConfigFlags)" EchoOff="true" Condition="'$(XmakeDefault)' != 'false'" /> + $(_XmakeExecutable) config $(_XmakeCommonFlags) $(_XmakeConfigFlags)" EchoOff="true" /> </Target> <Target Name="_XmakeBuild" DependsOnTargets="_XmakeProjCheck"> - <Message Text="$xmake build $(_XmakeCommonFlags) $(_XmakeBuildFlags) $(_XmakeTarget)" Importance="High" Condition="'$(XmakeDefault)' != 'false'" /> + <Message Text="$xmake build $(_XmakeCommonFlags) $(_XmakeBuildFlags) $(_XmakeTarget)" Importance="High" /> <Exec Command="$(_XmakeEnv) - $(_XmakeExecutable) build $(_XmakeCommonFlags) $(_XmakeBuildFlags) $(_XmakeTarget)" EchoOff="true" Condition="'$(XmakeDefault)' != 'false'" /> + $(_XmakeExecutable) build $(_XmakeCommonFlags) $(_XmakeBuildFlags) $(_XmakeTarget)" EchoOff="true" /> </Target> <Target Name="_XmakeRebuild" DependsOnTargets="_XmakeProjCheck"> - <Message Text="$xmake build -r $(_XmakeCommonFlags) $(_XmakeBuildFlags) $(_XmakeTarget)" Importance="High" Condition="'$(XmakeDefault)' != 'false'" /> + <Message Text="$xmake build -r $(_XmakeCommonFlags) $(_XmakeBuildFlags) $(_XmakeTarget)" Importance="High" /> <Exec Command="$(_XmakeEnv) - $(_XmakeExecutable) build -r $(_XmakeCommonFlags) $(_XmakeBuildFlags) $(_XmakeTarget)" EchoOff="true" Condition="'$(XmakeDefault)' != 'false'" /> + $(_XmakeExecutable) build -r $(_XmakeCommonFlags) $(_XmakeBuildFlags) $(_XmakeTarget)" EchoOff="true" /> </Target> <Target Name="_XmakeBuildFile" DependsOnTargets="_XmakeProjCheck"> <ItemGroup> @@ -120,9 +120,9 @@ $(_XmakeExecutable) build $(_XmakeCommonFlags) $(_XmakeBuildFileFlags) $(FileFlag) $(_XmakeTarget)" EchoOff="true" /> </Target> <Target Name="_XmakeClean" DependsOnTargets="_XmakeProjCheck"> - <Message Text="$xmake clean $(_XmakeCommonFlags) $(_XmakeCleanFlags) $(_XmakeTarget)" Importance="High" Condition="'$(XmakeDefault)' != 'false'" /> + <Message Text="$xmake clean $(_XmakeCommonFlags) $(_XmakeCleanFlags) $(_XmakeTarget)" Importance="High" /> <Exec Command="$(_XmakeEnv) - $(_XmakeExecutable) clean $(_XmakeCommonFlags) $(_XmakeCleanFlags) $(_XmakeTarget)" EchoOff="true" Condition="'$(XmakeDefault)' != 'false'" /> + $(_XmakeExecutable) clean $(_XmakeCommonFlags) $(_XmakeCleanFlags) $(_XmakeTarget)" EchoOff="true" /> </Target> <Target Name="Show"> diff --git a/xmake/plugins/project/vsxmake/vsproj/templates/sln/ProjConfig(target,mode,arch) b/xmake/plugins/project/vsxmake/vsproj/templates/sln/ProjConfig(target,mode,arch) index 427703018..7b41e11bc 100644 --- a/xmake/plugins/project/vsxmake/vsproj/templates/sln/ProjConfig(target,mode,arch) +++ b/xmake/plugins/project/vsxmake/vsproj/templates/sln/ProjConfig(target,mode,arch) @@ -1,2 +1,2 @@ {#target_id#}.#mode#|#arch#.ActiveCfg = #mode#|#vsarch# - {#target_id#}.#mode#|#arch#.Build.0 = #mode#|#vsarch# +@default=true; {#target_id#}.#mode#|#arch#.Build.0 = #mode#|#vsarch#@ diff --git a/xmake/plugins/project/vsxmake/vsxmake.lua b/xmake/plugins/project/vsxmake/vsxmake.lua index f475f431d..aa6a20069 100644 --- a/xmake/plugins/project/vsxmake/vsxmake.lua +++ b/xmake/plugins/project/vsxmake/vsxmake.lua @@ -225,7 +225,7 @@ function make(version) -- write solution file local sln = path.join(info.solution_dir, info.slnfile .. ".sln") - _writefileifneeded(sln, render(template_sln, "#([A-Za-z0-9_,%.%*%(%)]+)#", paramsprovidersln)) + _writefileifneeded(sln, render(template_sln, "#([A-Za-z0-9_,%.%*%(%)]+)#", "@([^@]+)@", paramsprovidersln)) -- add solution custom file _trycp(template_props, info.solution_dir) @@ -237,10 +237,10 @@ function make(version) -- write project file local proj = path.join(proj_dir, target .. ".vcxproj") - _writefileifneeded(proj, render(template_vcx, "#([A-Za-z0-9_,%.%*%(%)]+)#", paramsprovidertarget)) + _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)) + _writefileifneeded(projfil, render(template_fil, "#([A-Za-z0-9_,%.%*%(%)]+)#", "@([^@]+)@", paramsprovidertarget)) -- add project custom file _trycp(template_props, proj_dir) |
