我的应用程序需要svg支持,svg被移动到一个外部模块,必须进行明确的链接。这发生在Qt 5.1中。如何调整我的CMakeLists.txt以区分次要的 Qt值?
发布于 2015-03-24 21:18:12
这个示例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)更多细节可以在qt.io或这里上找到。
发布于 2016-03-25 22:48:47
您可以使用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()https://stackoverflow.com/questions/29234328
复制相似问题