summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2023-07-25 22:42:58 +0800
committerruki <[email protected]>2023-07-25 22:42:58 +0800
commitaf51876bc9ff2c76b76eb4c4fc01c8220e61f248 (patch)
treed673787e7b627f9f2d6e8c7e2639af285a02851b
parent4ee7331a38389823dbae056409ecd3922296227e (diff)
add linker.soname rule
-rw-r--r--xmake/core/project/target.lua2
-rw-r--r--xmake/rules/linker/soname/xmake.lua34
-rw-r--r--xmake/rules/linker/xmake.lua1
3 files changed, 37 insertions, 0 deletions
diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua
index 249858c1b..4d9a49150 100644
--- a/xmake/core/project/target.lua
+++ b/xmake/core/project/target.lua
@@ -647,6 +647,8 @@ function _instance:version()
end
-- get the target soname
+-- @see https://github.com/tboox/tbox/issues/214
+--
-- set_version("1.0.1", {soname = "1.0"}) -> libfoo.so.1.0, libfoo.1.0.dylib
-- set_version("1.0.1", {soname = "1"}) -> libfoo.so.1, libfoo.1.dylib
-- set_version("1.0.1", {soname = true}) -> libfoo.so.1, libfoo.1.dylib
diff --git a/xmake/rules/linker/soname/xmake.lua b/xmake/rules/linker/soname/xmake.lua
new file mode 100644
index 000000000..cd4d20221
--- /dev/null
+++ b/xmake/rules/linker/soname/xmake.lua
@@ -0,0 +1,34 @@
+--!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("linker.soname")
+ on_config(function (target)
+ local soname = target:soname()
+ if target:is_shared() and soname then
+ if target:has_tool("sh", "gcc", "gxx", "clang", "clangxx") then
+ if target:is_plat("macosx", "iphoneos", "watchos", "appletvos") then
+ target:add("shflags", "-Wl,-install_name," .. soname, {force = true})
+ else
+ target:add("shflags", "-Wl,-soname," .. soname, {force = true})
+ end
+ end
+ end
+ end)
+
diff --git a/xmake/rules/linker/xmake.lua b/xmake/rules/linker/xmake.lua
index 602eecdfe..c4632d6cf 100644
--- a/xmake/rules/linker/xmake.lua
+++ b/xmake/rules/linker/xmake.lua
@@ -21,4 +21,5 @@
rule("linker")
add_deps("linker.link_scripts")
add_deps("linker.version_scripts")
+ add_deps("linker.soname")