库“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
找不到“酒吧”。我用过
-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
option 值,但是当它在文件系统中实际执行包搜索时它会忽略该文件夹。我怎么知道
find_package
不忽略指定给 PATHS
的文件夹为 iOS 交叉编译时的选项?环境:macOS 10.14.6、Xcode 11.2.1、CMake 3.19.2(通过 Homebrew 安装)。
最佳答案
我目前已将此添加到我的 CMakeLists.txt,在我设置的位置之间 BAR_INSTALLATION_PREFIX
以及我调用的地方 find_package
:
if (${CMAKE_SYSTEM_NAME} STREQUAL "iOS")
set ( bar_DIR "${BAR_INSTALLATION_PREFIX}/lib/bar" )
endif()
这设置了 <PackageName>_DIR
变量到包的配置文件 ( bar-config.cmake
) 所在的具体文件夹。根据CMake docs这也可以设置为环境变量。它并不漂亮,并且它比我想要的更多地将项目“foo”与其依赖项“bar”结合在一起,但作为一种解决方法,它暂时可以这样做。
我不会将此答案标记为“已接受”,以防具有更多 CMake 知识的人提出真正的解决方案。
关于ios - CMake find_package 在为 iOS 构建时忽略 PATHS 选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65494246/