summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2016-08-08 14:11:35 +0800
committerruki <[email protected]>2016-08-08 14:11:35 +0800
commit36cffe6922680493c36d9f9ba4a8fa18b60d8539 (patch)
tree594150c0d7286d5adc8325ba70d9d300594e1357
parent92f5c739180afb80ddf99865902a68f122c3aef1 (diff)
add compflags and linkflags interfaces
-rw-r--r--xmake/core/sandbox/modules/import/core/tool/compiler.lua13
-rw-r--r--xmake/core/sandbox/modules/import/core/tool/linker.lua13
-rw-r--r--xmake/core/tool/compiler.lua93
-rw-r--r--xmake/core/tool/linker.lua99
-rwxr-xr-xxmake/plugins/project/vstudio/impl/vs200x_vcproj.lua281
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("<?xml version=\"1.0\" encoding=\"gb2312\"?>")
+ vcprojfile:enter("<VisualStudioProject")
+ vcprojfile:print("ProjectType=\"Visual C++\"")
+ vcprojfile:print("Version=\"%s0\"", assert(versions["vs" .. vsinfo.vstudio_version]))
+ vcprojfile:print("Name=\"%s\"", targetname)
+ vcprojfile:print("ProjectGUID=\"{%s}\"", os.uuid(targetname))
+ vcprojfile:print("RootNamespace=\"%s\"", targetname)
+ vcprojfile:print("TargetFrameworkVersion=\"196613\"")
+ vcprojfile:print(">")
+end
+
+-- make tailer
+function _make_tailer(vcprojfile, vsinfo, target)
+ vcprojfile:leave("</VisualStudioProject>")
+end
+
+-- make platforms
+function _make_platforms(vcprojfile, vsinfo, target)
+
+ -- add Win32 platform
+ vcprojfile:enter("<Platforms>")
+ vcprojfile:enter("<Platform")
+ vcprojfile:print("Name=\"Win32\"")
+ vcprojfile:leave("/>")
+ vcprojfile:leave("</Platforms>")
+end
+
+-- make toolfiles
+function _make_toolfiles(vcprojfile, vsinfo, target)
+
+ -- empty toolfiles
+ vcprojfile:enter("<ToolFiles>")
+ vcprojfile:leave("</ToolFiles>")
+end
+
+-- make VCCLCompilerTool
+--
+-- .e.g
+--
+-- <Tool
+-- Name="VCCLCompilerTool"
+-- AdditionalOptions="/TP"
+-- Optimization="0"
+-- AdditionalIncludeDirectories="&quot;$(SolutionDir)\..\..\src&quot;;&quot;"
+-- PreprocessorDefinitions=""
+-- MinimalRebuild="true"
+-- BasicRuntimeChecks="3"
+-- RuntimeLibrary="3"
+-- UsePrecompiledHeader="0"
+-- WarningLevel="3"
+-- DebugInformationFormat="4"
+-- />
+function _make_VCCLCompilerTool(vcprojfile, vsinfo, target)
+ vcprojfile:enter("<Tool")
+ vcprojfile:print("Name=\"VCCLCompilerTool\"")
+ vcprojfile:leave("/>")
+end
+
+-- make VCLinkerTool
+--
+-- .e.g
+-- <Tool
+-- Name="VCLinkerTool"
+-- AdditionalDependencies="xxx.lib"
+-- LinkIncremental="2"
+-- AdditionalLibraryDirectories="&quot;$(SolutionDir)\..\..\lib&quot;"
+-- GenerateDebugInformation="true"
+-- SubSystem="1"
+-- TargetMachine="1"
+-- />
+function _make_VCLinkerTool(vcprojfile, vsinfo, target)
+
+ -- need not linker?
+ local kind = target:get("kind")
+ if kind ~= "binary" and kind ~= "shared" then
+ vcprojfile:enter("<Tool")
+ vcprojfile:print("Name=\"VCLinkerTool\"")
+ vcprojfile:leave("/>")
+ 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("<Tool")
+ vcprojfile:print("Name=\"VCLinkerTool\"")
+ vcprojfile:print("AdditionalOptions=\"%s\"", linker.linkflags(target))
+ 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("TargetMachine=\"%d\"", ifelse(config.arch() == "x64", 17, 1))
+ vcprojfile:leave("/>")
+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("<Configurations>")
+
+ -- make configuration for the current mode
+ vcprojfile:enter("<Configuration")
+ vcprojfile:print("Name=\"$(mode)|Win32\"")
+ vcprojfile:print("OutputDirectory=\"$(buildir)\\%s\"", target:name())
+ vcprojfile:print("IntermediateDirectory=\"%$(ConfigurationName)\"")
+ vcprojfile:print("ConfigurationType=\"%d\"", assert(configuration_types[target:get("kind")]))
+ vcprojfile:print("CharacterSet=\"2\"") -- mbc: 2, wcs: 1
+ vcprojfile:print(">")
+
+ -- make VCPreBuildEventTool
+ vcprojfile:enter("<Tool")
+ vcprojfile:print("Name=\"VCPreBuildEventTool\"")
+ vcprojfile:leave("/>")
+
+ -- make VCCustomBuildTool
+ vcprojfile:enter("<Tool")
+ vcprojfile:print("Name=\"VCCustomBuildTool\"")
+ vcprojfile:leave("/>")
+
+ -- make VCXMLDataGeneratorTool
+ vcprojfile:enter("<Tool")
+ vcprojfile:print("Name=\"VCXMLDataGeneratorTool\"")
+ vcprojfile:leave("/>")
+
+ -- make VCWebServiceProxyGeneratorTool
+ vcprojfile:enter("<Tool")
+ vcprojfile:print("Name=\"VCWebServiceProxyGeneratorTool\"")
+ vcprojfile:leave("/>")
+
+ -- make VCMIDLTool
+ vcprojfile:enter("<Tool")
+ vcprojfile:print("Name=\"VCMIDLTool\"")
+ vcprojfile:leave("/>")
+
+ -- make VCCLCompilerTool
+ _make_VCCLCompilerTool(vcprojfile, vsinfo, target)
+
+ -- make VCManagedResourceCompilerTool
+ vcprojfile:enter("<Tool")
+ vcprojfile:print("Name=\"VCManagedResourceCompilerTool\"")
+ vcprojfile:leave("/>")
+
+ -- make VCResourceCompilerTool
+ vcprojfile:enter("<Tool")
+ vcprojfile:print("Name=\"VCResourceCompilerTool\"")
+ vcprojfile:leave("/>")
+
+ -- make VCPreLinkEventTool
+ vcprojfile:enter("<Tool")
+ vcprojfile:print("Name=\"VCPreLinkEventTool\"")
+ vcprojfile:leave("/>")
+
+ -- make VCLinkerTool
+ _make_VCLinkerTool(vcprojfile, vsinfo, target)
+
+ -- make VCALinkTool
+ vcprojfile:enter("<Tool")
+ vcprojfile:print("Name=\"VCALinkTool\"")
+ vcprojfile:leave("/>")
+
+ -- make VCManifestTool
+ vcprojfile:enter("<Tool")
+ vcprojfile:print("Name=\"VCManifestTool\"")
+ vcprojfile:leave("/>")
+
+ -- make VCXDCMakeTool
+ vcprojfile:enter("<Tool")
+ vcprojfile:print("Name=\"VCXDCMakeTool\"")
+ vcprojfile:leave("/>")
+
+ -- make VCBscMakeTool
+ vcprojfile:enter("<Tool")
+ vcprojfile:print("Name=\"VCBscMakeTool\"")
+ vcprojfile:leave("/>")
+
+ -- make VCFxCopTool
+ vcprojfile:enter("<Tool")
+ vcprojfile:print("Name=\"VCFxCopTool\"")
+ vcprojfile:leave("/>")
+
+ -- make VCAppVerifierTool
+ vcprojfile:enter("<Tool")
+ vcprojfile:print("Name=\"VCAppVerifierTool\"")
+ vcprojfile:leave("/>")
+
+ -- make VCPostBuildEventTool
+ vcprojfile:enter("<Tool")
+ vcprojfile:print("Name=\"VCPostBuildEventTool\"")
+ vcprojfile:leave("/>")
+
+
+ -- leave configuration
+ vcprojfile:leave("</Configuration>")
+
+ -- leave configurations
+ vcprojfile:leave("</Configurations>")
+end
+
+-- make references
+function _make_references(vcprojfile, vsinfo, target)
+
+ vcprojfile:enter("<References>")
+ vcprojfile:leave("</References>")
+end
+
+-- make files
+function _make_files(vcprojfile, vsinfo, target)
+
+ vcprojfile:enter("<Files>")
+ vcprojfile:leave("</Files>")
+end
+
+-- make globals
+function _make_globals(vcprojfile, vsinfo, target)
+
+ vcprojfile:enter("<Globals>")
+ vcprojfile:leave("</Globals>")
+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()