From e15e08d70cadfe3d6d3b42756cb92ff4ac77ba61 Mon Sep 17 00:00:00 2001 From: enorof Date: Fri, 16 Sep 2016 20:36:50 +0800 Subject: add filters for vs201x project. --- .../sandbox/modules/import/core/tool/compiler.lua | 5 + xmake/core/tool/compiler.lua | 29 ++++++ xmake/plugins/project/vstudio/impl/vs201x.lua | 2 + .../project/vstudio/impl/vs201x_vcxproj.lua | 13 +++ .../vstudio/impl/vs201x_vcxproj_filters.lua | 111 +++++++++++++++++++++ 5 files changed, 160 insertions(+) create mode 100644 xmake/plugins/project/vstudio/impl/vs201x_vcxproj_filters.lua 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("") end +function _make_header_file(vcxprojfile, includefile, vcxprojdir) + vcxprojfile:print("", 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("") + + -- enter header group + vcxprojfile:enter("") + + -- add headers + for idx, includefile in ipairs(target:headerfiles()) do + _make_header_file(vcxprojfile, includefile, vcxprojdir) + end + vcxprojfile:leave("") 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("") + filtersfile:enter("", assert(versions["vs" .. vsinfo.vstudio_version])) +end + +-- make tailer +function _make_tailer(filtersfile, vsinfo, target) + filtersfile:leave("") +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("") + for _, includeFile in ipairs(include_list) do + filtersfile:enter("", path.relative(includeFile, vcxprojdir)) + filtersfile:print("%s", path.relative(path.directory(includeFile), "Sources")) + filtersfile:leave("") + end + filtersfile:leave("") + + -- and sources + filtersfile:enter("") + for _, sourceFile in ipairs(sources_list) do + filtersfile:enter("", path.relative(sourceFile, vcxprojdir)) + filtersfile:print("%s", path.relative(path.directory(sourceFile), "Sources")) + filtersfile:leave("") + end + filtersfile:leave("") + + -- add filters + filtersfile:enter("") + for sourceFile, _ in pairs(filters_list) do + filtersfile:enter("", sourceFile) + filtersfile:print("{%s}", os.uuid()) + filtersfile:leave("") + end + filtersfile:leave("") +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 -- cgit v1.3.1