From 36cffe6922680493c36d9f9ba4a8fa18b60d8539 Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 8 Aug 2016 14:11:35 +0800 Subject: add compflags and linkflags interfaces --- .../sandbox/modules/import/core/tool/compiler.lua | 13 + .../sandbox/modules/import/core/tool/linker.lua | 13 + xmake/core/tool/compiler.lua | 93 ++++--- xmake/core/tool/linker.lua | 99 ++++---- .../plugins/project/vstudio/impl/vs200x_vcproj.lua | 281 ++++++++++++++++++++- 5 files changed, 395 insertions(+), 104 deletions(-) diff --git a/xmake/core/sandbox/modules/import/core/tool/compiler.lua b/xmake/core/sandbox/modules/import/core/tool/compiler.lua index a6e0e78dc..77eb51ad1 100644 --- a/xmake/core/sandbox/modules/import/core/tool/compiler.lua +++ b/xmake/core/sandbox/modules/import/core/tool/compiler.lua @@ -41,6 +41,19 @@ function sandbox_core_tool_compiler.compcmd(sourcefile, objectfile, target) return instance:compcmd(sourcefile, objectfile, target) end +-- make compiling flags for the given target +function sandbox_core_tool_compiler.compflags(sourcefile) + + -- get the compiler instance + local instance, errors = compiler.load(compiler.kind_of_file(sourcefile)) + if not instance then + raise(errors) + end + + -- make flags + return instance:compflags(target) +end + -- compile source file function sandbox_core_tool_compiler.compile(sourcefile, objectfile, incdepfile, target) diff --git a/xmake/core/sandbox/modules/import/core/tool/linker.lua b/xmake/core/sandbox/modules/import/core/tool/linker.lua index ec4e28ebd..a204681d4 100644 --- a/xmake/core/sandbox/modules/import/core/tool/linker.lua +++ b/xmake/core/sandbox/modules/import/core/tool/linker.lua @@ -41,6 +41,19 @@ function sandbox_core_tool_linker.linkcmd(objectfiles, targetfile, target) return instance:linkcmd(objectfiles, targetfile, target) end +-- make link flags for the given target +function sandbox_core_tool_linker.linkflags(target) + + -- get the linker instance + local instance, errors = linker.load(target:get("kind")) + if not instance then + raise(errors) + end + + -- make flags + return instance:linkflags(target) +end + -- link target file function sandbox_core_tool_linker.link(objectfiles, targetfile, target) diff --git a/xmake/core/tool/compiler.lua b/xmake/core/tool/compiler.lua index 14a3178c3..d14b4dcbd 100644 --- a/xmake/core/tool/compiler.lua +++ b/xmake/core/tool/compiler.lua @@ -49,44 +49,6 @@ function compiler:_flagnames() return self._FLAGNAMES end --- get the flags -function compiler:_flags(target) - - -- get the target key - local key = tostring(target) - - -- get it directly from cache dirst - self._FLAGS = self._FLAGS or {} - if self._FLAGS[key] then - return self._FLAGS[key] - end - - -- add flags from the configure - local flags = {} - self:_addflags_from_config(flags) - - -- add flags from the target - self:_addflags_from_target(flags, target) - - -- add flags from the platform - self:_addflags_from_platform(flags) - - -- add flags from the compiler - self:_addflags_from_compiler(flags, target:get("kind")) - - -- remove repeat - flags = table.unique(flags) - - -- merge flags - flags = table.concat(flags, " "):trim() - - -- save flags - self._FLAGS[key] = flags - - -- get it - return flags -end - -- map gcc flag to the given compiler flag function compiler:_mapflag(flag, mapflags) @@ -359,27 +321,58 @@ end -- compile the source file function compiler:compile(sourcefile, objectfile, incdepfile, target) - -- get flags - local flags = nil - if target then - flags = self:_flags(target) - end - -- compile it - return sandbox.load(self:_tool().compile, sourcefile, objectfile, incdepfile, flags or "") + return sandbox.load(self:_tool().compile, sourcefile, objectfile, incdepfile, self:compflags(target)) end -- get the compile command function compiler:compcmd(sourcefile, objectfile, target) - -- get flags - local flags = nil - if target then - flags = self:_flags(target) + -- get it + return self:_tool().compcmd(sourcefile, objectfile, self:compflags(target)) +end + +-- get the compling flags +function compiler:compflags(target) + + -- no target? + if not target then + return "" end + -- get the target key + local key = tostring(target) + + -- get it directly from cache dirst + self._FLAGS = self._FLAGS or {} + if self._FLAGS[key] then + return self._FLAGS[key] + end + + -- add flags from the configure + local flags = {} + self:_addflags_from_config(flags) + + -- add flags from the target + self:_addflags_from_target(flags, target) + + -- add flags from the platform + self:_addflags_from_platform(flags) + + -- add flags from the compiler + self:_addflags_from_compiler(flags, target:get("kind")) + + -- remove repeat + flags = table.unique(flags) + + -- merge flags + flags = table.concat(flags, " "):trim() + + -- save flags + self._FLAGS[key] = flags + -- get it - return self:_tool().compcmd(sourcefile, objectfile, flags or "") + return flags end -- make the symbol flag diff --git a/xmake/core/tool/linker.lua b/xmake/core/tool/linker.lua index e054517f5..9f638034a 100644 --- a/xmake/core/tool/linker.lua +++ b/xmake/core/tool/linker.lua @@ -64,47 +64,6 @@ function linker._kind_of_target(targetkind) return kinds[targetkind] end --- get the flags -function linker:_flags(target) - - -- get the target key - local key = tostring(target) - - -- get it directly from cache dirst - self._FLAGS = self._FLAGS or {} - if self._FLAGS[key] then - return self._FLAGS[key] - end - - -- add flags from the configure - local flags = {} - self:_addflags_from_config(flags) - - -- add flags from the target - self:_addflags_from_target(flags, target) - - -- add flags from the platform - self:_addflags_from_platform(flags) - - -- add flags from the compiler - self:_addflags_from_compiler(flags, target:sourcekinds()) - - -- add flags from the linker - self:_addflags_from_linker(flags) - - -- remove repeat - flags = table.unique(flags) - - -- merge flags - flags = table.concat(flags, " "):trim() - - -- save flags - self._FLAGS[key] = flags - - -- get it - return flags -end - -- map gcc flag to the given linker flag function linker:_mapflag(flag, mapflags) @@ -329,27 +288,61 @@ end -- link the target file function linker:link(objectfiles, targetfile, target) - -- get flags - local flags = nil - if target then - flags = self:_flags(target) - end - -- link it - return sandbox.load(self:_tool().link, table.concat(table.wrap(objectfiles), " "), targetfile, flags or "") + return sandbox.load(self:_tool().link, table.concat(table.wrap(objectfiles), " "), targetfile, self:linkflags(target)) end -- get the link command function linker:linkcmd(objectfiles, targetfile, target) - -- get flags - local flags = nil - if target then - flags = self:_flags(target) + -- get it + return self:_tool().linkcmd(table.concat(table.wrap(objectfiles), " "), targetfile, self:linkflags(target)) +end + +-- get the link flags +function linker:linkflags(target) + + -- no target? + if not target then + return "" + end + + -- get the target key + local key = tostring(target) + + -- get it directly from cache dirst + self._FLAGS = self._FLAGS or {} + if self._FLAGS[key] then + return self._FLAGS[key] end + -- add flags from the configure + local flags = {} + self:_addflags_from_config(flags) + + -- add flags from the target + self:_addflags_from_target(flags, target) + + -- add flags from the platform + self:_addflags_from_platform(flags) + + -- add flags from the compiler + self:_addflags_from_compiler(flags, target:sourcekinds()) + + -- add flags from the linker + self:_addflags_from_linker(flags) + + -- remove repeat + flags = table.unique(flags) + + -- merge flags + flags = table.concat(flags, " "):trim() + + -- save flags + self._FLAGS[key] = flags + -- get it - return self:_tool().linkcmd(table.concat(table.wrap(objectfiles), " "), targetfile, flags or "") + return flags end -- make the strip flag diff --git a/xmake/plugins/project/vstudio/impl/vs200x_vcproj.lua b/xmake/plugins/project/vstudio/impl/vs200x_vcproj.lua index fd35145fe..dca5ee419 100755 --- a/xmake/plugins/project/vstudio/impl/vs200x_vcproj.lua +++ b/xmake/plugins/project/vstudio/impl/vs200x_vcproj.lua @@ -21,8 +21,264 @@ -- -- imports +import("core.tool.linker") +import("core.tool.archiver") +import("core.tool.compiler") +import("core.project.config") import("vsfile") +-- make header +function _make_header(vcprojfile, vsinfo, target) + + -- the target name + local targetname = target:name() + + -- the versions + local versions = + { + vs2002 = '7.0' + , vs2003 = '7.1' + , vs2005 = '8.0' + , vs2008 = '9.0' + } + + -- make header + vcprojfile:print("") + vcprojfile:enter("") +end + +-- make tailer +function _make_tailer(vcprojfile, vsinfo, target) + vcprojfile:leave("") +end + +-- make platforms +function _make_platforms(vcprojfile, vsinfo, target) + + -- add Win32 platform + vcprojfile:enter("") + vcprojfile:enter("") + vcprojfile:leave("") +end + +-- make toolfiles +function _make_toolfiles(vcprojfile, vsinfo, target) + + -- empty toolfiles + vcprojfile:enter("") + vcprojfile:leave("") +end + +-- make VCCLCompilerTool +-- +-- .e.g +-- +-- +function _make_VCCLCompilerTool(vcprojfile, vsinfo, target) + vcprojfile:enter("") +end + +-- make VCLinkerTool +-- +-- .e.g +-- +function _make_VCLinkerTool(vcprojfile, vsinfo, target) + + -- need not linker? + local kind = target:get("kind") + if kind ~= "binary" and kind ~= "shared" then + vcprojfile:enter("") + return + end + + -- generate debug infomation? + local debug = false + for _, symbol in ipairs(target:get("symbols")) do + if symbol == "debug" then + debug = true + break + end + end + + -- make it + vcprojfile:enter("") +end + +-- make configurations +function _make_configurations(vcprojfile, vsinfo, target) + + -- init configuration type + local configuration_types = + { + binary = 1 + , shared = 2 + , static = 4 + } + + -- enter configurations + vcprojfile:enter("") + + -- make configuration for the current mode + vcprojfile:enter("") + + -- make VCPreBuildEventTool + vcprojfile:enter("") + + -- make VCCustomBuildTool + vcprojfile:enter("") + + -- make VCXMLDataGeneratorTool + vcprojfile:enter("") + + -- make VCWebServiceProxyGeneratorTool + vcprojfile:enter("") + + -- make VCMIDLTool + vcprojfile:enter("") + + -- make VCCLCompilerTool + _make_VCCLCompilerTool(vcprojfile, vsinfo, target) + + -- make VCManagedResourceCompilerTool + vcprojfile:enter("") + + -- make VCResourceCompilerTool + vcprojfile:enter("") + + -- make VCPreLinkEventTool + vcprojfile:enter("") + + -- make VCLinkerTool + _make_VCLinkerTool(vcprojfile, vsinfo, target) + + -- make VCALinkTool + vcprojfile:enter("") + + -- make VCManifestTool + vcprojfile:enter("") + + -- make VCXDCMakeTool + vcprojfile:enter("") + + -- make VCBscMakeTool + vcprojfile:enter("") + + -- make VCFxCopTool + vcprojfile:enter("") + + -- make VCAppVerifierTool + vcprojfile:enter("") + + -- make VCPostBuildEventTool + vcprojfile:enter("") + + + -- leave configuration + vcprojfile:leave("") + + -- leave configurations + vcprojfile:leave("") +end + +-- make references +function _make_references(vcprojfile, vsinfo, target) + + vcprojfile:enter("") + vcprojfile:leave("") +end + +-- make files +function _make_files(vcprojfile, vsinfo, target) + + vcprojfile:enter("") + vcprojfile:leave("") +end + +-- make globals +function _make_globals(vcprojfile, vsinfo, target) + + vcprojfile:enter("") + vcprojfile:leave("") +end + -- make vcproj function make(outputdir, vsinfo, target) @@ -30,8 +286,31 @@ function make(outputdir, vsinfo, target) local targetname = target:name() -- open vcproj file - local vcprojfile = vsfile.open(format("%s/vs%s/%s/%s.vsproj", outputdir, vsinfo.vstudio_version, targetname, targetname), "w") + local vcprojfile = vsfile.open(format("%s/vs%s/%s/%s.vcproj", outputdir, vsinfo.vstudio_version, targetname, targetname), "w") + + -- make header + _make_header(vcprojfile, vsinfo, target) + + -- make platforms + _make_platforms(vcprojfile, vsinfo, target) + + -- make toolfiles + _make_toolfiles(vcprojfile, vsinfo, target) + + -- make configurations + _make_configurations(vcprojfile, vsinfo, target) + + -- make references + _make_references(vcprojfile, vsinfo, target) + + -- make files + _make_files(vcprojfile, vsinfo, target) + + -- make globals + _make_globals(vcprojfile, vsinfo, target) + -- make tailer + _make_tailer(vcprojfile, vsinfo, target) -- exit solution file vcprojfile:close() -- cgit v1.3.1