Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix find_package failed problem for CMake projects on Android platform #5147

Merged
merged 3 commits into from
May 27, 2024

Conversation

zjyhjqs
Copy link
Contributor

@zjyhjqs zjyhjqs commented May 26, 2024

相关issue: #2037


NDK环境设置了CMAKE_FIND_ROOT_PATH/CMAKE_SYSROOT_PATH, 会导致CMake工程在find_package时因CMAKE_PREFIX_PATH策略变更, 从而安装失败.

先前相关修改处理了其它交叉编译的平台, 但未处理Android平台. 且遗漏了CMAKE_FIND_ROOT_PATH_MODE_PACKAGE


但目前的改法仍未解决一个问题:

CMake的Module mode比Config mode优先级更高, 导致CMake官方提供了Module脚本的库:

  1. 在系统中被找到, 不做任何处理的情况下xrepo准备的依赖会被系统库所覆盖
  2. 直接报错退出

(即CMAKE_PREFIX_PATH被忽略了)

这我能想到的有两种方案:

  1. 考虑全局设置CMAKE_FIND_PACKAGE_PREFER_CONFIGTRUE, 但这样的话xrepo需要大规模测试

  2. 设置CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATHFALSE. 这会导致系统环境变量的工具无法被找到 (如make, ninja). 应该需要单独配置CMAKE_MAKE_PROGRAM的路径

@zjyhjqs zjyhjqs marked this pull request as ready for review May 26, 2024 14:27
@zjyhjqs zjyhjqs force-pushed the fix/android-cmake-find-package branch from e19da02 to 0d2d893 Compare May 26, 2024 14:45
@waruqi waruqi added this to the v2.9.3 milestone May 27, 2024
@waruqi waruqi requested a review from xq114 May 27, 2024 07:36
@waruqi
Copy link
Member

waruqi commented May 27, 2024

但目前的改法仍未解决一个问题:

CMake的Module mode比Config mode优先级更高, 导致CMake官方提供了Module脚本的库:

  1. 在系统中被找到, 不做任何处理的情况下xrepo准备的依赖会被系统库所覆盖
  2. 直接报错退出

尽可能保持最小改动,避免 break 现有包的风险,如果没法规避部分小概率 case 下让 cmake 找到库,那么就直接走 patch 直接去干掉 cmakelists.txt 的 FindXXX 然后 cmake.install("xxx", configs, {packagedeps = "xxx"}) 强行打入依赖就行了。。

目前 xmake-repo 里面一些包就是这么干的。。

考虑全局设置CMAKE_FIND_PACKAGE_PREFER_CONFIG为TRUE, 但这样的话xrepo需要大规模测试

即使这种方式有效,也不用全局加,风险太大,可以在遇到此类问题包的时候,在这个包的 on_install 里面,单独开启 CMAKE_FIND_PACKAGE_PREFER_CONFIG 先看看行不行,如果这种情况很少见,就直接包里面配置就行了。。如果后面遇到的多了。。并且测试下来 都没啥副作用,那么再挪到全局也就无所谓了

@waruqi
Copy link
Member

waruqi commented May 27, 2024

这边暂时先 merge 了,我不确定是否会有什么副作用,你们自己多测试吧

@waruqi waruqi merged commit d1c2095 into xmake-io:master May 27, 2024
19 checks passed
@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


I'm merging here for the time being. I'm not sure if there will be any side effects. You can test it yourself.

@waruqi
Copy link
Member

waruqi commented May 27, 2024

记得下回提 patch 时候,提到 dev 分支

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Remember to mention the dev branch next time when you mention patch

@zjyhjqs
Copy link
Contributor Author

zjyhjqs commented May 27, 2024

记得下回提 patch 时候,提到 dev 分支

提交时没仔细看😱,不好意思

@xq114
Copy link
Contributor

xq114 commented May 27, 2024

我记得本来就有这个参数的,config/module的控制 #2576

@waruqi
Copy link
Member

waruqi commented May 27, 2024

我记得本来就有这个参数的,config/module的控制 #2576

那是 cmake::xxx 包的参数,不是 xmake-repo 里面 cmake 包的参数。

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Remember to mention the dev branch next time when you mention patch

I didn’t read it carefully when I submitted it, sorry.

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


I remember this parameter existed, config/module control #2576

That is a parameter of the cmake::xxx package, not a parameter of the cmake package in xmake-repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants