【发布时间】:2021-04-06 04:57:42
【问题描述】:
库“foo”依赖于库“bar”。这两个库的构建系统都基于 CMake。库“bar”提供了下游项目可以使用的 CMake 包,例如库“foo”。
“foo”通过 Git 子模块集成“bar”。 "foo" 期望 "bar" 被构建并安装在特定位置的子模块路径中。文件夹结构如下所示:
/path/to/foo
+-- bar <-- "bar" Git submodule
| +-- build <-- "bar" out-of-source build folder
| +-- install <-- "bar" installation folder
+-- build <-- "foo" out-of-source build folder
+-- CMakeLists.txt
这是“foo”的简约 CMakeLists.txt,显示了我正在使用的 find_package 调用:
project ( foo )
set ( BAR_INSTALLATION_PREFIX "${CMAKE_CURRENT_SOURCE_DIR}/bar/build/install" )
find_package (
bar
0.1
EXACT
QUIET
PATHS ${BAR_INSTALLATION_PREFIX}
)
这很好用,即find_package 找到“bar”,只要我为主机平台 macOS 构建“foo”。但是,当我尝试为 iOS 交叉编译“foo”时,find_package 找不到“bar”。
我使用-DCMAKE_FIND_DEBUG_MODE=ON 来诊断问题,看来find_package 只是忽略了为PATHS 选项指定的文件夹。这是我在诊断期间遇到的仍然存在问题的简约命令行:
cmake .. -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_FIND_DEBUG_MODE=ON
这是我看到的输出的相关部分:
[...]
Paths specified by the find_package PATHS option.
/Users/patrick/dev/foo/bar/build/install
find_package considered the following locations for the Config module:
/Applications/Xcode-11.2.1.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.2.sdk/usr/barConfig.cmake
/Applications/Xcode-11.2.1.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.2.sdk/usr/bar-config.cmake
/Applications/Xcode-11.2.1.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.2.sdk/barConfig.cmake
/Applications/Xcode-11.2.1.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.2.sdk/bar-config.cmake
/Applications/Xcode-11.2.1.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.2.sdk/usr/barConfig.cmake
/Applications/Xcode-11.2.1.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.2.sdk/usr/bar-config.cmake
/Applications/Xcode-11.2.1.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.2.sdk/System/Library/Frameworks/barConfig.cmake
/Applications/Xcode-11.2.1.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.2.sdk/System/Library/Frameworks/bar-config.cmake
/Applications/Xcode-11.2.1.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.2.sdk/System/Library/Frameworks/barConfig.cmake
/Applications/Xcode-11.2.1.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.2.sdk/System/Library/Frameworks/bar-config.cmake
The file was not found.
[...]
可以看出find_package 最初识别PATHS 选项值,但随后它在文件系统中实际执行包搜索时忽略了该文件夹。
如何告诉find_package 在交叉编译iOS 时不要忽略PATHS 选项指定的文件夹?
环境:macOS 10.14.6、Xcode 11.2.1、CMake 3.19.2(通过 Homebrew 安装)。
【问题讨论】:
标签: ios cmake cross-compiling