diff options
| author | 夕伽 <[email protected]> | 2018-09-02 20:00:16 +0800 |
|---|---|---|
| committer | 夕伽 <[email protected]> | 2018-09-02 20:00:16 +0800 |
| commit | 90786f2a568f3063907f4566d910da1ceae74194 (patch) | |
| tree | 4f11bbcafa5038d3df251d63d930a6f07447d3ec /xmake/plugins | |
| parent | d74715b3615e171776a6e5b9971d2ec2bff115d5 (diff) | |
vsporject add some configs
1.suport vsproject mfc mode
target(xxx)
-- for make vsproject on mfcmode
set_values("mfc",true)
-- for unicode mode
add_defines("UNICODE")
-- use MT or MD switch RuntimeLibrary, (debug use MTd,MDd)
add_cxflags("-MT")
2.subsystem switch support
target(xxx)
-- change subsystem to windows, default console
add_ldflags("/SUBSYSTEM:WINDOWS",{force=true})
Diffstat (limited to 'xmake/plugins')
| -rw-r--r-- | xmake/plugins/project/vstudio/impl/vs200x_vcproj.lua | 61 | ||||
| -rw-r--r-- | xmake/plugins/project/vstudio/impl/vs201x.lua | 19 | ||||
| -rw-r--r-- | xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua | 17 |
3 files changed, 88 insertions, 9 deletions
diff --git a/xmake/plugins/project/vstudio/impl/vs200x_vcproj.lua b/xmake/plugins/project/vstudio/impl/vs200x_vcproj.lua index d1dd0d06e..91c287c08 100644 --- a/xmake/plugins/project/vstudio/impl/vs200x_vcproj.lua +++ b/xmake/plugins/project/vstudio/impl/vs200x_vcproj.lua @@ -180,10 +180,22 @@ end -- WarningLevel="3" -- DebugInformationFormat="4" -- /> -function _make_VCCLCompilerTool(vcprojfile, vsinfo, target) +function _make_VCCLCompilerTool(vcprojfile, vsinfo, target, compflags) vcprojfile:enter("<Tool") vcprojfile:print("Name=\"VCCLCompilerTool\"") vcprojfile:print("ProgramDataBaseFileName=\"\"") -- disable pdb file default + -- MT:0, MTd:1, MD:2, MDd:3, ML:4, MLd:5 + local runtime = 0 + for _,flag in pairs(compflags) do + if flag:find("[%-|/]MD") then + runtime = 2 + break + elseif flag:find("[%-|/]MT") then + runtime = 0 + break + end + end + vcprojfile:print("RuntimeLibrary=\"%d\"", ifelse(val("mode") == "debug", runtime + 1, runtime)) vcprojfile:leave("/>") end @@ -219,15 +231,22 @@ function _make_VCLinkerTool(vcprojfile, vsinfo, target, vcprojdir) end end + -- subsystem, console: 1, windows: 2 + local subsystem = 1 + local flags = _make_linkflags(target, vcprojdir) + if string.lower(flags):find("[%-/]subsystem:windows") then + subsystem = 2 + end + -- make it vcprojfile:enter("<Tool") vcprojfile:print("Name=\"VCLinkerTool\"") - vcprojfile:print("AdditionalOptions=\"%s\"", _make_linkflags(target, vcprojdir)) + vcprojfile:print("AdditionalOptions=\"%s\"", flags) vcprojfile:print("AdditionalDependencies=\"\"") vcprojfile:print("AdditionalLibraryDirectories=\"\"") vcprojfile:print("LinkIncremental=\"2\"") -- enable: 2, disable: 1 vcprojfile:print("GenerateDebugInformation=\"%s\"", tostring(debug)) - vcprojfile:print("SubSystem=\"1\"") -- console: 1, windows: 2 + vcprojfile:print("SubSystem=\"%d\"", subsystem) -- console: 1, windows: 2 vcprojfile:print("TargetMachine=\"%d\"", ifelse(config.arch() == "x64", 17, 1)) vcprojfile:leave("/>") end @@ -243,6 +262,37 @@ function _make_configurations(vcprojfile, vsinfo, target, vcprojdir) , static = 4 } + -- save compiler flags + local compflags=nil + for sourcekind, sourcebatch in pairs(target:sourcebatches()) do + if not sourcebatch.rulename then + for _, sourcefile in ipairs(sourcebatch.sourcefiles) do + local flags = compiler.compflags(sourcefile, {target = target}) + if sourcekind == "cc" or sourcekind == "cxx" then + compflags = flags + break + end + end + end + if compflags then + break + end + end + + -- set default mfc, not used: 0, static:1, dynamic:2 + local mfc = ifelse(target:values("mfc"), 2, 0) + -- set unicode and mfc + local unicode = false + for _, flag in pairs(compflags) do + if flag:find("-DUNICODE") then + unicode = true + elseif flag:find("[%-|/]MT") then + mfc = ifelse(mfc ~= 0, 1, 0) + elseif flag:find("[%-|/]MD") then + mfc = ifelse(mfc ~= 0, 2, 0) + end + end + -- enter configurations vcprojfile:enter("<Configurations>") @@ -252,7 +302,8 @@ function _make_configurations(vcprojfile, vsinfo, target, vcprojdir) vcprojfile:print("OutputDirectory=\"%s\"", path.relative(path.absolute(target:targetdir()), vcprojdir)) vcprojfile:print("IntermediateDirectory=\"%s\"", path.relative(path.absolute(target:objectdir()), vcprojdir)) vcprojfile:print("ConfigurationType=\"%d\"", assert(configuration_types[target:get("kind")])) - vcprojfile:print("CharacterSet=\"2\"") -- mbc: 2, wcs: 1 + vcprojfile:print("CharacterSet=\"%d\"", ifelse(unicode, 1, 2)) -- mbc: 2, wcs: 1 + vcprojfile:print("UseOfMFC=\"%d\"", mfc) vcprojfile:print(">") -- make VCPreBuildEventTool @@ -281,7 +332,7 @@ function _make_configurations(vcprojfile, vsinfo, target, vcprojdir) vcprojfile:leave("/>") -- make VCCLCompilerTool - _make_VCCLCompilerTool(vcprojfile, vsinfo, target) + _make_VCCLCompilerTool(vcprojfile, vsinfo, target, compflags) -- make VCManagedResourceCompilerTool vcprojfile:enter("<Tool") diff --git a/xmake/plugins/project/vstudio/impl/vs201x.lua b/xmake/plugins/project/vstudio/impl/vs201x.lua index 8ef5681d2..bcdd45ddd 100644 --- a/xmake/plugins/project/vstudio/impl/vs201x.lua +++ b/xmake/plugins/project/vstudio/impl/vs201x.lua @@ -75,11 +75,15 @@ function _make_targetinfo(mode, arch, target) targetinfo.objectdir = target:objectdir() -- save compiler flags + local firstcompflags=nil targetinfo.compflags = {} - for _, sourcebatch in pairs(target:sourcebatches()) do + for sourcekind, sourcebatch in pairs(target:sourcebatches()) do if not sourcebatch.rulename then for _, sourcefile in ipairs(sourcebatch.sourcefiles) do local compflags = compiler.compflags(sourcefile, {target = target}) + if not firstcompflags and (sourcekind == "cc" or sourcekind == "cxx") then + firstcompflags = compflags + end targetinfo.compflags[sourcefile] = compflags end end @@ -89,6 +93,19 @@ function _make_targetinfo(mode, arch, target) local linkflags = linker.linkflags(target:get("kind"), target:sourcekinds(), {target = target}) targetinfo.linkflags = linkflags + -- set default mfc + targetinfo.mfc = ifelse(target:values("mfc"), "Dynamic", nil) + -- set unicode and mfc + for _, flag in pairs(firstcompflags) do + if flag:find("-DUNICODE") then + targetinfo.unicode = true + elseif flag:find("[%-|/]MT") then + targetinfo.mfc = ifelse(targetinfo.mfc, "Static", false) + elseif flag:find("[%-|/]MD") then + targetinfo.mfc = ifelse(targetinfo.mfc, "Dynamic", false) + end + end + -- ok return targetinfo end diff --git a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua index 3a9ccc6f6..4e96a4fe1 100644 --- a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua +++ b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua @@ -172,7 +172,10 @@ function _make_configurations(vcxprojfile, vsinfo, target, vcxprojdir) vcxprojfile:enter("<PropertyGroup Condition=\"\'%$(Configuration)|%$(Platform)\'==\'%s|%s\'\" Label=\"Configuration\">", targetinfo.mode, targetinfo.arch) vcxprojfile:print("<ConfigurationType>%s</ConfigurationType>", assert(configuration_types[target.kind])) vcxprojfile:print("<PlatformToolset>v%s</PlatformToolset>", assert(toolset_versions["vs" .. vsinfo.vstudio_version])) - vcxprojfile:print("<CharacterSet>MultiByte</CharacterSet>") + vcxprojfile:print("<CharacterSet>%s</CharacterSet>", ifelse(targetinfo.unicode, "Unicode", "MultiByte")) + if targetinfo.mfc then + vcxprojfile:print("<UseOfMfc>%s</UseOfMfc>", targetinfo.mfc) + end vcxprojfile:leave("</PropertyGroup>") end @@ -328,12 +331,20 @@ function _make_common_item(vcxprojfile, vsinfo, target, targetinfo, vcxprojdir) -- for linker? vcxprojfile:enter("<%s>", linkerkinds[targetinfo.targetkind]) + -- save subsystem + local subsystem = "Console" + -- make linker flags local flags = {} for _, flag in ipairs(_make_linkflags(targetinfo, vcxprojdir)) do + local flag_lower = string.lower(flag) + + -- remove "-subsystem:windows" + if flag_lower:find("[%-/]subsystem:windows") then + subsystem = "Windows" -- remove "-machine:[x86|x64]", "-pdb:*.pdb" and "-debug" - if not flag:find("[%-/]machine:%w+") and not flag:find("[%-/]pdb:.+%.pdb") and not flag:find("[%-/]debug") then + elseif not flag_lower:find("[%-/]machine:%w+") and not flag_lower:find("[%-/]pdb:.+%.pdb") and not flag_lower:find("[%-/]debug") then table.insert(flags, flag) end end @@ -358,7 +369,7 @@ function _make_common_item(vcxprojfile, vsinfo, target, targetinfo, vcxprojdir) -- make SubSystem if targetinfo.targetkind == "binary" then - vcxprojfile:print("<SubSystem>Console</SubSystem>") + vcxprojfile:print("<SubSystem>%s</SubSystem>", subsystem) end -- make TargetMachine |
