Skip to content

Commit

Permalink
Merge pull request #5147 from zjyhjqs/fix/android-cmake-find-package
Browse files Browse the repository at this point in the history
Fix `find_package` failed problem for CMake projects on Android platform
  • Loading branch information
waruqi authored May 27, 2024
2 parents d58352a + 0d2d893 commit d1c2095
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
10 changes: 10 additions & 0 deletions xmake/modules/package/tools/cmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
17 changes: 13 additions & 4 deletions xmake/modules/private/action/trybuild/cmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 = ""
Expand Down Expand Up @@ -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 = ""
Expand Down

0 comments on commit d1c2095

Please sign in to comment.