且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用通过CMake中的brew安装的Qwt

更新时间:2023-10-22 22:51:10

假定您已经熟悉

Assuming that you are already familiar with cmake/qt basics, this is my proposal:

if(APPLE)
    set(CMAKE_FIND_FRAMEWORK ONLY)
    find_library(QWT
        NAMES qwt
        HINTS /usr/local/opt/qwt/lib/
        REQUIRED)
    if(QWT)
        include_directories(${QWT}/Headers)
        link_libraries(${QWT})
        message("QWT found: ${QWT}")
    endif()
endif()

CMake变量 CMAKE_FIND_FRAMEWORK 影响find_ *命令如何选择macOS框架和Unix风格的dylib.您可能会注意到,使用上面的代码片段输出执行cmake:

The CMake variable CMAKE_FIND_FRAMEWORK affects how find_* commands choose between macOS Frameworks and unix-style dylibs. You may observe that executing cmake with the above snippet outputs:

QWT found: /usr/local/Cellar/qwt/6.1.4/lib/qwt.framework

此代码段将qwt框架添加到CMakeLists.txt中定义的任何目标,但是您可能更喜欢将链接部分仅应用于一个目标,如下所示:

This snippet adds the qwt framework to any target defined in your CMakeLists.txt, but you may prefer to apply the link part to only one target, like this:

target_link_libraries(yourtarget ${QWT})

另一个警告:您应该将程序链接到由Qwt链接的相同Qt5框架,并且也要通过brew安装:QTDIR =/usr/local/opt/qt5

Another caveat: you should link your program to the same Qt5 frameworks linked by Qwt, and also installed by brew: QTDIR=/usr/local/opt/qt5