Skip to content

Commit d1c2095

Browse files
authored
Merge pull request #5147 from zjyhjqs/fix/android-cmake-find-package
Fix `find_package` failed problem for CMake projects on Android platform
2 parents d58352a + 0d2d893 commit d1c2095

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

xmake/modules/package/tools/cmake.lua

+10
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,13 @@ function _get_configs_for_android(package, configs, opt)
423423
table.insert(configs, "-DCMAKE_MAKE_PROGRAM=" .. make)
424424
end
425425
end
426+
427+
-- avoid find and add system include/library path
428+
-- @see https://github.com/xmake-io/xmake/issues/2037
429+
table.insert(configs, "-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=BOTH")
430+
table.insert(configs, "-DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=BOTH")
431+
table.insert(configs, "-DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=BOTH")
432+
table.insert(configs, "-DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER")
426433
end
427434
_get_configs_for_generic(package, configs, opt)
428435
end
@@ -453,6 +460,7 @@ function _get_configs_for_appleos(package, configs, opt)
453460
envs.CMAKE_SYSTEM_NAME = "Darwin"
454461
end
455462
envs.CMAKE_OSX_ARCHITECTURES = package:arch()
463+
envs.CMAKE_FIND_ROOT_PATH_MODE_PACKAGE = "BOTH"
456464
envs.CMAKE_FIND_ROOT_PATH_MODE_LIBRARY = "BOTH"
457465
envs.CMAKE_FIND_ROOT_PATH_MODE_INCLUDE = "BOTH"
458466
envs.CMAKE_FIND_ROOT_PATH_MODE_FRAMEWORK = "BOTH"
@@ -484,6 +492,7 @@ function _get_configs_for_mingw(package, configs, opt)
484492
-- avoid find and add system include/library path
485493
-- @see https://github.com/xmake-io/xmake/issues/2037
486494
envs.CMAKE_FIND_ROOT_PATH = sdkdir
495+
envs.CMAKE_FIND_ROOT_PATH_MODE_PACKAGE = "BOTH"
487496
envs.CMAKE_FIND_ROOT_PATH_MODE_LIBRARY = "BOTH"
488497
envs.CMAKE_FIND_ROOT_PATH_MODE_INCLUDE = "BOTH"
489498
envs.CMAKE_FIND_ROOT_PATH_MODE_PROGRAM = "NEVER"
@@ -578,6 +587,7 @@ function _get_configs_for_cross(package, configs, opt)
578587
-- avoid find and add system include/library path
579588
-- @see https://github.com/xmake-io/xmake/issues/2037
580589
envs.CMAKE_FIND_ROOT_PATH = sdkdir
590+
envs.CMAKE_FIND_ROOT_PATH_MODE_PACKAGE = "BOTH"
581591
envs.CMAKE_FIND_ROOT_PATH_MODE_LIBRARY = "BOTH"
582592
envs.CMAKE_FIND_ROOT_PATH_MODE_INCLUDE = "BOTH"
583593
envs.CMAKE_FIND_ROOT_PATH_MODE_PROGRAM = "NEVER"

xmake/modules/private/action/trybuild/cmake.lua

+13-4
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,13 @@ function _get_configs_for_android(configs)
134134
if ndk_cxxstl then
135135
table.insert(configs, "-DANDROID_STL=" .. ndk_cxxstl)
136136
end
137+
138+
-- avoid find and add system include/library path
139+
-- @see https://github.com/xmake-io/xmake/issues/2037
140+
table.insert(configs, "-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=BOTH")
141+
table.insert(configs, "-DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=BOTH")
142+
table.insert(configs, "-DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=BOTH")
143+
table.insert(configs, "-DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER")
137144
end
138145
end
139146

@@ -195,8 +202,9 @@ function _get_configs_for_mingw(configs)
195202
-- avoid find and add system include/library path
196203
envs.CMAKE_FIND_ROOT_PATH = sdkdir
197204
envs.CMAKE_SYSROOT = sdkdir
198-
envs.CMAKE_FIND_ROOT_PATH_MODE_LIBRARY = "ONLY"
199-
envs.CMAKE_FIND_ROOT_PATH_MODE_INCLUDE = "ONLY"
205+
envs.CMAKE_FIND_ROOT_PATH_MODE_PACKAGE = "BOTH"
206+
envs.CMAKE_FIND_ROOT_PATH_MODE_LIBRARY = "BOTH"
207+
envs.CMAKE_FIND_ROOT_PATH_MODE_INCLUDE = "BOTH"
200208
envs.CMAKE_FIND_ROOT_PATH_MODE_PROGRAM = "NEVER"
201209
-- avoid add -isysroot on macOS
202210
envs.CMAKE_OSX_SYSROOT = ""
@@ -260,8 +268,9 @@ function _get_configs_for_cross(configs)
260268
-- avoid find and add system include/library path
261269
envs.CMAKE_FIND_ROOT_PATH = sdkdir
262270
envs.CMAKE_SYSROOT = sdkdir
263-
envs.CMAKE_FIND_ROOT_PATH_MODE_LIBRARY = "ONLY"
264-
envs.CMAKE_FIND_ROOT_PATH_MODE_INCLUDE = "ONLY"
271+
envs.CMAKE_FIND_ROOT_PATH_MODE_PACKAGE = "BOTH"
272+
envs.CMAKE_FIND_ROOT_PATH_MODE_LIBRARY = "BOTH"
273+
envs.CMAKE_FIND_ROOT_PATH_MODE_INCLUDE = "BOTH"
265274
envs.CMAKE_FIND_ROOT_PATH_MODE_PROGRAM = "NEVER"
266275
-- avoid add -isysroot on macOS
267276
envs.CMAKE_OSX_SYSROOT = ""

0 commit comments

Comments
 (0)