diff --git a/xmake/modules/package/tools/cmake.lua b/xmake/modules/package/tools/cmake.lua index 7b8aef36077..df930643657 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 b600f3ef6d3..3a3b0078889 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 = ""