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 7 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 = target:get(flagsname) | ||
for key, flag in pairs(table.wrap(flags)) do | ||
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 = target:get("ldflags") | ||
for key, ldflag in pairs(table.wrap(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 = target:get("defines") | ||
for key, define in pairs(table.wrap(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吧