summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2024-05-27 15:45:14 +0800
committerGitHub <[email protected]>2024-05-27 15:45:14 +0800
commitd1c2095855bcf6633aeffac98c1b03bca0978f8a (patch)
tree39f7463fd5b8b99a1087283de987e62e3d5c0da7
parentd58352a36f0ee20e302e09fb9b0400695ff665b8 (diff)
parent0d2d893015954d08539a7b948f60b1bb04512732 (diff)
Merge pull request #5147 from zjyhjqs/fix/android-cmake-find-package
Fix `find_package` failed problem for CMake projects on Android platform
-rw-r--r--xmake/modules/package/tools/cmake.lua10
-rw-r--r--xmake/modules/private/action/trybuild/cmake.lua17
2 files changed, 23 insertions, 4 deletions
diff --git a/xmake/modules/package/tools/cmake.lua b/xmake/modules/package/tools/cmake.lua
index 7b8aef360..df9306436 100644
--- a/xmake/modules/package/tools/cmake.lua
+++ b/xmake/modules/package/tools/cmake.lua
@@ -423,6 +423,13 @@ function _get_configs_for_android(package, configs, opt)
table.insert(configs, "-DCMAKE_MAKE_PROGRAM=" .. make)
end
end
+
+ -- avoid find and add system include/library path
+ -- @see https://github.com/xmake-io/xmake/issues/2037
+ table.insert(configs, "-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=BOTH")
+ table.insert(configs, "-DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=BOTH")
+ table.insert(configs, "-DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=BOTH")
+ table.insert(configs, "-DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER")
end
_get_configs_for_generic(package, configs, opt)
end
@@ -453,6 +460,7 @@ function _get_configs_for_appleos(package, configs, opt)
envs.CMAKE_SYSTEM_NAME = "Darwin"
end
envs.CMAKE_OSX_ARCHITECTURES = package:arch()
+ envs.CMAKE_FIND_ROOT_PATH_MODE_PACKAGE = "BOTH"
envs.CMAKE_FIND_ROOT_PATH_MODE_LIBRARY = "BOTH"
envs.CMAKE_FIND_ROOT_PATH_MODE_INCLUDE = "BOTH"
envs.CMAKE_FIND_ROOT_PATH_MODE_FRAMEWORK = "BOTH"
@@ -484,6 +492,7 @@ function _get_configs_for_mingw(package, configs, opt)
-- avoid find and add system include/library path
-- @see https://github.com/xmake-io/xmake/issues/2037
envs.CMAKE_FIND_ROOT_PATH = sdkdir
+ envs.CMAKE_FIND_ROOT_PATH_MODE_PACKAGE = "BOTH"
envs.CMAKE_FIND_ROOT_PATH_MODE_LIBRARY = "BOTH"
envs.CMAKE_FIND_ROOT_PATH_MODE_INCLUDE = "BOTH"
envs.CMAKE_FIND_ROOT_PATH_MODE_PROGRAM = "NEVER"
@@ -578,6 +587,7 @@ function _get_configs_for_cross(package, configs, opt)
-- avoid find and add system include/library path
-- @see https://github.com/xmake-io/xmake/issues/2037
envs.CMAKE_FIND_ROOT_PATH = sdkdir
+ envs.CMAKE_FIND_ROOT_PATH_MODE_PACKAGE = "BOTH"
envs.CMAKE_FIND_ROOT_PATH_MODE_LIBRARY = "BOTH"
envs.CMAKE_FIND_ROOT_PATH_MODE_INCLUDE = "BOTH"
envs.CMAKE_FIND_ROOT_PATH_MODE_PROGRAM = "NEVER"
diff --git a/xmake/modules/private/action/trybuild/cmake.lua b/xmake/modules/private/action/trybuild/cmake.lua
index b600f3ef6..3a3b00788 100644
--- a/xmake/modules/private/action/trybuild/cmake.lua
+++ b/xmake/modules/private/action/trybuild/cmake.lua
@@ -134,6 +134,13 @@ function _get_configs_for_android(configs)
if ndk_cxxstl then
table.insert(configs, "-DANDROID_STL=" .. ndk_cxxstl)
end
+
+ -- avoid find and add system include/library path
+ -- @see https://github.com/xmake-io/xmake/issues/2037
+ table.insert(configs, "-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=BOTH")
+ table.insert(configs, "-DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=BOTH")
+ table.insert(configs, "-DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=BOTH")
+ table.insert(configs, "-DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER")
end
end
@@ -195,8 +202,9 @@ function _get_configs_for_mingw(configs)
-- avoid find and add system include/library path
envs.CMAKE_FIND_ROOT_PATH = sdkdir
envs.CMAKE_SYSROOT = sdkdir
- envs.CMAKE_FIND_ROOT_PATH_MODE_LIBRARY = "ONLY"
- envs.CMAKE_FIND_ROOT_PATH_MODE_INCLUDE = "ONLY"
+ envs.CMAKE_FIND_ROOT_PATH_MODE_PACKAGE = "BOTH"
+ envs.CMAKE_FIND_ROOT_PATH_MODE_LIBRARY = "BOTH"
+ envs.CMAKE_FIND_ROOT_PATH_MODE_INCLUDE = "BOTH"
envs.CMAKE_FIND_ROOT_PATH_MODE_PROGRAM = "NEVER"
-- avoid add -isysroot on macOS
envs.CMAKE_OSX_SYSROOT = ""
@@ -260,8 +268,9 @@ function _get_configs_for_cross(configs)
-- avoid find and add system include/library path
envs.CMAKE_FIND_ROOT_PATH = sdkdir
envs.CMAKE_SYSROOT = sdkdir
- envs.CMAKE_FIND_ROOT_PATH_MODE_LIBRARY = "ONLY"
- envs.CMAKE_FIND_ROOT_PATH_MODE_INCLUDE = "ONLY"
+ envs.CMAKE_FIND_ROOT_PATH_MODE_PACKAGE = "BOTH"
+ envs.CMAKE_FIND_ROOT_PATH_MODE_LIBRARY = "BOTH"
+ envs.CMAKE_FIND_ROOT_PATH_MODE_INCLUDE = "BOTH"
envs.CMAKE_FIND_ROOT_PATH_MODE_PROGRAM = "NEVER"
-- avoid add -isysroot on macOS
envs.CMAKE_OSX_SYSROOT = ""