diff options
| author | ruki <[email protected]> | 2017-03-23 09:49:07 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-03-23 09:49:07 +0800 |
| commit | dcf38006d36ec96bbc20be32f97ceb7b5f176821 (patch) | |
| tree | 423b0feafb6a7ce1f733fcd44881b049855caa48 | |
| parent | 1bdf43c3a7fcd6aa578e2b293664f0db80ebd058 (diff) | |
improve vs201x project plugin and add set_basename api
| -rw-r--r-- | CHANGELOG.md | 6 | ||||
| -rw-r--r-- | core/src/demo/xmake.lua | 3 | ||||
| -rw-r--r-- | scripts/installer.nsi | 5 | ||||
| -rw-r--r-- | xmake/core/project/project.lua | 13 | ||||
| -rw-r--r-- | xmake/core/project/target.lua | 41 | ||||
| -rw-r--r-- | xmake/plugins/project/vstudio/impl/vs201x.lua | 34 | ||||
| -rw-r--r-- | xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua | 29 |
7 files changed, 83 insertions, 48 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e933bce5..b4c4dd00e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### New features * Add aur package script and support to install xmake from yaourt +* Add `set_basename` api for target ### Changes @@ -16,7 +17,7 @@ * Fix cannot find android sdk header files * Fix checking option bug -* Fix code files mode to 0644 +* [#57](https://github.com/tboox/xmake/issues/57): Fix code files mode to 0644 ## v2.1.1 @@ -222,6 +223,7 @@ ### 新特性 * 添加aur打包脚本,并支持用`yaourt`包管理器进行安装。 +* 添加`set_basename`接口,便于定制化修改生成后的目标文件名 ### 改进 @@ -233,7 +235,7 @@ * 修复编译android程序,找不到系统头文件问题 * 修复检测选项行为不正确问题 -* 修复代码文件权限到0644 +* [#57](https://github.com/tboox/xmake/issues/57): 修复代码文件权限到0644 ## v2.1.1 diff --git a/core/src/demo/xmake.lua b/core/src/demo/xmake.lua index fddc45886..beee74704 100644 --- a/core/src/demo/xmake.lua +++ b/core/src/demo/xmake.lua @@ -7,6 +7,9 @@ target("demo") -- make as a binary set_kind("binary") + -- set basename of target file + set_basename("xmake") + -- add defines add_defines("__tb_prefix__=\"xmake\"") diff --git a/scripts/installer.nsi b/scripts/installer.nsi index cc906cb69..85cdb3342 100644 --- a/scripts/installer.nsi +++ b/scripts/installer.nsi @@ -70,11 +70,8 @@ Section "xmake (required)" Installer ; Put file there
File /r /x ".DS_Store" "..\xmake\*.*"
File "..\*.md"
- File "..\core\build\demo.exe"
+ File "..\core\build\xmake.exe"
- ; Rename file
- Rename "$INSTDIR\demo.exe" "$INSTDIR\xmake.exe"
-
; Write the installation path into the registry
WriteRegStr HKLM SOFTWARE\NSIS_xmake "Install_Dir" "$INSTDIR"
diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua index 0cf877ba3..6c25ed8e7 100644 --- a/xmake/core/project/project.lua +++ b/xmake/core/project/project.lua @@ -194,6 +194,7 @@ function project._interpreter() , "target.set_strip" , "target.set_options" , "target.set_symbols" + , "target.set_basename" , "target.set_warnings" , "target.set_optimize" , "target.set_languages" @@ -421,17 +422,7 @@ function project.load() -- make targets local targets = {} for targetname, targetinfo in pairs(results) do - - -- init a target instance - local instance = table.inherit(target) - assert(instance) - - -- save name and info - instance._NAME = targetname - instance._INFO = targetinfo - - -- save it - targets[targetname] = instance + targets[targetname] = target.new(targetname, targetinfo) end -- save targets diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index b78584b74..76f2f7548 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -50,6 +50,21 @@ function target.filename(targetname, targetkind, targetformat) return format[1] .. targetname .. format[2] end +-- new a target instance +function target.new(name, info) + + -- init a target instance + local instance = table.inherit(target) + assert(instance) + + -- save name and info + instance._NAME = name + instance._INFO = info + + -- ok? + return instance +end + -- get the target info function target:get(infoname) @@ -67,6 +82,13 @@ function target:name() return self._NAME end +-- get the base name of target file +function target:basename() + + -- get it + return self:get("basename") +end + -- get the target linker function target:linker() @@ -105,8 +127,13 @@ end -- get the options function target:options() - -- the options - local options = {} + -- attempt to get it from cache first + if self._OPTIONS then + return self._OPTIONS + end + + -- load options + self._OPTIONS = {} for _, name in ipairs(table.wrap(self:get("options"))) do -- get option if be enabled @@ -115,12 +142,12 @@ function target:options() if nil ~= opt then -- insert it and must ensure the order for linking - table.insert(options, opt) + table.insert(self._OPTIONS, opt) end end - -- ok? - return options + -- get it + return self._OPTIONS end -- get the object file directory @@ -162,7 +189,7 @@ function target:targetfile() local targetkind = self:targetkind() -- make the target file name and attempt to use the format of linker first - local filename = target.filename(self:name(), targetkind, self:linker():format(targetkind)) + local filename = target.filename(self:basename() or self:name(), targetkind, self:linker():format(targetkind)) assert(filename) -- make the target file path @@ -180,7 +207,7 @@ function target:symbolfile() assert(targetdir and type(targetdir) == "string") -- the symbol file name - local filename = target.filename(self:name(), "symbol") + local filename = target.filename(self:basename() or self:name(), "symbol") assert(filename) -- make the symbol file path diff --git a/xmake/plugins/project/vstudio/impl/vs201x.lua b/xmake/plugins/project/vstudio/impl/vs201x.lua index ccf34db67..c7eea9c66 100644 --- a/xmake/plugins/project/vstudio/impl/vs201x.lua +++ b/xmake/plugins/project/vstudio/impl/vs201x.lua @@ -27,10 +27,42 @@ import("core.base.option") import("core.project.config") import("core.project.project") import("core.platform.platform") +import("core.tool.compiler") +import("core.tool.linker") import("vs201x_solution") import("vs201x_vcxproj") import("vs201x_vcxproj_filters") +-- make target info +function _make_targetinfo(mode, arch, target) + + -- init target info + local targetinfo = { mode = mode, arch = ifelse(arch == "x86", "Win32", "x64") } + + -- save symbols + targetinfo.symbols = target:get("symbols") + + -- save target kind + targetinfo.targetkind = target:targetkind() + + -- save sourcebatches + targetinfo.sourcebatches = target:sourcebatches() + + -- save compiler flags + targetinfo.compflags = {} + for _, sourcefile in ipairs(target:sourcefiles()) do + local _, compflags = compiler.compflags(sourcefile, target) + targetinfo.compflags[sourcefile] = compflags + end + + -- save linker flags + local _, linkflags = linker.linkflags(target) + targetinfo.linkflags = linkflags + + -- ok + return targetinfo +end + -- make vstudio project function make(outputdir, vsinfo) @@ -91,7 +123,7 @@ function make(outputdir, vsinfo) _target.kind = target:get("kind") _target.scriptdir = target:scriptdir() _target.info = _target.info or {} - table.insert(_target.info, { mode = mode, arch = ifelse(arch == "x86", "Win32", "x64"), target = target }) + table.insert(_target.info, _make_targetinfo(mode, arch, target)) -- save all sourcefiles and headerfiles _target.sourcefiles = table.unique(table.join(_target.sourcefiles or {}, (target:sourcefiles()))) diff --git a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua index ffae2bd98..320c4813c 100644 --- a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua +++ b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua @@ -23,24 +23,15 @@ -- -- imports -import("core.tool.linker") -import("core.tool.compiler") import("core.project.config") import("vsfile") -- make compiling flags function _make_compflags(sourcefile, targetinfo, vcxprojdir) - -- make the compiling flags - local _, compflags = compiler.compflags(sourcefile, targetinfo.target) - - -- switch to the given mode and arch - config.set("mode", targetinfo.mode) - config.set("arch", ifelse(targetinfo.arch == "Win32", "x86", "x64")) - -- translate path for -Idir or /Idir, -Fdsymbol.pdb or /Fdsymbol.pdb local flags = {} - for _, flag in ipairs(compflags) do + for _, flag in ipairs(targetinfo.compflags[sourcefile]) do -- -Idir or /Idir flag = flag:gsub("[%-|/]I(.*)", function (dir) @@ -71,16 +62,9 @@ end -- make linking flags function _make_linkflags(targetinfo, vcxprojdir) - -- switch to the given mode and arch - config.set("mode", targetinfo.mode) - config.set("arch", ifelse(targetinfo.arch == "Win32", "x86", "x64")) - - -- make the linking flags - local _, linkflags = linker.linkflags(targetinfo.target) - -- replace -libpath:dir or /libpath:dir, -pdb:symbol.pdb or /pdb:symbol.pdb local flags = {} - for _, flag in ipairs(linkflags) do + for _, flag in ipairs(targetinfo.linkflags) do -- replace -libpath:dir or /libpath:dir flag = flag:gsub("[%-|/]libpath:(.*)", function (dir) @@ -315,8 +299,7 @@ function _make_common_item(vcxprojfile, vsinfo, targetinfo, vcxprojdir) vcxprojfile:enter("<ItemDefinitionGroup Condition=\"\'%$(Configuration)|%$(Platform)\'==\'%s|%s\'\">", targetinfo.mode, targetinfo.arch) -- for linker? - local target = targetinfo.target - if target:targetkind() == "binary" then + if targetinfo.targetkind == "binary" then vcxprojfile:enter("<Link>") -- make linker flags @@ -327,7 +310,7 @@ function _make_common_item(vcxprojfile, vsinfo, targetinfo, vcxprojdir) -- generate debug infomation? local debug = false - for _, symbol in ipairs(target:get("symbols")) do + for _, symbol in ipairs(targetinfo.symbols) do if symbol == "debug" then debug = true break @@ -370,7 +353,7 @@ function _make_common_items(vcxprojfile, vsinfo, target, vcxprojdir) local files_count = 0 local first_flags = nil targetinfo.sourceflags = {} - for sourcekind, sourcebatch in pairs(targetinfo.target:sourcebatches()) do + for sourcekind, sourcebatch in pairs(targetinfo.sourcebatches) do if sourcekind == "cc" or sourcekind == "cxx" then for _, sourcefile in ipairs(sourcebatch.sourcefiles) do @@ -519,7 +502,7 @@ function _make_source_files(vcxprojfile, vsinfo, target, vcxprojdir) -- make source file infos local sourceinfos = {} for _, targetinfo in ipairs(target.info) do - for sourcekind, sourcebatch in pairs(targetinfo.target:sourcebatches()) do + for sourcekind, sourcebatch in pairs(targetinfo.sourcebatches) do if sourcekind == "cc" or sourcekind == "cxx" then local objectfiles = sourcebatch.objectfiles for idx, sourcefile in ipairs(sourcebatch.sourcefiles) do |
