RuLoViC
RuLoViC

Reputation: 855

Use framework in static library

I have a library which is being generated as .a file (to be statically linked). There I want to include Qt framework (QtCore.framework) since I am on OSX. Is that possible? How could I do it using cmake?

My attempt:

In CMakeLists.txt I have

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

Then I print variable ${QTCORE_LIBRARY} and it gives right path.

Then in src/CMakeLists.txt (where my sources are) I link the library TARGET_LINK_LIBRARIES(libname $${QTCORE_LIBRARY})

However when I launch the compilation it complains because it does not find

fatal error: 'QtGlobal' file not found

I have checked and QtCore.framework contains QtGlobal header

EDIT: In case someone has same problem I found solution. I needed to add "${QTCORE_LIBRARY}/Headers" in my project include directories

Thanks in advance and regards

Upvotes: 0

Views: 670

Answers (1)

Mizux
Mizux

Reputation: 9309

Why don't using the CMake "config.cmake" provided by Qt5 ?
something like:

 # 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

src: 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.

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

Upvotes: 2

Related Questions