summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2018-09-06 19:12:52 +0800
committerGitHub <[email protected]>2018-09-06 19:12:52 +0800
commite4d6de3fa21809d29484eda04c33985b4b891adb (patch)
tree85ba39dae186918f53c431c7f09278a48291f582
parent9f330ff3c528cdda8718a0c086f1681322b13e80 (diff)
parente8af37c32549f54059f6e7635064c623b80c039c (diff)
Merge pull request #216 from xigalto/dev
add windows mfc rule
-rw-r--r--xmake/rules/winsdk/mfc/env/xmake.lua30
-rw-r--r--xmake/rules/winsdk/mfc/mfc.lua107
-rw-r--r--xmake/rules/winsdk/mfc/xmake.lua81
-rw-r--r--xmake/rules/winsdk/xmake.lua3
4 files changed, 219 insertions, 2 deletions
diff --git a/xmake/rules/winsdk/mfc/env/xmake.lua b/xmake/rules/winsdk/mfc/env/xmake.lua
new file mode 100644
index 000000000..38ce77925
--- /dev/null
+++ b/xmake/rules/winsdk/mfc/env/xmake.lua
@@ -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) \ No newline at end of file
diff --git a/xmake/rules/winsdk/mfc/mfc.lua b/xmake/rules/winsdk/mfc/mfc.lua
new file mode 100644
index 000000000..b51ab0733
--- /dev/null
+++ b/xmake/rules/winsdk/mfc/mfc.lua
@@ -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
+--
+
+-- remove exists md or mt
+function _mfc_remove_mt_md_flags(target, flagsname)
+ local flags = table.wrap(target:get(flagsname))
+ for i = #flags, 1, -1 do
+ flag = flags[i]:lower():trim()
+ if flag:find("^[/%-]?mt[d]?$") or flag:find("^[/%-]?md[d]?$") then
+ table.remove(flags, i)
+ end
+ end
+ target:set(flagsname, flags)
+end
+
+-- remove exists settings
+function _mfc_remove_flags(target)
+ local ldflags = table.wrap(target:get("ldflags"))
+ for i = #ldflags, 1, -1 do
+ ldflag = ldflags[i]:lower():trim()
+ if ldflag:find("[/%-]subsystem:") then
+ table.remove(ldflags, i)
+ break
+ end
+ end
+ target:set("ldflags", ldflags)
+
+ -- remove defines MT MTd MD MDd
+ local defines = table.wrap(target:get("defines"))
+ for i = #defines, 1, -1 do
+ define = defines[i]:lower():trim()
+ if define:find("^[/%-]?mt[d]?$") or define:find("^[/%-]?md[d]?$") then
+ table.remove(defines, i)
+ 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"
+ 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 \ No newline at end of file
diff --git a/xmake/rules/winsdk/mfc/xmake.lua b/xmake/rules/winsdk/mfc/xmake.lua
new file mode 100644
index 000000000..d22752a94
--- /dev/null
+++ b/xmake/rules/winsdk/mfc/xmake.lua
@@ -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")
+
+ -- after load
+ after_load(function (target)
+
+ -- apply mfc settings
+ import("mfc").mfc_shared(target)
+ end)
+
+-- define rule: static
+rule("win.sdk.mfc.static")
+
+ -- 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) \ No newline at end of file
diff --git a/xmake/rules/winsdk/xmake.lua b/xmake/rules/winsdk/xmake.lua
index 9e389de36..123829019 100644
--- a/xmake/rules/winsdk/xmake.lua
+++ b/xmake/rules/winsdk/xmake.lua
@@ -51,5 +51,4 @@ rule("win.sdk.application")
target:add("links", "kernel32", "user32", "gdi32", "winspool", "comdlg32", "advapi32")
target:add("links", "shell32", "ole32", "oleaut32", "uuid", "odbc32", "odbccp32", "comctl32")
target:add("links", "cfgmgr32", "comdlg32", "setupapi", "strsafe", "shlwapi")
- end)
-
+ end) \ No newline at end of file