在静态库中使用框架

Use framework in static library

我有一个生成为 .a 文件的库(静态 linked)。我想包括 Qt 框架 (QtCore.framework),因为我在 OSX。那可能吗?我怎么能用 cmake 做到这一点?

我的尝试:

在CMakeLists.txt我有

FIND_LIBRARY(QTCORE_LIBRARY NAMES QtCore
             HINTS "${CMAKE_SOURCE_DIR}/osx/frameworks")

然后我打印变量 ${QTCORE_LIBRARY} 并给出正确的路径。

然后在 src/CMakeLists.txt(我的资源所在的位置)我 link 图书馆 TARGET_LINK_LIBRARIES(库名$${QTCORE_LIBRARY})

然而,当我启动编译时,它会抱怨,因为它没有找到

fatal error: 'QtGlobal' file not found

我检查过 QtCore.framework 包含 QtGlobal header

编辑:如果有人遇到同样的问题,我找到了解决方案。 我需要在我的项目中添加“${QTCORE_LIBRARY}/Headers”包含目录

提前致谢并问候

为什么不使用 Qt5 提供的 CMake "config.cmake"?
类似于:

 # Qt Setting
 set(CMAKE_AUTOMOC ON)
 set(CMAKE_AUTOUIC ON)
 set(CMAKE_AUTORCC ON)
 find_package(Qt5  REQUIRED COMPONENTS Core Gui Widgets)
 ...
 target_link_libraries(libname Qt5::Core Qt5::Gui Qt5::Widgets)

CMake can find and use [...] Qt5 libraries. [...] Qt5 libraries are found using “Config-file Packages” shipped with Qt5

来源:https://cmake.org/cmake/help/latest/manual/cmake-qt.7.html

In order for find_package to be successful, Qt 5 must be found below the CMAKE_PREFIX_PATH, or the Qt5_DIR must be set in the CMake cache to the location of the Qt5WidgetsConfig.cmake file. The easiest way to use CMake is to set the CMAKE_PREFIX_PATH environment variable to the install prefix of Qt 5.

来源:http://doc.qt.io/qt-5/cmake-manual.html