Qt 的 CMake 版本分支
CMake version branch for Qt
我的应用程序需要 svg 支持,它已移至必须明确链接的外部模块。这发生在 Qt 5.1 中。如何调整我的 CMakeLists.txt 以区分 minor Qt 版本?
这个例子CMakeLists.txt
应该是一个好的开始
cmake_minimum_required(VERSION 2.8.11)
project(testproject)
# Make sure that CMake can find your Qt installations.
list(APPEND CMAKE_PREFIX_PATH "/path/to/qt5.1")
list(APPEND CMAKE_PREFIX_PATH "/path/to/qt5.2")
list(APPEND CMAKE_PREFIX_PATH "/path/to/qt5.3")
list(APPEND CMAKE_PREFIX_PATH "/path/to/qt5.4")
# ...
# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
# You version switch.
set(MY_QT_VERSION 5.1)
# Find the QtWidgets library
find_package(Qt5Widgets ${MY_QT_VERSION} EXACT REQUIRED)
find_package(Qt5Svg ${MY_QT_VERSION} EXACT REQUIRED)
# Tell CMake to create the helloworld executable
add_executable(helloworld main.cpp)
# Use the Widgets module from Qt 5.
target_link_libraries(helloworld Qt5::Widgets Qt5::Svg)
您可以使用 qmake
查询 Qt 版本,并确保它与您指定的最低版本匹配。
set(QT_MINIMUM_VERSION 5.1.0)
set(QTDIR $ENV{QTDIR} CACHE STRING "Qt install path")
list(APPEND CMAKE_PREFIX_PATH ${QTDIR})
# Test for supported Qt version
find_program(QMAKE NAMES qmake HINTS ${QTDIR} PATH_SUFFIXES bin)
execute_process(COMMAND ${QMAKE} -query QT_VERSION OUTPUT_VARIABLE QT_VERSION)
if(QT_VERSION LESS QT_MINIMUM_VERSION)
MESSAGE(FATAL_ERROR "Minimum supported Qt version: ${QT_MINIMUM_VERSION}.
Installed version: ${QT_VERSION}")
endif()
我的应用程序需要 svg 支持,它已移至必须明确链接的外部模块。这发生在 Qt 5.1 中。如何调整我的 CMakeLists.txt 以区分 minor Qt 版本?
这个例子CMakeLists.txt
应该是一个好的开始
cmake_minimum_required(VERSION 2.8.11)
project(testproject)
# Make sure that CMake can find your Qt installations.
list(APPEND CMAKE_PREFIX_PATH "/path/to/qt5.1")
list(APPEND CMAKE_PREFIX_PATH "/path/to/qt5.2")
list(APPEND CMAKE_PREFIX_PATH "/path/to/qt5.3")
list(APPEND CMAKE_PREFIX_PATH "/path/to/qt5.4")
# ...
# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
# You version switch.
set(MY_QT_VERSION 5.1)
# Find the QtWidgets library
find_package(Qt5Widgets ${MY_QT_VERSION} EXACT REQUIRED)
find_package(Qt5Svg ${MY_QT_VERSION} EXACT REQUIRED)
# Tell CMake to create the helloworld executable
add_executable(helloworld main.cpp)
# Use the Widgets module from Qt 5.
target_link_libraries(helloworld Qt5::Widgets Qt5::Svg)
您可以使用 qmake
查询 Qt 版本,并确保它与您指定的最低版本匹配。
set(QT_MINIMUM_VERSION 5.1.0)
set(QTDIR $ENV{QTDIR} CACHE STRING "Qt install path")
list(APPEND CMAKE_PREFIX_PATH ${QTDIR})
# Test for supported Qt version
find_program(QMAKE NAMES qmake HINTS ${QTDIR} PATH_SUFFIXES bin)
execute_process(COMMAND ${QMAKE} -query QT_VERSION OUTPUT_VARIABLE QT_VERSION)
if(QT_VERSION LESS QT_MINIMUM_VERSION)
MESSAGE(FATAL_ERROR "Minimum supported Qt version: ${QT_MINIMUM_VERSION}.
Installed version: ${QT_VERSION}")
endif()