summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2021-02-22 22:38:54 +0800
committerruki <[email protected]>2021-02-22 22:38:54 +0800
commit3a579c246f983da7a91bc870a8395a6227ac93c7 (patch)
tree11b74074a26f86e4e6ee20c8fbbe53f48e8a5d20
parentf78a823f3cc8f1b1d71bbd8882a1881c99834aa6 (diff)
add manifest rule
-rw-r--r--tests/projects/c++/manifest/src/main.cpp9
-rw-r--r--tests/projects/c++/manifest/src/main.manifest10
-rw-r--r--tests/projects/c++/manifest/xmake.lua6
-rw-r--r--xmake/modules/core/tools/link.lua19
-rw-r--r--xmake/rules/c++/xmake.lua8
-rw-r--r--xmake/rules/platform/windows/manifest/xmake.lua30
-rw-r--r--xmake/rules/platform/xmake.lua23
7 files changed, 92 insertions, 13 deletions
diff --git a/tests/projects/c++/manifest/src/main.cpp b/tests/projects/c++/manifest/src/main.cpp
new file mode 100644
index 000000000..db2361659
--- /dev/null
+++ b/tests/projects/c++/manifest/src/main.cpp
@@ -0,0 +1,9 @@
+#include <iostream>
+
+using namespace std;
+
+int main(int argc, char** argv)
+{
+ cout << "hello world!" << endl;
+ return 0;
+}
diff --git a/tests/projects/c++/manifest/src/main.manifest b/tests/projects/c++/manifest/src/main.manifest
new file mode 100644
index 000000000..1c06b6190
--- /dev/null
+++ b/tests/projects/c++/manifest/src/main.manifest
@@ -0,0 +1,10 @@
+<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
+<assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'>
+ <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
+ <security>
+ <requestedPrivileges>
+ <requestedExecutionLevel level='asInvoker' uiAccess='false' />
+ </requestedPrivileges>
+ </security>
+ </trustInfo>
+</assembly>
diff --git a/tests/projects/c++/manifest/xmake.lua b/tests/projects/c++/manifest/xmake.lua
new file mode 100644
index 000000000..121530a0c
--- /dev/null
+++ b/tests/projects/c++/manifest/xmake.lua
@@ -0,0 +1,6 @@
+add_rules("mode.debug", "mode.release")
+target("test")
+ set_kind("binary")
+ add_files("src/*.cpp")
+ add_files("src/*.manifest")
+
diff --git a/xmake/modules/core/tools/link.lua b/xmake/modules/core/tools/link.lua
index 9a70de9ce..3994bbab4 100644
--- a/xmake/modules/core/tools/link.lua
+++ b/xmake/modules/core/tools/link.lua
@@ -58,16 +58,19 @@ function get(self, name)
end
-- make the strip flag
-function nf_strip(self, level)
+function nf_strip(self, level, target)
-- @note we explicitly strip some useless code, because `/debug` may keep them
-- @see https://github.com/xmake-io/xmake/issues/907
- --
- local maps =
- {
- debug = "/opt:ref /opt:icf"
- , all = "/opt:ref /opt:icf /ltcg" -- we enable /ltcg for optimize/smallest:/Gl
- }
- return maps[level]
+ if level == "all" then
+ -- we enable /ltcg for optimize/smallest:/Gl
+ local flags = {"/opt:ref", "/opt:icf"}
+ if target and target:get("optimize") == "smallest" then
+ table.insert(flags, "/ltcg")
+ end
+ return flags
+ elseif level == "debug" then
+ return {"/opt:ref", "/opt:icf"}
+ end
end
-- make the symbol flag
diff --git a/xmake/rules/c++/xmake.lua b/xmake/rules/c++/xmake.lua
index 1b188566a..14dc961d3 100644
--- a/xmake/rules/c++/xmake.lua
+++ b/xmake/rules/c++/xmake.lua
@@ -18,31 +18,26 @@
-- @file xmake.lua
--
--- define rule: c.build.pcheader
rule("c.build.pcheader")
before_build(function (target, opt)
import("private.action.build.pcheader")(target, "c", opt)
end)
--- define rule: c.build
rule("c.build")
set_sourcekinds("cc")
add_deps("c.build.pcheader")
on_build_files("private.action.build.object", {batch = true})
--- define rule: c++.build.pcheader
rule("c++.build.pcheader")
before_build(function (target, opt)
import("private.action.build.pcheader")(target, "cxx", opt)
end)
--- define rule: c++.build
rule("c++.build")
set_sourcekinds("cxx")
add_deps("c++.build.pcheader", "c++.build.modules")
on_build_files("private.action.build.object", {batch = true})
--- define rule: cpp
rule("c++")
-- add build rules
@@ -66,3 +61,6 @@ rule("c++")
-- check licenses
add_deps("utils.check.licenses")
+
+ -- add platform rules
+ add_deps("platform.windows")
diff --git a/xmake/rules/platform/windows/manifest/xmake.lua b/xmake/rules/platform/windows/manifest/xmake.lua
new file mode 100644
index 000000000..63fb57622
--- /dev/null
+++ b/xmake/rules/platform/windows/manifest/xmake.lua
@@ -0,0 +1,30 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed 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-present, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file xmake.lua
+--
+
+-- add *.manifest for windows
+rule("platform.windows.manifest")
+ set_extensions(".manifest")
+ before_build_file("windows", function (target, sourcefile)
+ local _, toolname = target:tool("ld")
+ if toolname == "link" then
+ target:add("ldflags", "/manifest", "/ManifestFile:" .. path.translate(sourcefile), {force = true})
+ end
+ end)
+
diff --git a/xmake/rules/platform/xmake.lua b/xmake/rules/platform/xmake.lua
new file mode 100644
index 000000000..3bd9b51eb
--- /dev/null
+++ b/xmake/rules/platform/xmake.lua
@@ -0,0 +1,23 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed 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-present, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file xmake.lua
+--
+
+rule("platform.windows")
+ add_deps("platform.windows.manifest")
+