-
-
Notifications
You must be signed in to change notification settings - Fork 784
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add windows mfc rule #216
add windows mfc rule #216
Changes from 8 commits
aa6cba4
3cb295e
b5fbcac
e3038f3
26b8ecc
a959913
cf23dd6
8d0d7c8
e8af37c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
--!A cross-platform build utility based on Lua | ||
-- | ||
-- Licensed to the Apache Software Foundation (ASF) under one | ||
-- or more contributor license agreements. See the NOTICE file | ||
-- distributed with this work for additional information | ||
-- regarding copyright ownership. The ASF licenses this file | ||
-- to you under the Apache License, Version 2.0 (the | ||
-- "License"); you may not use this file except in compliance | ||
-- with the License. You may obtain a copy of the License at | ||
-- | ||
-- http://www.apache.org/licenses/LICENSE-2.0 | ||
-- | ||
-- Unless required by applicable law or agreed to in writing, software | ||
-- distributed under the License is distributed on an "AS IS" BASIS, | ||
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
-- See the License for the specific language governing permissions and | ||
-- limitations under the License. | ||
-- | ||
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group. | ||
-- | ||
-- @author xigal | ||
-- @file xmake.lua | ||
-- | ||
|
||
-- define rule: mfc.env | ||
rule("win.sdk.mfc.env") | ||
|
||
-- FIXME: before load need check of vs's minverion, if defined | ||
--before_load(function (target) | ||
--end) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
--!A cross-platform build utility based on Lua | ||
-- | ||
-- Licensed to the Apache Software Foundation (ASF) under one | ||
-- or more contributor license agreements. See the NOTICE file | ||
-- distributed with this work for additional information | ||
-- regarding copyright ownership. The ASF licenses this file | ||
-- to you under the Apache License, Version 2.0 (the | ||
-- "License"); you may not use this file except in compliance | ||
-- with the License. You may obtain a copy of the License at | ||
-- | ||
-- http://www.apache.org/licenses/LICENSE-2.0 | ||
-- | ||
-- Unless required by applicable law or agreed to in writing, software | ||
-- distributed under the License is distributed on an "AS IS" BASIS, | ||
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
-- See the License for the specific language governing permissions and | ||
-- limitations under the License. | ||
-- | ||
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group. | ||
-- | ||
-- @author xigal | ||
-- @file xmake.lua | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. author 可以标注下你的名字 😄 |
||
-- | ||
|
||
-- remove exists md or mt | ||
function _mfc_remove_mt_md_flags(target, flagsname) | ||
local flags = table.wrap(target:get(flagsname)) | ||
for key, flag in pairs(flags) do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 此处改动 跟之前的没什么本质区别么,之前提的那个问题还是存在 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 应该不会吧,只要flags是个table就可以了,之前是因为放到for中了,flags并不一定是table。这个我测试过了是没问题的,你有疑惑的话可以写个demo测试下,自己加入MT,MD之类的看看是否过滤了就知道了 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 我给你造个测试用例复现吧: function main()
local flags = table.wrap({"1", "2", "3", "-mt", "4", "5", "6"})
for key, flag in pairs(flags) do
flag = flag:lower():trim()
if flag:find("^[/%-]?mt[d]?$") or flag:find("^[/%-]?md[d]?$") then
flags[key] = nil
end
end
for _, flag in ipairs(flags) do
print(flag)
end
print(#flags)
end 你保存为 ./test.lua 然后直接运行测试: $ xmake lua ./test.lua 正常结果应该是从 但是实际输出的flags结果只有 因为flags是个array数组,在luajit中,中间元素不能有nil值,否则结果未定义,有可能会被截断,所以我一般不会这么写,会有各种隐患和未定义行为。 |
||
flag = flag:lower():trim() | ||
if flag:find("^[/%-]?mt[d]?$") or flag:find("^[/%-]?md[d]?$") then | ||
flags[key] = nil | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 此处的flags遍历内部直接改写,也处理下吧,我觉得还是有问题的。。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 额知道了,flags并没有被转化,转化的地方弄错了,明天去提交下 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. flags还在遍历过程中,去改flags的元素会有隐患,最好通过一个临时table先存储下修改后的结果,再到循环外更新整个flags 改成, local tmp = {} -- 新建个tmp数组存储新的结果
for _, flag in ipairs(table.wrap(flags)) do -- 此处是array数组遍历,得用ipairs
flag = flag:lower():trim()
if not flag:find("^[/%-]?mt[d]?$") and not flag:find("^[/%-]?md[d]?$") then
table.insert(tmp, flag)
end
end
flags = tmp 而且flags是个array不是dictionary, 通过 $ xmake lua
> a = {1, 2, 3, nil, 5, 6}
> #a -- 这个时候a数组的长度只有3,即使通过ipairs去for循环遍历,也到3就终止了,5跟6就被丢弃了 |
||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 此处可通过 table.wrap(flags) 跟table的处理进行合并统一处理 |
||
target:set(flagsname, flags) | ||
end | ||
|
||
-- remove exists settings | ||
function _mfc_remove_flags(target) | ||
local ldflags = table.wrap(target:get("ldflags")) | ||
for key, ldflag in pairs(ldflags) do | ||
ldflag = ldflag:lower():trim() | ||
if ldflag:find("[/%-]subsystem:") then | ||
ldflags[key] = nil | ||
break | ||
end | ||
end | ||
target:set("ldflags", ldflags) | ||
|
||
-- remove defines MT MTd MD MDd | ||
local defines = table.wrap(target:get("defines")) | ||
for key, define in pairs(defines) do | ||
define = define:lower():trim() | ||
if define:find("^[/%-]?mt[d]?$") or define:find("^[/%-]?md[d]?$") then | ||
defines[key] = nil | ||
end | ||
end | ||
target:set("defines", defines) | ||
|
||
-- remove c /MD,/MT | ||
_mfc_remove_mt_md_flags(target, "cflags") | ||
|
||
-- remove c,cpp /MD,/MT | ||
_mfc_remove_mt_md_flags(target, "cxflags") | ||
|
||
-- remove cpp /MD,/MT | ||
_mfc_remove_mt_md_flags(target, "cxxflags") | ||
end | ||
|
||
-- get application entry | ||
function mfc_application_entry(target) | ||
local defines = target:get("defines") | ||
for key, define in pairs(defines) do | ||
define = define:lower():trim() | ||
if define:find("^[_]?unicode$") then | ||
return "-entry:wWinMainCRTStartup" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 带unicode字样的macro defines说不定会有误判,还是改成 完整匹配 判断吧, define:trim() strip调用空格后判断就行了 define = define:lower():trim()
if define == "unicode" or define == "_unicode" then There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 已调整,的确不太严谨,其他几个flag也加入了校验 |
||
end | ||
end | ||
return "-entry:WinMainCRTStartup" | ||
end | ||
|
||
-- apply shared mfc settings | ||
function mfc_shared(target) | ||
|
||
-- remove some exists flags | ||
_mfc_remove_flags(target) | ||
|
||
-- add flags | ||
target:add("ldflags", "-subsystem:windows", {force = true}) | ||
|
||
-- set runtimelibrary | ||
target:add("cxflags", ifelse(is_mode("debug"), "-MDd", "-MD")) | ||
target:add("defines", "AFX", "_AFXDLL") | ||
end | ||
|
||
-- apply static mfc settings | ||
function mfc_static(target) | ||
|
||
-- remove some exists flags | ||
_mfc_remove_flags(target) | ||
|
||
-- add flags | ||
target:add("ldflags", "-subsystem:windows", {force = true}) | ||
target:add("ldflags", "-force", {force = true}) | ||
|
||
-- set runtimelibrary | ||
target:add("cxflags", ifelse(is_mode("debug"), "-MTd", "-MT")) | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
--!A cross-platform build utility based on Lua | ||
-- | ||
-- Licensed to the Apache Software Foundation (ASF) under one | ||
-- or more contributor license agreements. See the NOTICE file | ||
-- distributed with this work for additional information | ||
-- regarding copyright ownership. The ASF licenses this file | ||
-- to you under the Apache License, Version 2.0 (the | ||
-- "License"); you may not use this file except in compliance | ||
-- with the License. You may obtain a copy of the License at | ||
-- | ||
-- http://www.apache.org/licenses/LICENSE-2.0 | ||
-- | ||
-- Unless required by applicable law or agreed to in writing, software | ||
-- distributed under the License is distributed on an "AS IS" BASIS, | ||
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
-- See the License for the specific language governing permissions and | ||
-- limitations under the License. | ||
-- | ||
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group. | ||
-- | ||
-- @author xigal | ||
-- @file xmake.lua | ||
-- | ||
|
||
-- define rule: shared | ||
rule("win.sdk.mfc.shared") | ||
|
||
-- add mfc base rule | ||
add_deps("win.sdk.mfc.env") | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 通用的环境预加载,可以通过 加个 win.sdk.mfc.env 的依赖规则,优先执行: rule("win.sdk.mfc.env")
-- FIXME: before load need check of vs's minverion, if defined
--before_load(function (target)
--end)
rule("win.sdk.mfcapp.shared")
add_deps("win.sdk.mfc.env")
-- after load
after_load(function (target)
-- apply mfc settings
import("mfc").mfc_shared_app(target)
end)
-- define rule: static mfcapp
rule("win.sdk.mfcapp.static")
add_deps("win.sdk.mfc.env")
-- after load
after_load(function (target)
-- apply mfc settings
import("mfc").mfc_static_app(target)
end) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个是想这样弄的,哈哈,就是当时没发现rule怎么继承另外的rule |
||
-- after load | ||
after_load(function (target) | ||
|
||
-- apply mfc settings | ||
import("mfc").mfc_shared(target) | ||
end) | ||
|
||
-- define rule: static | ||
rule("win.sdk.mfc.static") | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 规则名也改下吧,改成 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个是这样计划的 win.sdk.mfcdll.static,win.sdk.mfcdll.shared,格式比较规整点 |
||
-- add mfc base rule | ||
add_deps("win.sdk.mfc.env") | ||
|
||
-- after load | ||
after_load(function (target) | ||
|
||
-- apply mfc settings | ||
import("mfc").mfc_static(target) | ||
end) | ||
|
||
-- define rule: sharedcapp | ||
rule("win.sdk.mfc.shared_app") | ||
|
||
-- add mfc base rule | ||
add_deps("win.sdk.mfc.shared") | ||
|
||
-- after load | ||
after_load(function (target) | ||
|
||
-- set kind: binary | ||
target:set("kind", "binary") | ||
|
||
-- set entry | ||
target:add("ldflags", import("mfc").mfc_application_entry(target), {force = true}) | ||
end) | ||
|
||
-- define rule: staticapp | ||
rule("win.sdk.mfc.static_app") | ||
|
||
-- add mfc base rule | ||
add_deps("win.sdk.mfc.static") | ||
|
||
-- after load | ||
after_load(function (target) | ||
|
||
-- set kind: binary | ||
target:set("kind", "binary") | ||
|
||
-- set entry | ||
target:add("ldflags", import("mfc").mfc_application_entry(target), {force = true}) | ||
end) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个改成 win.sdk.mfc.env吧