summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorenorof <[email protected]>2016-09-16 20:36:50 +0800
committerenorof <[email protected]>2016-09-16 20:36:50 +0800
commite15e08d70cadfe3d6d3b42756cb92ff4ac77ba61 (patch)
tree87049136b99c4db16c4108baeb3ad4eb7feec4d6
parent252f501054ab2058320319a1cb9f749858b6776c (diff)
add filters for vs201x project.
-rw-r--r--xmake/core/sandbox/modules/import/core/tool/compiler.lua5
-rw-r--r--xmake/core/tool/compiler.lua29
-rwxr-xr-xxmake/plugins/project/vstudio/impl/vs201x.lua2
-rwxr-xr-xxmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua13
-rw-r--r--xmake/plugins/project/vstudio/impl/vs201x_vcxproj_filters.lua111
5 files changed, 160 insertions, 0 deletions
diff --git a/xmake/core/sandbox/modules/import/core/tool/compiler.lua b/xmake/core/sandbox/modules/import/core/tool/compiler.lua
index 46803b444..4e32ccd63 100644
--- a/xmake/core/sandbox/modules/import/core/tool/compiler.lua
+++ b/xmake/core/sandbox/modules/import/core/tool/compiler.lua
@@ -75,5 +75,10 @@ function sandbox_core_tool_compiler.kind_of_file(sourcefile)
return compiler.kind_of_file(sourcefile)
end
+-- get the type of file
+function sandbox_core_tool_compiler.type_of_file(sourcefile)
+ return compiler.type_of_file(sourcefile)
+end
+
-- return module
return sandbox_core_tool_compiler
diff --git a/xmake/core/tool/compiler.lua b/xmake/core/tool/compiler.lua
index 81c6c5da8..9ac87cb82 100644
--- a/xmake/core/tool/compiler.lua
+++ b/xmake/core/tool/compiler.lua
@@ -253,6 +253,35 @@ function compiler.kind_of_file(sourcefile)
return kinds[filetype:lower()]
end
+-- get the type of file
+function compiler.type_of_file(sourcefile)
+
+ -- get the source file type
+ local filetype = path.extension(sourcefile)
+ if not filetype then
+ return nil
+ end
+
+ -- the kinds
+ local kinds =
+ {
+ [".c"] = "source"
+ , [".cc"] = "source"
+ , [".cpp"] = "source"
+ , [".cxx"] = "source"
+ , [".h"] = "header"
+ , [".hpp"] = "header"
+ , [".m"] = "source"
+ , [".mm"] = "source"
+ , [".s"] = "source"
+ , [".asm"] = "source"
+ , [".swift"] = "source"
+ }
+
+ -- get kind
+ return kinds[filetype:lower()]
+end
+
-- get the current kind
function compiler:kind()
diff --git a/xmake/plugins/project/vstudio/impl/vs201x.lua b/xmake/plugins/project/vstudio/impl/vs201x.lua
index 618413056..e2a9f4687 100755
--- a/xmake/plugins/project/vstudio/impl/vs201x.lua
+++ b/xmake/plugins/project/vstudio/impl/vs201x.lua
@@ -24,6 +24,7 @@
import("core.project.project")
import("vs200x_solution")
import("vs201x_vcxproj")
+import("vs201x_vcxproj_filters")
-- make vstudio project
function make(outputdir, vsinfo)
@@ -40,6 +41,7 @@ function make(outputdir, vsinfo)
-- make vsprojs
for _, target in pairs(project.targets()) do
vs201x_vcxproj.make(vsinfo, target)
+ vs201x_vcxproj_filters.make(vsinfo, target)
end
-- leave project directory
diff --git a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua
index afff30133..53ab72d01 100755
--- a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua
+++ b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua
@@ -269,6 +269,10 @@ function _make_file(vcxprojfile, vsinfo, target, sourcefile, objectfile, vcxproj
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)
@@ -282,6 +286,15 @@ function _make_source_code_list(vcxprojfile, vsinfo, target, vcxprojdir)
end
vcxprojfile:leave("</ItemGroup>")
+
+ -- enter header group
+ vcxprojfile:enter("<ItemGroup>")
+
+ -- add headers
+ for idx, includefile in ipairs(target:headerfiles()) do
+ _make_header_file(vcxprojfile, includefile, vcxprojdir)
+ end
+ vcxprojfile:leave("</ItemGroup>")
end
-- make vcxproj
diff --git a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj_filters.lua b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj_filters.lua
new file mode 100644
index 000000000..f8ffaaa17
--- /dev/null
+++ b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj_filters.lua
@@ -0,0 +1,111 @@
+-- importes
+import("core.tool.compiler")
+import("vsfile")
+
+-- make header
+function _make_header(filtersfile, vsinfo, target)
+
+ -- the versions
+ local versions =
+ {
+ vs2010 = '10'
+ , vs2012 = '11'
+ , vs2013 = '12'
+ , vs2015 = '14'
+ }
+
+ -- make header
+ filtersfile:print("<?xml version=\"1.0\" encoding=\"utf-8\"?>")
+ filtersfile:enter("<Project ToolsVersion=\"%s.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">", assert(versions["vs" .. vsinfo.vstudio_version]))
+end
+
+-- make tailer
+function _make_tailer(filtersfile, vsinfo, target)
+ filtersfile:leave("</Project>")
+end
+
+local include_list = {}
+local sources_list = {}
+local filters_list = {}
+
+-- add to file list
+function _add_to_list(source, list, vcxprojdir)
+ table.insert(list, source)
+ _add_to_filter(source, vcxprojdir)
+end
+
+-- make filters
+function _add_to_filter(source, vcxprojdir)
+
+ local filter = path.relative(path.directory(source), "Sources")
+
+ if filters_list[filter] == nil then
+ filters_list[filter] = true
+ end
+end
+
+-- make source list
+function _make_source_list(filtersfile, vsinfo, target, vcxprojdir)
+
+ for _, includefile in ipairs(target:headerfiles()) do
+ _add_to_list(includefile, include_list, vcxprojdir)
+ end
+ for _, sourcefile in ipairs(target:sourcefiles()) do
+ _add_to_list(sourcefile, include_list, vcxprojdir)
+ end
+
+ -- and includes
+ filtersfile:enter("<ItemGroup>")
+ for _, includeFile in ipairs(include_list) do
+ filtersfile:enter("<ClInclude Include=\"%s\">", path.relative(includeFile, vcxprojdir))
+ filtersfile:print("<Filter>%s</Filter>", path.relative(path.directory(includeFile), "Sources"))
+ filtersfile:leave("</ClInclude>")
+ end
+ filtersfile:leave("</ItemGroup>")
+
+ -- and sources
+ filtersfile:enter("<ItemGroup>")
+ for _, sourceFile in ipairs(sources_list) do
+ filtersfile:enter("<ClCompile Include=\"%s\">", path.relative(sourceFile, vcxprojdir))
+ filtersfile:print("<Filter>%s</Filter>", path.relative(path.directory(sourceFile), "Sources"))
+ filtersfile:leave("</ClCompile>")
+ end
+ filtersfile:leave("</ItemGroup>")
+
+ -- add filters
+ filtersfile:enter("<ItemGroup>")
+ for sourceFile, _ in pairs(filters_list) do
+ filtersfile:enter("<Filter Include=\"%s\">", sourceFile)
+ filtersfile:print("<UniqueIdentifier>{%s}</UniqueIdentifier>", os.uuid())
+ filtersfile:leave("</Filter>")
+ end
+ filtersfile:leave("</ItemGroup>")
+end
+
+-- main filters
+function make(vsinfo, target)
+
+ -- the target name
+ local targetname = target:name()
+
+ -- the vcxproj directory
+ local vcxprojdir = path.join(vsinfo.solution_dir, targetname)
+
+ -- open vcxproj file
+ local filtersfile = vsfile.open(path.join(vcxprojdir, targetname .. ".vcxproj.filters"), "w")
+
+ -- init indent character
+ vsfile.indentchar(' ')
+
+ -- make header
+ _make_header(filtersfile, vsinfo, target)
+
+ -- make source list
+ _make_source_list(filtersfile, vsinfo, target, vcxprojdir)
+
+ -- make tailer
+ _make_tailer(filtersfile, vsinfo, target)
+
+ -- exit solution file
+ filtersfile:close()
+end