diff options
| author | ruki <[email protected]> | 2017-03-15 16:12:36 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-03-15 16:12:36 +0800 |
| commit | 645779a4239069b504a530b5667b80cf8f7f5f9a (patch) | |
| tree | fd847a21cb93a743ae90242d2a2bc3d579ce136b | |
| parent | 84a1ac1d297ff039e600a4ea2ecb9f122aac5846 (diff) | |
modify vs201x project plugin
| -rw-r--r--[-rwxr-xr-x] | core/src/xmake/os/argv.c | 2 | ||||
| -rw-r--r-- | xmake/core/base/interpreter.lua | 1 | ||||
| -rw-r--r-- | xmake/core/project/project.lua | 32 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/project/project.lua | 24 | ||||
| -rwxr-xr-x | xmake/plugins/project/vstudio/impl/vs200x_solution.lua | 8 | ||||
| -rwxr-xr-x | xmake/plugins/project/vstudio/impl/vs201x.lua | 20 | ||||
| -rwxr-xr-x | xmake/plugins/project/vstudio/impl/vs201x_solution.lua | 118 | ||||
| -rwxr-xr-x | xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua | 82 | ||||
| -rwxr-xr-x | xmake/plugins/project/xmake.lua | 5 |
9 files changed, 227 insertions, 65 deletions
diff --git a/core/src/xmake/os/argv.c b/core/src/xmake/os/argv.c index 359c94331..0954c0da2 100755..100644 --- a/core/src/xmake/os/argv.c +++ b/core/src/xmake/os/argv.c @@ -71,7 +71,7 @@ tb_int_t xm_os_argv(lua_State* lua) // leave quote? else if ((s == 2 && ch == '\"') || (s == 1 && ch == '\'')) s = 0; // escape charactor? - else if (!escape && ch == '\\') escape = 1; + else if (!escape && ch == '\\' && p[1] != '\\') escape = 1; // is argument end with ' '? else if (!s && tb_isspace(ch)) { diff --git a/xmake/core/base/interpreter.lua b/xmake/core/base/interpreter.lua index c4ae93a9f..a207a32f2 100644 --- a/xmake/core/base/interpreter.lua +++ b/xmake/core/base/interpreter.lua @@ -900,7 +900,6 @@ function interpreter:api_register_set_values(scope_kind, ...) -- update values? scope[name] = {} table.join2(scope[name], ...) - end -- register implementation diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua index b11fc9154..8c07a0706 100644 --- a/xmake/core/project/project.lua +++ b/xmake/core/project/project.lua @@ -185,10 +185,12 @@ function project._interpreter() { values = { + -- set_xxx + "set_project" + , "set_version" + , "set_modes" -- target.set_xxx - "target.set_kind" - , "target.set_version" - , "target.set_project" + , "target.set_kind" , "target.set_strip" , "target.set_options" , "target.set_symbols" @@ -369,6 +371,28 @@ function project.check() return true end +-- get the project info from the given name +function project.get(name) + + -- load the global project infos + local infos = project._INFOS + if not infos then + + -- get interpreter + local interp = project._interpreter() + assert(interp) + + -- load infos + infos = interp:load(xmake._PROJECT_FILE, nil, true, true) + project._INFOS = infos + end + + -- get it + if infos then + return infos[name] + end +end + -- load the project function project.load() @@ -382,7 +406,7 @@ function project.load() return false, errors end - -- load results + -- load targets local results, errors = interp:load(xmake._PROJECT_FILE, "target", true, true) if not results then return false, errors diff --git a/xmake/core/sandbox/modules/import/core/project/project.lua b/xmake/core/sandbox/modules/import/core/project/project.lua index 45605599b..883dcc750 100644 --- a/xmake/core/sandbox/modules/import/core/project/project.lua +++ b/xmake/core/sandbox/modules/import/core/project/project.lua @@ -92,29 +92,17 @@ end -- get the project version function sandbox_core_project.version() - - -- get version - for _, target in pairs(table.wrap(project.targets())) do - local version = target:get("version") - if version then - return version - end - end + return project.get("version") end -- get the project name function sandbox_core_project.name() - - -- get version - for _, target in pairs(table.wrap(project.targets())) do - local name = target:get("project") - if name then - return name - end - end + return project.get("project") +end - -- uses the project directory name - return path.basename(project.directory()) +-- get the project modes +function sandbox_core_project.modes() + return project.get("modes") end -- return module diff --git a/xmake/plugins/project/vstudio/impl/vs200x_solution.lua b/xmake/plugins/project/vstudio/impl/vs200x_solution.lua index 59056b9b7..85de807cc 100755 --- a/xmake/plugins/project/vstudio/impl/vs200x_solution.lua +++ b/xmake/plugins/project/vstudio/impl/vs200x_solution.lua @@ -41,14 +41,8 @@ function _make_projects(slnfile, vsinfo) -- make all targets for targetname, target in pairs(project.targets()) do - -- the project suffix - local suffix = "vcproj" - if tonumber(vsinfo.vstudio_version) >= 2010 then - suffix = "vcxproj" - end - -- enter project - slnfile:enter("Project(\"{%s}\") = \"%s\", \"%s\\%s.%s\", \"{%s}\"", vctool, targetname, targetname, targetname, suffix, os.uuid(targetname)) + slnfile:enter("Project(\"{%s}\") = \"%s\", \"%s\\%s.vcproj\", \"{%s}\"", vctool, targetname, targetname, targetname, os.uuid(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 7da0e29c4..8d97bdaae 100755 --- a/xmake/plugins/project/vstudio/impl/vs201x.lua +++ b/xmake/plugins/project/vstudio/impl/vs201x.lua @@ -23,8 +23,10 @@ -- -- imports +import("core.base.option") +import("core.project.config") import("core.project.project") -import("vs200x_solution") +import("vs201x_solution") import("vs201x_vcxproj") import("vs201x_vcxproj_filters") @@ -37,8 +39,22 @@ function make(outputdir, vsinfo) -- init solution directory vsinfo.solution_dir = path.join(outputdir, "vs" .. vsinfo.vstudio_version) + -- init modes + local modes = option.get("modes") + if modes then + vsinfo.modes = {} + for _, mode in ipairs(modes:split(',')) do + table.insert(vsinfo.modes, mode:trim()) + end + else + vsinfo.modes = project.modes() + end + if not vsinfo.modes or #vsinfo.modes == 0 then + vsinfo.modes = { config.mode() } + end + -- make solution - vs200x_solution.make(vsinfo) + vs201x_solution.make(vsinfo) -- make vsprojs for _, target in pairs(project.targets()) do diff --git a/xmake/plugins/project/vstudio/impl/vs201x_solution.lua b/xmake/plugins/project/vstudio/impl/vs201x_solution.lua new file mode 100755 index 000000000..a3182d9fd --- /dev/null +++ b/xmake/plugins/project/vstudio/impl/vs201x_solution.lua @@ -0,0 +1,118 @@ +--!The Make-like Build Utility based on Lua +-- +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you 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 - 2017, TBOOX Open Source Group. +-- +-- @author ruki +-- @file vs201x_solution.lua +-- + +-- imports +import("core.project.project") +import("vsfile") + +-- make header +function _make_header(slnfile, vsinfo) + slnfile:print("Microsoft Visual Studio Solution File, Format Version %s.00", vsinfo.solution_version) + slnfile:print("# Visual Studio %s", vsinfo.vstudio_version) +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 + + -- enter project + slnfile:enter("Project(\"{%s}\") = \"%s\", \"%s\\%s.vcxproj\", \"{%s}\"", vctool, targetname, targetname, targetname, os.uuid(targetname)) + + -- add dependences + for _, dep in ipairs(target:get("deps")) do + slnfile:enter("ProjectSection(ProjectDependencies) = postProject") + slnfile:print("{%s} = {%s}", os.uuid(dep), os.uuid(dep)) + slnfile:leave("EndProjectSection") + end + + -- leave project + slnfile:leave("EndProject") + end +end + +-- make global +function _make_global(slnfile, vsinfo) + + -- enter global + slnfile:enter("Global") + + -- add solution configuration platforms + slnfile:enter("GlobalSection(SolutionConfigurationPlatforms) = preSolution") + for _, mode in ipairs(vsinfo.modes) do + for _, arch in ipairs({"x86", "x64"}) do + slnfile:print("%s|%s = %s|%s", mode, arch, mode, arch) + end + end + slnfile:leave("EndGlobalSection") + + -- add project configuration platforms + slnfile:enter("GlobalSection(ProjectConfigurationPlatforms) = postSolution") + for targetname, _ in pairs(project.targets()) do + for _, mode in ipairs(vsinfo.modes) do + for _, arch in ipairs({"x86", "x64"}) do + slnfile:print("{%s}.%s|%s.ActiveCfg = %s|%s", os.uuid(targetname), mode, arch, mode, arch) + slnfile:print("{%s}.%s|%s.Build.0 = %s|%s", os.uuid(targetname), mode, arch, mode, arch) + end + end + end + slnfile:leave("EndGlobalSection") + + -- add solution properties + slnfile:enter("GlobalSection(SolutionProperties) = preSolution") + slnfile:print("HideSolutionNode = FALSE") + slnfile:leave("EndGlobalSection") + + -- leave global + slnfile:leave("EndGlobal") +end + +-- make solution +function make(vsinfo) + + -- init solution name + vsinfo.solution_name = project.name() or "vs" .. vsinfo.vstudio_version + + -- open solution file + local slnfile = vsfile.open(path.join(vsinfo.solution_dir, vsinfo.solution_name .. ".sln"), "w") + + -- init indent character + vsfile.indentchar('\t') + + -- make header + _make_header(slnfile, vsinfo) + + -- make projects + _make_projects(slnfile, vsinfo) + + -- make global + _make_global(slnfile, vsinfo) + + -- exit solution file + slnfile:close() +end diff --git a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua index 6e8423a92..527540098 100755 --- a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua +++ b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua @@ -158,10 +158,14 @@ function _make_configurations(vcxprojfile, vsinfo, target, vcxprojdir) -- make ProjectConfigurations vcxprojfile:enter("<ItemGroup Label=\"ProjectConfigurations\">") - vcxprojfile:enter("<ProjectConfiguration Include=\"$(mode)|Win32\">") - vcxprojfile:print("<Configuration>$(mode)</Configuration>") - vcxprojfile:print("<Platform>Win32</Platform>") - vcxprojfile:leave("</ProjectConfiguration>") + for _, mode in ipairs(vsinfo.modes) do + for _, arch in ipairs({"x86", "x64"}) do + vcxprojfile:enter("<ProjectConfiguration Include=\"%s|%s\">", mode, arch) + vcxprojfile:print("<Configuration>%s</Configuration>", mode) + vcxprojfile:print("<Platform>%s</Platform>", arch) + vcxprojfile:leave("</ProjectConfiguration>") + end + end vcxprojfile:leave("</ItemGroup>") -- make Globals @@ -174,11 +178,15 @@ function _make_configurations(vcxprojfile, vsinfo, target, vcxprojdir) vcxprojfile:print("<Import Project=\"%$(VCTargetsPath)\\Microsoft.Cpp.Default.props\" />") -- make Configuration - vcxprojfile:enter("<PropertyGroup Condition=\"\'%$(Configuration)|%$(Platform)\'==\'$(mode)|Win32\'\" Label=\"Configuration\">") - vcxprojfile:print("<ConfigurationType>%s</ConfigurationType>", assert(configuration_types[target:get("kind")])) - vcxprojfile:print("<PlatformToolset>v%s</PlatformToolset>", assert(versions["vs" .. vsinfo.vstudio_version])) - vcxprojfile:print("<CharacterSet>MultiByte</CharacterSet>") - vcxprojfile:leave("</PropertyGroup>") + for _, mode in ipairs(vsinfo.modes) do + for _, arch in ipairs({"x86", "x64"}) do + vcxprojfile:enter("<PropertyGroup Condition=\"\'%$(Configuration)|%$(Platform)\'==\'%s|%s\'\" Label=\"Configuration\">", mode, arch) + vcxprojfile:print("<ConfigurationType>%s</ConfigurationType>", assert(configuration_types[target:get("kind")])) + vcxprojfile:print("<PlatformToolset>v%s</PlatformToolset>", assert(versions["vs" .. vsinfo.vstudio_version])) + vcxprojfile:print("<CharacterSet>MultiByte</CharacterSet>") + vcxprojfile:leave("</PropertyGroup>") + end + end -- import Microsoft.Cpp.props vcxprojfile:print("<Import Project=\"%$(VCTargetsPath)\\Microsoft.Cpp.props\" />") @@ -188,9 +196,13 @@ function _make_configurations(vcxprojfile, vsinfo, target, vcxprojdir) vcxprojfile:leave("</ImportGroup>") -- make PropertySheets - vcxprojfile:enter("<ImportGroup Condition=\"\'%$(Configuration)|%$(Platform)\'==\'$(mode)|Win32\'\" Label=\"PropertySheets\">") - vcxprojfile:print("<Import Project=\"%$(UserRootDir)\\Microsoft.Cpp.%$(Platform).user.props\" Condition=\"exists(\'%$(UserRootDir)\\Microsoft.Cpp.%$(Platform).user.props\')\" Label=\"LocalAppDataPlatform\" />") - vcxprojfile:leave("</ImportGroup>") + for _, mode in ipairs(vsinfo.modes) do + for _, arch in ipairs({"x86", "x64"}) do + vcxprojfile:enter("<ImportGroup Condition=\"\'%$(Configuration)|%$(Platform)\'==\'%s|%s\'\" Label=\"PropertySheets\">", mode, arch) + vcxprojfile:print("<Import Project=\"%$(UserRootDir)\\Microsoft.Cpp.%$(Platform).user.props\" Condition=\"exists(\'%$(UserRootDir)\\Microsoft.Cpp.%$(Platform).user.props\')\" Label=\"LocalAppDataPlatform\" />") + vcxprojfile:leave("</ImportGroup>") + end + end -- make UserMacros vcxprojfile:print("<PropertyGroup Label=\"UserMacros\" />") @@ -206,10 +218,10 @@ function _make_configurations(vcxprojfile, vsinfo, target, vcxprojdir) end -- make ItemDefinitionGroup -function _make_item_define_group(vcxprojfile, vsinfo, target, vcxprojdir) +function _make_item_define_group(vcxprojfile, vsinfo, target, vcxprojdir, mode, arch) -- enter ItemDefinitionGroup - vcxprojfile:enter("<ItemDefinitionGroup Condition=\"\'%$(Configuration)|%$(Platform)\'==\'$(mode)|Win32\'\">") + vcxprojfile:enter("<ItemDefinitionGroup Condition=\"\'%$(Configuration)|%$(Platform)\'==\'%s|%s\'\">", mode, arch) -- for linker? if target:get("kind") == "binary" then @@ -232,7 +244,7 @@ function _make_item_define_group(vcxprojfile, vsinfo, target, vcxprojdir) vcxprojfile:print("<SubSystem>Console</SubSystem>") -- make TargetMachine - vcxprojfile:print("<TargetMachine>%s</TargetMachine>", ifelse(config.arch() == "x64", "MachineX64", "MachineX86")) + vcxprojfile:print("<TargetMachine>%s</TargetMachine>", ifelse(arch == "x64", "MachineX64", "MachineX86")) vcxprojfile:leave("</Link>") end @@ -247,8 +259,13 @@ function _make_item_define_group(vcxprojfile, vsinfo, target, vcxprojdir) vcxprojfile:leave("</ItemDefinitionGroup>") end --- make file -function _make_file(vcxprojfile, vsinfo, target, sourcefile, objectfile, vcxprojdir) +-- make header file +function _make_header_file(vcxprojfile, includefile, vcxprojdir) + vcxprojfile:print("<ClInclude Include=\"%s\" />", path.relative(path.absolute(includefile), vcxprojdir)) +end + +-- make source file +function _make_source_file(vcxprojfile, vsinfo, target, sourcefile, objectfile, vcxprojdir, mode, arch) -- get the target key local key = tostring(target) @@ -262,23 +279,19 @@ function _make_file(vcxprojfile, vsinfo, target, sourcefile, objectfile, vcxproj -- add file vcxprojfile:enter("<ClCompile Include=\"%s\">", path.relative(path.absolute(sourcefile), vcxprojdir)) - vcxprojfile:print("<AdditionalOptions Condition=\"\'%$(Configuration)|%$(Platform)\'==\'$(mode)|Win32\'\">%s %%(AdditionalOptions)</AdditionalOptions>", flags) - vcxprojfile:print("<ObjectFileName Condition=\"\'%$(Configuration)|%$(Platform)\'==\'$(mode)|Win32\'\">%s</ObjectFileName>", path.relative(path.absolute(objectfile), vcxprojdir)) + vcxprojfile:print("<AdditionalOptions Condition=\"\'%$(Configuration)|%$(Platform)\'==\'%s|%s\'\">%s %%(AdditionalOptions)</AdditionalOptions>", mode, arch, flags) + vcxprojfile:print("<ObjectFileName Condition=\"\'%$(Configuration)|%$(Platform)\'==\'%s|%s\'\">%s</ObjectFileName>", mode, arch, path.relative(path.absolute(objectfile), vcxprojdir)) -- complie as c++ if exists flag: /TP if flags:find("[%-|/]TP") then - vcxprojfile:print("<CompileAs Condition=\"\'%$(Configuration)|%$(Platform)\'==\'$(mode)|Win32\'\">CompileAsCpp</CompileAs>") + vcxprojfile:print("<CompileAs Condition=\"\'%$(Configuration)|%$(Platform)\'==\'%s|%s\'\">CompileAsCpp</CompileAs>", mode, arch) end vcxprojfile:leave("</ClCompile>") end -function _make_header_file(vcxprojfile, includefile, vcxprojdir) - vcxprojfile:print("<ClInclude Include=\"%s\" />", path.relative(path.absolute(includefile), vcxprojdir)) -end - --- make source code list -function _make_source_code_list(vcxprojfile, vsinfo, target, vcxprojdir) +-- make source files +function _make_source_files(vcxprojfile, vsinfo, target, vcxprojdir, mode, arch) -- enter ItemGroup vcxprojfile:enter("<ItemGroup>") @@ -286,7 +299,7 @@ function _make_source_code_list(vcxprojfile, vsinfo, target, vcxprojdir) -- add files local objectfiles = target:objectfiles() for idx, sourcefile in ipairs(target:sourcefiles()) do - _make_file(vcxprojfile, vsinfo, target, sourcefile, objectfiles[idx], vcxprojdir) + _make_source_file(vcxprojfile, vsinfo, target, sourcefile, objectfiles[idx], vcxprojdir, mode, arch) end vcxprojfile:leave("</ItemGroup>") @@ -322,11 +335,18 @@ function make(vsinfo, target) -- make Configurations _make_configurations(vcxprojfile, vsinfo, target, vcxprojdir) - -- make ItemDefinitionGroup - _make_item_define_group(vcxprojfile, vsinfo, target, vcxprojdir) + -- make compiler and linker options for the source files + for _, mode in ipairs(vsinfo.modes) do + for _, arch in ipairs({"x86", "x64"}) do + + -- make ItemDefinitionGroup + _make_item_define_group(vcxprojfile, vsinfo, target, vcxprojdir, mode, arch) + + -- make source files + _make_source_files(vcxprojfile, vsinfo, target, vcxprojdir) - -- make source code list - _make_source_code_list(vcxprojfile, vsinfo, target, vcxprojdir) + end + end -- make tailer _make_tailer(vcxprojfile, vsinfo, target) diff --git a/xmake/plugins/project/xmake.lua b/xmake/plugins/project/xmake.lua index 2e04ddd8f..4de77ea2b 100755 --- a/xmake/plugins/project/xmake.lua +++ b/xmake/plugins/project/xmake.lua @@ -45,7 +45,10 @@ task("project") {'k', "kind", "kv", "makefile", "Set the project kind." , " - makefile" , " - vs2002, vs2003, vs2005, vs2008, vs2010, vs2012, vs2013, vs2015, vs2017" } - , {nil, "outputdir", "v", ".", "Set the output directory." } + , {'m', "modes", "kv", nil, "Set the project modes." + , " .e.g " + , " - xmake project -k vs2015 -m \"release,debug\"" } + , {nil, "outputdir", "v", ".", "Set the output directory." } } } |
