summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2017-03-17 11:02:22 +0800
committerruki <[email protected]>2017-03-17 11:02:22 +0800
commit3e6132e5fee64b0ca38796494922a6bbe8648de1 (patch)
tree2c46d365f897fe4285fbb2671c9f2555765b77c0
parent831509cea9c280d0274b1d309f82b370be2c9a23 (diff)
fix option checking and support multi-modes vs201x project
-rw-r--r--xmake/core/project/option.lua19
-rw-r--r--xmake/core/project/project.lua4
-rw-r--r--xmake/core/sandbox/modules/import/core/project/project.lua4
-rwxr-xr-xxmake/plugins/project/vstudio/impl/vs201x.lua40
-rwxr-xr-xxmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua81
5 files changed, 77 insertions, 71 deletions
diff --git a/xmake/core/project/option.lua b/xmake/core/project/option.lua
index 4ce846134..a62b6009a 100644
--- a/xmake/core/project/option.lua
+++ b/xmake/core/project/option.lua
@@ -445,10 +445,10 @@ function option:_check_condition()
end
-- attempt to check option
-function option:check()
+function option:check(force)
-- have been checked?
- if self._CHECKED then
+ if self._CHECKED and not force then
return
end
@@ -456,11 +456,16 @@ function option:check()
local name = self:name()
-- need check?
- if config.get(name) == nil then
+ if config.get(name) == nil or force then
+
+ -- get default value, TODO: enable will be deprecated
+ local default = self:get("default")
+ if default == nil then
+ default = self:get("enable")
+ end
-- enable it?
- local enable = self:get("enable")
- if enable ~= nil and enable then
+ if default ~= nil and (type(default) ~= "boolean" or default == true) then
-- enable this option
config.set(name, true)
@@ -468,8 +473,8 @@ function option:check()
-- save this option to configure
self:save()
- -- check option
- elseif enable == nil and self:_check_condition() then
+ -- check option if the default value not exists
+ elseif default == nil and self:_check_condition() then
-- enable this option
config.set(name, true)
diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua
index 8c07a0706..0cf877ba3 100644
--- a/xmake/core/project/project.lua
+++ b/xmake/core/project/project.lua
@@ -336,7 +336,7 @@ function project.directory()
end
-- check the project
-function project.check()
+function project.check(force)
-- enter the project directory
local ok, errors = os.cd(project.directory())
@@ -355,7 +355,7 @@ function project.check()
-- check all options
for _, opt in pairs(options) do
- opt:check()
+ opt:check(force)
end
-- leave toolchains environment
diff --git a/xmake/core/sandbox/modules/import/core/project/project.lua b/xmake/core/sandbox/modules/import/core/project/project.lua
index 883dcc750..56257fbc2 100644
--- a/xmake/core/sandbox/modules/import/core/project/project.lua
+++ b/xmake/core/sandbox/modules/import/core/project/project.lua
@@ -42,10 +42,10 @@ function sandbox_core_project.load()
end
-- check project options
-function sandbox_core_project.check()
+function sandbox_core_project.check(force)
-- check it
- local ok, errors = project.check()
+ local ok, errors = project.check(force)
if not ok then
raise(errors)
end
diff --git a/xmake/plugins/project/vstudio/impl/vs201x.lua b/xmake/plugins/project/vstudio/impl/vs201x.lua
index 389152f01..ce20ae182 100755
--- a/xmake/plugins/project/vstudio/impl/vs201x.lua
+++ b/xmake/plugins/project/vstudio/impl/vs201x.lua
@@ -58,6 +58,7 @@ function make(outputdir, vsinfo)
local targets = {}
for _, mode in ipairs(vsinfo.modes) do
for _, arch in ipairs({"x86", "x64"}) do
+
-- reload config, project and platform
if mode ~= config.mode() or arch ~= config.arch() then
@@ -65,39 +66,36 @@ function make(outputdir, vsinfo)
config.set("mode", mode)
config.set("arch", arch)
- -- recheck configure
- config.check()
-
-- recheck project options
- project.check()
+ project.check(true)
-- reload platform
platform.load(config.plat())
-- reload project
project.load()
+ end
- -- ensure to enter project directory
- os.cd(project.directory())
+ -- ensure to enter project directory
+ os.cd(project.directory())
- -- save targets
- for targetname, target in pairs(project.targets()) do
+ -- save targets
+ for targetname, target in pairs(project.targets()) do
- -- make target with the given mode and arch
- targets[targetname] = targets[targetname] or {}
- local _target = targets[targetname]
+ -- make target with the given mode and arch
+ targets[targetname] = targets[targetname] or {}
+ local _target = targets[targetname]
- -- init target info
- _target.name = targetname
- _target.kind = target:get("kind")
- _target.scriptdir = scriptdir
- _target.info = _target.info or {}
- table.insert(_target.info, { mode = mode, arch = arch, target = target })
+ -- init target info
+ _target.name = targetname
+ _target.kind = target:get("kind")
+ _target.scriptdir = scriptdir
+ _target.info = _target.info or {}
+ table.insert(_target.info, { mode = mode, arch = arch, target = target })
- -- save all sourcefiles and headerfiles
- _target.sourcefiles = table.unique(table.join(_target.sourcefiles or {}, (target:sourcefiles())))
- _target.headerfiles = table.unique(table.join(_target.headerfiles or {}, (target:headerfiles())))
- end
+ -- save all sourcefiles and headerfiles
+ _target.sourcefiles = table.unique(table.join(_target.sourcefiles or {}, (target:sourcefiles())))
+ _target.headerfiles = table.unique(table.join(_target.headerfiles or {}, (target:headerfiles())))
end
end
end
diff --git a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua
index a8fc7fa1b..3bae5607d 100755
--- a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua
+++ b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua
@@ -213,8 +213,8 @@ function _make_configurations(vcxprojfile, vsinfo, target, vcxprojdir)
end
end
--- make ItemDefinitionGroup
-function _make_item_define_group(vcxprojfile, vsinfo, targetinfo, vcxprojdir)
+-- make link item
+function _make_link_item(vcxprojfile, vsinfo, targetinfo, vcxprojdir)
-- enter ItemDefinitionGroup
vcxprojfile:enter("<ItemDefinitionGroup Condition=\"\'%$(Configuration)|%$(Platform)\'==\'%s|%s\'\">", targetinfo.mode, targetinfo.arch)
@@ -256,53 +256,60 @@ function _make_item_define_group(vcxprojfile, vsinfo, targetinfo, vcxprojdir)
vcxprojfile:leave("</ItemDefinitionGroup>")
end
+-- make link items
+function _make_link_items(vcxprojfile, vsinfo, target, vcxprojdir)
+ for _, targetinfo in ipairs(target.info) do
+ _make_link_item(vcxprojfile, vsinfo, targetinfo, vcxprojdir)
+ end
+end
+
-- make header file
function _make_header_file(vcxprojfile, includefile, vcxprojdir)
vcxprojfile:print("<ClInclude Include=\"%s\" />", path.relative(path.absolute(includefile), vcxprojdir))
end
-- make source file
-function _make_source_file(vcxprojfile, vsinfo, targetinfo, sourcefile, objectfile, vcxprojdir)
-
- -- get target
- local target = targetinfo.target
+function _make_source_file(vcxprojfile, vsinfo, sourcefile, sourceinfo, vcxprojdir)
- -- get the target key
- local key = tostring(target)
-
- -- make flags cache
- _g.flags = _g.flags or {}
+ -- add source file
+ vcxprojfile:enter("<ClCompile Include=\"%s\">", path.relative(path.absolute(sourcefile), vcxprojdir))
+ for _, info in ipairs(sourceinfo) do
- -- make flags
- local flags = _g.flags[key] or _make_compflags(sourcefile, target, vcxprojdir)
- _g.flags[key] = flags
+ -- add compiler flags
+ vcxprojfile:print("<AdditionalOptions Condition=\"\'%$(Configuration)|%$(Platform)\'==\'%s|%s\'\">%s %%(AdditionalOptions)</AdditionalOptions>", info.mode, info.arch, info.flags)
- -- add file
- vcxprojfile:enter("<ClCompile Include=\"%s\">", path.relative(path.absolute(sourcefile), vcxprojdir))
- vcxprojfile:print("<AdditionalOptions Condition=\"\'%$(Configuration)|%$(Platform)\'==\'%s|%s\'\">%s %%(AdditionalOptions)</AdditionalOptions>", targetinfo.mode, targetinfo.arch, flags)
- vcxprojfile:print("<ObjectFileName Condition=\"\'%$(Configuration)|%$(Platform)\'==\'%s|%s\'\">%s</ObjectFileName>", targetinfo.mode, targetinfo.arch, path.relative(path.absolute(objectfile), vcxprojdir))
+ -- add object file
+ vcxprojfile:print("<ObjectFileName Condition=\"\'%$(Configuration)|%$(Platform)\'==\'%s|%s\'\">%s</ObjectFileName>", info.mode, info.arch, path.relative(path.absolute(info.objectfile), vcxprojdir))
- -- complie as c++ if exists flag: /TP
- if flags:find("[%-|/]TP") then
- vcxprojfile:print("<CompileAs Condition=\"\'%$(Configuration)|%$(Platform)\'==\'%s|%s\'\">CompileAsCpp</CompileAs>", targetinfo.mode, targetinfo.arch)
+ -- complie as c++ if exists flag: /TP
+ if info.flags:find("[%-|/]TP") then
+ vcxprojfile:print("<CompileAs Condition=\"\'%$(Configuration)|%$(Platform)\'==\'%s|%s\'\">CompileAsCpp</CompileAs>", info.mode, info.arch)
+ end
end
-
vcxprojfile:leave("</ClCompile>")
end
-- make source files
-function _make_source_files(vcxprojfile, vsinfo, targetinfo, vcxprojdir)
-
- -- get target
- local target = targetinfo.target
+function _make_source_files(vcxprojfile, vsinfo, target, vcxprojdir)
-- enter ItemGroup
vcxprojfile:enter("<ItemGroup>")
- -- add files
- local objectfiles = target:objectfiles()
- for idx, sourcefile in ipairs(target:sourcefiles()) do
- _make_source_file(vcxprojfile, vsinfo, targetinfo, sourcefile, objectfiles[idx], vcxprojdir)
+ -- make source file infos
+ local sourceinfos = {}
+ for _, targetinfo in ipairs(target.info) do
+ local objectfiles = targetinfo.target:objectfiles()
+ for idx, sourcefile in ipairs(targetinfo.target:sourcefiles()) do
+ local objectfile = objectfiles[idx]
+ local flags = _make_compflags(sourcefile, targetinfo.target, vcxprojdir)
+ sourceinfos[sourcefile] = sourceinfos[sourcefile] or {}
+ table.insert(sourceinfos[sourcefile], {mode = targetinfo.mode, arch = targetinfo.arch, objectfile = objectfile, flags = flags})
+ end
+ end
+
+ -- make source files
+ for sourcefile, sourceinfo in pairs(sourceinfos) do
+ _make_source_file(vcxprojfile, vsinfo, sourcefile, sourceinfo, vcxprojdir)
end
vcxprojfile:leave("</ItemGroup>")
@@ -311,7 +318,7 @@ function _make_source_files(vcxprojfile, vsinfo, targetinfo, vcxprojdir)
vcxprojfile:enter("<ItemGroup>")
-- add headers
- for _, includefile in ipairs(target:headerfiles()) do
+ for _, includefile in ipairs(target.headerfiles) do
_make_header_file(vcxprojfile, includefile, vcxprojdir)
end
vcxprojfile:leave("</ItemGroup>")
@@ -338,15 +345,11 @@ function make(vsinfo, target)
-- make Configurations
_make_configurations(vcxprojfile, vsinfo, target, vcxprojdir)
- -- make compiler and linker options for the source files
- for _, targetinfo in ipairs(target.info) do
-
- -- make ItemDefinitionGroup
- _make_item_define_group(vcxprojfile, vsinfo, targetinfo, vcxprojdir)
+ -- make link items
+ _make_link_items(vcxprojfile, vsinfo, target, vcxprojdir)
- -- make source files
- _make_source_files(vcxprojfile, vsinfo, targetinfo, vcxprojdir)
- end
+ -- make source files
+ _make_source_files(vcxprojfile, vsinfo, target, vcxprojdir)
-- make tailer
_make_tailer(vcxprojfile, vsinfo)