Description | Currently, to specify what Qt4 modules you want to use, you need to use variables which are later checked by FindQt4.cmake and UseQt4.cmake: QT_USE_QTXML, QT_USE_QT, etc
Also, it was possible to specify the minimum Qt version you wanted to use (by means of the QT_MIN_VERSION varible) but not the maximum version.
The attached patch adds support for things like:
FIND_PACKAGE( Qt4 4.4.3 EXACT COMPONENTS QtCore QtXml REQUIRED )
Best of all is the patch does not break source compatibility:
- it is still possible (although discouraged) to use the variables
- it is still possible to use QT_MIN_VERSION to specify the minimum Qt version
When using the COMPONENTS syntax, it is no longer necessary to use INCLUDE(${QT_USE_FILE})
|
Attached Files | FindQt4-use_components_and_version.diff [^] (8,126 bytes) 2009-02-16 12:37 [Show Content] [Hide Content]Index: FindQt4.cmake
===================================================================
RCS file: /cvsroot/CMake/CMake/Modules/FindQt4.cmake,v
retrieving revision 1.151
diff -u -p -d -r1.151 FindQt4.cmake
--- FindQt4.cmake 13 Feb 2009 23:52:02 -0000 1.151
+++ FindQt4.cmake 16 Feb 2009 17:31:34 -0000
@@ -4,9 +4,26 @@
# This qmake is then used to detect basically everything else.
# This module defines a number of key variables and macros.
# First is QT_USE_FILE which is the path to a CMake file that can be included
-# to compile Qt 4 applications and libraries. By default, the QtCore and QtGui
-# libraries are loaded. This behavior can be changed by setting one or more
-# of the following variables to true before doing INCLUDE(${QT_USE_FILE}):
+# to compile Qt 4 applications and libraries.
+#
+# The file pointed to by QT_USE_FILE will set up your compile environment
+# by adding include directories, preprocessor defines, and populate a
+# QT_LIBRARIES variable containing all the Qt libraries and their dependencies.
+# Add the QT_LIBRARIES variable to your TARGET_LINK_LIBRARIES.
+#
+# Typical usage could be something like:
+# FIND_PACKAGE(Qt4 4.4.3 COMPONENTS QtCore QtGui QtXml REQUIRED )
+# ADD_EXECUTABLE(myexe main.cpp)
+# TARGET_LINK_LIBRARIES(myexe ${QT_LIBRARIES})
+#
+# DEPRECATED
+#
+# Before CMake 2.6.4, QtCore and QtGui were enabled by default and variables
+# were used to enable/disable libraries. To keep source compatibility in the
+# CMake 2.6.x series, those variables are still supported but consider them
+# deprecated. They will not be supported from CMake 2.8 on. Before CMake
+# 2.6.3, you enabled libraries by setting one of the following variables to
+# true before doing INCLUDE(${QT_USE_FILE}):
# QT_DONT_USE_QTCORE
# QT_DONT_USE_QTGUI
# QT_USE_QT3SUPPORT
@@ -32,18 +49,14 @@
# QT_USE_QTXMLPATTERNS
# QT_USE_PHONON
#
-# The file pointed to by QT_USE_FILE will set up your compile environment
-# by adding include directories, preprocessor defines, and populate a
-# QT_LIBRARIES variable containing all the Qt libraries and their dependencies.
-# Add the QT_LIBRARIES variable to your TARGET_LINK_LIBRARIES.
-#
-# Typical usage could be something like:
+# Typical usage before CMake 2.6.3 was something like:
# FIND_PACKAGE(Qt4)
# SET(QT_USE_QTXML 1)
# INCLUDE(${QT_USE_FILE})
# ADD_EXECUTABLE(myexe main.cpp)
# TARGET_LINK_LIBRARIES(myexe ${QT_LIBRARIES})
#
+# QT4 TOOLS
#
# There are also some files that need processing by some Qt tools such as moc
# and uic. Listed below are macros that may be used to process those files.
@@ -267,6 +280,26 @@
# (They make no sense in Qt4)
# QT_QT_LIBRARY Qt-Library is now split
+
+# Use FIND_PACKAGE( Qt4 COMPONENTS ... ) to enable modules
+IF( Qt4_FIND_COMPONENTS )
+ FOREACH( component ${Qt4_FIND_COMPONENTS} )
+ STRING( TOUPPER ${component} _COMPONENT )
+ SET( QT_USE_${_COMPONENT} 1 )
+ ENDFOREACH( component )
+
+ # To make sure we don't use QtCore or QtGui when not in COMPONENTS
+ LIST( FIND Qt4_FIND_COMPONENTS "QtCore" _QT_USE_QTCORE )
+ IF( _QT_USE_QTCORE EQUAL -1 )
+ SET( QT_DONT_USE_QTCORE 1 )
+ ENDIF( _QT_USE_QTCORE EQUAL -1 )
+
+ LIST( FIND Qt4_FIND_COMPONENTS "QtGui" _QT_USE_QTGUI )
+ IF( _QT_USE_QTGUI EQUAL -1 )
+ SET( QT_DONT_USE_QTGUI 1 )
+ ENDIF( _QT_USE_QTGUI EQUAL -1 )
+ENDIF( Qt4_FIND_COMPONENTS )
+
# If Qt3 has already been found, fail.
IF(QT_QT_LIBRARY)
IF(Qt4_FIND_REQUIRED)
@@ -288,6 +321,7 @@ SET(QT_USE_FILE ${CMAKE_ROOT}/Modules/Us
SET( QT_DEFINITIONS "")
SET(QT4_INSTALLED_VERSION_TOO_OLD FALSE)
+SET(QT4_INSTALLED_VERSION_TOO_NEW FALSE)
# macro for asking qmake to process pro files
MACRO(QT_QUERY_QMAKE outvar invar)
@@ -372,6 +406,18 @@ IF (QT_QMAKE_EXECUTABLE)
STRING(REGEX REPLACE "^[0-9]+\\.([0-9])+\\.[0-9]+" "\\1" req_qt_minor_vers "${QT_MIN_VERSION}")
STRING(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]+)" "\\1" req_qt_patch_vers "${QT_MIN_VERSION}")
+ # Suppport finding at least a particular version, for instance FIND_PACKAGE( Qt4 4.4.3 )
+ # This implementation is a hack to avoid duplicating code and make sure we stay
+ # source-compatible with CMake 2.6.x
+ # For CMake 2.8, we should not set QT_MIN_VERSION but only use Qt4_FIND_VERSION_MAJOR,
+ # Qt4_FIND_VERSION_MINOR, etc
+ IF( Qt4_FIND_VERSION )
+ SET( QT_MIN_VERSION ${Qt4_FIND_VERSION} )
+ SET( req_qt_major_vers ${Qt4_FIND_VERSION_MAJOR} )
+ SET( req_qt_minor_vers ${Qt4_FIND_VERSION_MINOR} )
+ SET( req_qt_patch_vers ${Qt4_FIND_VERSION_PATCH} )
+ ENDIF( Qt4_FIND_VERSION )
+
IF (NOT req_qt_major_vers EQUAL 4)
MESSAGE( FATAL_ERROR "Invalid Qt version string given: \"${QT_MIN_VERSION}\", major version 4 is required, e.g. \"4.0.1\"")
ENDIF (NOT req_qt_major_vers EQUAL 4)
@@ -385,12 +431,27 @@ IF (QT_QMAKE_EXECUTABLE)
MATH(EXPR req_vers "${req_qt_major_vers}*10000 + ${req_qt_minor_vers}*100 + ${req_qt_patch_vers}")
MATH(EXPR found_vers "${QT_VERSION_MAJOR}*10000 + ${QT_VERSION_MINOR}*100 + ${QT_VERSION_PATCH}")
- IF (found_vers LESS req_vers)
- SET(QT4_QMAKE_FOUND FALSE)
- SET(QT4_INSTALLED_VERSION_TOO_OLD TRUE)
- ELSE (found_vers LESS req_vers)
- SET(QT4_QMAKE_FOUND TRUE)
- ENDIF (found_vers LESS req_vers)
+ # Support finding *exactly* a particular version, for instance FIND_PACKAGE( Qt4 4.4.3 EXACT )
+ # The 'else' branch should be removed for CMake 2.8
+ IF( Qt4_FIND_VERSION_EXACT )
+ IF(found_vers EQUAL req_vers)
+ SET( QT4_QMAKE_FOUND TRUE )
+ ELSE(found_vers EQUAL req_vers)
+ SET( QT4_QMAKE_FOUND FALSE )
+ IF (found_vers LESS req_vers)
+ SET(QT4_INSTALLED_VERSION_TOO_OLD TRUE)
+ ELSE (found_vers LESS req_vers)
+ SET(QT4_INSTALLED_VERSION_TOO_NEW TRUE)
+ ENDIF (found_vers LESS req_vers)
+ ENDIF(found_vers EQUAL req_vers)
+ ELSE( Qt4_FIND_VERSION_EXACT )
+ IF (found_vers LESS req_vers)
+ SET(QT4_QMAKE_FOUND FALSE)
+ SET(QT4_INSTALLED_VERSION_TOO_OLD TRUE)
+ ELSE (found_vers LESS req_vers)
+ SET(QT4_QMAKE_FOUND TRUE)
+ ENDIF (found_vers LESS req_vers)
+ ENDIF( Qt4_FIND_VERSION_EXACT )
ENDIF (qt_version_tmp)
ENDIF (QT_QMAKE_EXECUTABLE)
@@ -1550,11 +1611,23 @@ IF (QT4_QMAKE_FOUND)
ELSE(QT4_QMAKE_FOUND)
SET(QT_QMAKE_EXECUTABLE "${QT_QMAKE_EXECUTABLE}-NOTFOUND" CACHE FILEPATH "Invalid qmake found" FORCE)
+
+ # The code below is overly complex to make sure we do not break compatibility with CMake 2.6.x
+ # For CMake 2.8, it should be simplified by getting rid of QT4_INSTALLED_VERSION_TOO_OLD and
+ # QT4_INSTALLED_VERSION_TOO_NEW
IF(Qt4_FIND_REQUIRED)
IF(QT4_INSTALLED_VERSION_TOO_OLD)
- MESSAGE(FATAL_ERROR "The installed Qt version ${QTVERSION} is too old, at least version ${QT_MIN_VERSION} is required")
+ IF( Qt4_FIND_VERSION_EXACT )
+ MESSAGE(FATAL_ERROR "The installed Qt version ${QTVERSION} is too old, version ${QT_MIN_VERSION} is required")
+ ELSE( Qt4_FIND_VERSION_EXACT )
+ MESSAGE(FATAL_ERROR "The installed Qt version ${QTVERSION} is too old, at least version ${QT_MIN_VERSION} is required")
+ ENDIF( Qt4_FIND_VERSION_EXACT )
ELSE(QT4_INSTALLED_VERSION_TOO_OLD)
- MESSAGE( FATAL_ERROR "Qt qmake not found!")
+ IF( Qt4_FIND_VERSION_EXACT AND QT4_INSTALLED_VERSION_TOO_NEW )
+ MESSAGE(FATAL_ERROR "The installed Qt version ${QTVERSION} is too new, version ${QT_MIN_VERSION} is required")
+ ELSE( Qt4_FIND_VERSION_EXACT AND QT4_INSTALLED_VERSION_TOO_NEW )
+ MESSAGE( FATAL_ERROR "Qt qmake not found!")
+ ENDIF( Qt4_FIND_VERSION_EXACT AND QT4_INSTALLED_VERSION_TOO_NEW )
ENDIF(QT4_INSTALLED_VERSION_TOO_OLD)
ELSE(Qt4_FIND_REQUIRED)
IF(QT4_INSTALLED_VERSION_TOO_OLD AND NOT Qt4_FIND_QUIETLY)
@@ -1564,3 +1637,6 @@ ELSE(QT4_QMAKE_FOUND)
ENDIF (QT4_QMAKE_FOUND)
+IF( Qt4_FIND_COMPONENTS )
+ INCLUDE( ${QT_USE_FILE} )
+ENDIF( Qt4_FIND_COMPONENTS )
|