我的应用程序需要svg支持,该支持已移至外部模块,必须明确链接。这发生在Qt 5.1中。如何调整我的CMakeLists.txt以区分 次要 Qt版本?
答案 0 :(得分:1)
此示例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)
答案 1 :(得分:1)
您可以使用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()