From 23abf548e56120fbc3c535d1fa1bd8ac9609cbb5 Mon Sep 17 00:00:00 2001 From: "Uwe L. Korn" Date: Wed, 26 Feb 2014 09:15:45 +0000 Subject: [PATCH] Fix Qt5 compilation when only qt4-qmake is in the PATH --- cmake/modules/FindQt.cmake | 44 ++++++++++++++++++++++++------------- cmake/modules/FindQt5.cmake | 53 ++++++++++++++++++++++++++------------------- 2 files changed, 60 insertions(+), 37 deletions(-) diff --git a/cmake/modules/FindQt.cmake b/cmake/modules/FindQt.cmake index 8cf0f25..562da35 100644 --- a/cmake/modules/FindQt.cmake +++ b/cmake/modules/FindQt.cmake @@ -7,22 +7,36 @@ # Redistribution and use is allowed according to the terms of the BSD license. # For details see the accompanying COPYING-CMAKE-SCRIPTS file. -IF(NOT QT_QMAKE_EXECUTABLE) - FIND_PROGRAM(QT_QMAKE_EXECUTABLE_FINDQT NAMES qmake qmake4 qmake-qt4 qmake5 qmake-qt5 - PATHS "${QT_SEARCH_PATH}/bin" "$ENV{QTDIR}/bin") - SET(QT_QMAKE_EXECUTABLE ${QT_QMAKE_EXECUTABLE_FINDQT} CACHE PATH "Qt qmake program.") -ENDIF(NOT QT_QMAKE_EXECUTABLE) +IF(DESIRED_QT_VERSION MATCHES 5) + # Qt5 was explicitly requested, so use its CMakeConfig instead of qmake which may not be at a global location + find_package(Qt5Core QUIET) + IF( Qt5Core_DIR ) + SET(QT_VERSION_MAJOR ${Qt5Core_VERSION_MAJOR}) + SET(QT_VERSION_MINOR ${Qt5Core_VERSION_MINOR}) + SET(QT_VERSION_PATCH ${Qt5Core_VERSION_PATCH}) + SET(QT_VERSION ${Qt5Core_VERSION}) + SET(QT5_INSTALLED TRUE) + ENDIF( Qt5Core_DIR ) +ENDIF(DESIRED_QT_VERSION MATCHES 5) + +IF(NOT QT_VERSION) + IF(NOT QT_QMAKE_EXECUTABLE) + FIND_PROGRAM(QT_QMAKE_EXECUTABLE_FINDQT NAMES qmake qmake4 qmake-qt4 qmake5 qmake-qt5 + PATHS "${QT_SEARCH_PATH}/bin" "$ENV{QTDIR}/bin") + SET(QT_QMAKE_EXECUTABLE ${QT_QMAKE_EXECUTABLE_FINDQT} CACHE PATH "Qt qmake program.") + ENDIF(NOT QT_QMAKE_EXECUTABLE) -# now find qmake -IF(QT_QMAKE_EXECUTABLE) - EXEC_PROGRAM(${QT_QMAKE_EXECUTABLE} ARGS "-query QT_VERSION" OUTPUT_VARIABLE QTVERSION) - IF(QTVERSION MATCHES "4.*") - SET(QT4_INSTALLED TRUE) - ENDIF(QTVERSION MATCHES "4.*") - IF(QTVERSION MATCHES "5.*") - SET(QT5_INSTALLED TRUE) - ENDIF(QTVERSION MATCHES "5.*") -ENDIF(QT_QMAKE_EXECUTABLE) + # now find qmake + IF(QT_QMAKE_EXECUTABLE) + EXEC_PROGRAM(${QT_QMAKE_EXECUTABLE} ARGS "-query QT_VERSION" OUTPUT_VARIABLE QTVERSION) + IF(QTVERSION MATCHES "4.*") + SET(QT4_INSTALLED TRUE) + ENDIF(QTVERSION MATCHES "4.*") + IF(QTVERSION MATCHES "5.*") + SET(QT5_INSTALLED TRUE) + ENDIF(QTVERSION MATCHES "5.*") + ENDIF(QT_QMAKE_EXECUTABLE) +ENDIF(NOT QT_VERSION) IF(NOT DESIRED_QT_VERSION) IF(QT4_INSTALLED) diff --git a/cmake/modules/FindQt5.cmake b/cmake/modules/FindQt5.cmake index 922ebc1..957f7b3 100644 --- a/cmake/modules/FindQt5.cmake +++ b/cmake/modules/FindQt5.cmake @@ -44,25 +44,31 @@ IF(QT_INCLUDES AND QT_LIBRARIES AND QT_MAJOR_VERSION MATCHES 5) RETURN() ENDIF(QT_INCLUDES AND QT_LIBRARIES AND QT_MAJOR_VERSION MATCHES 5) -IF(NOT QT_QMAKE_EXECUTABLE) - FIND_PROGRAM(QT_QMAKE_EXECUTABLE_FINDQT NAMES qmake qmake5 qmake-qt5 - PATHS "${QT_SEARCH_PATH}/bin" "$ENV{QTDIR}/bin") - SET(QT_QMAKE_EXECUTABLE ${QT_QMAKE_EXECUTABLE_FINDQT} CACHE PATH "Qt qmake program.") -ENDIF(NOT QT_QMAKE_EXECUTABLE) - -EXEC_PROGRAM(${QT_QMAKE_EXECUTABLE} ARGS "-query QT_VERSION" OUTPUT_VARIABLE QTVERSION) -IF(NOT QTVERSION MATCHES "5.*") - SET(QT_FOUND FALSE) - SET(QT5_FOUND FALSE) - IF(Qt5_FIND_REQUIRED) - MESSAGE(FATAL_ERROR "CMake was unable to find Qt5, put qmake in your path or set QTDIR/QT_QMAKE_EXECUTABLE.") - ENDIF(Qt5_FIND_REQUIRED) - RETURN() -ENDIF(NOT QTVERSION MATCHES "5.*") - -FIND_PACKAGE(PkgConfig REQUIRED) - -FIND_PACKAGE(Qt5 ${REQUIRED_QT_VERSION} CONFIG REQUIRED Core DBus Gui Network Test Widgets Xml) +IF(NOT Qt5Core_DIR ) + IF(NOT QT_QMAKE_EXECUTABLE) + FIND_PROGRAM(QT_QMAKE_EXECUTABLE_FINDQT NAMES qmake qmake5 qmake-qt5 + PATHS "${QT_SEARCH_PATH}/bin" "$ENV{QTDIR}/bin") + SET(QT_QMAKE_EXECUTABLE ${QT_QMAKE_EXECUTABLE_FINDQT} CACHE PATH "Qt qmake program.") + ENDIF(NOT QT_QMAKE_EXECUTABLE) + + EXEC_PROGRAM(${QT_QMAKE_EXECUTABLE} ARGS "-query QT_VERSION" OUTPUT_VARIABLE QTVERSION) + IF(NOT QTVERSION MATCHES "5.*") + SET(QT_FOUND FALSE) + SET(QT5_FOUND FALSE) + IF(Qt5_FIND_REQUIRED) + MESSAGE(FATAL_ERROR "CMake was unable to find Qt5, put qmake in your path or set QTDIR/QT_QMAKE_EXECUTABLE.") + ENDIF(Qt5_FIND_REQUIRED) + RETURN() + ENDIF(NOT QTVERSION MATCHES "5.*") +ENDIF(NOT Qt5Core_DIR ) + +find_package(Qt5Core ${REQUIRED_QT_VERSION} REQUIRED) +find_package(Qt5DBus ${REQUIRED_QT_VERSION} REQUIRED) +find_package(Qt5Gui ${REQUIRED_QT_VERSION} REQUIRED) +find_package(Qt5Test ${REQUIRED_QT_VERSION} REQUIRED) +find_package(Qt5Widgets ${REQUIRED_QT_VERSION} REQUIRED) +find_package(Qt5Network ${REQUIRED_QT_VERSION} REQUIRED) +find_package(Qt5Xml ${REQUIRED_QT_VERSION} REQUIRED) # Copy includes and library names into the same style as pkgconfig used for Qt4 set(QT_INCLUDES ${Qt5Core_INCLUDE_DIRS} ${Qt5DBus_INCLUDE_DIRS} ${Qt5Gui_INCLUDE_DIRS} ${Qt5Network_INCLUDE_DIRS} ${Qt5Test_INCLUDE_DIRS} ${Qt5Widgets_INCLUDE_DIRS}) @@ -77,9 +83,12 @@ set(QT_QTXML_LIBRARY ${Qt5Xml_LIBRARIES}) set(QT_LIBRARIES ${QT_QTCORE_LIBRARY} ${QT_QTDBUS_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_QTNETWORK_LIBRARY} ${QT_QTTEST_LIBRARY} ${QT_QTWIDGETS_LIBRARY} ${QT_QTXML_LIBRARY}) -STRING(REGEX REPLACE "^([0-9]+)\\.[0-9]+\\.[0-9]+.*" "\\1" QT_VERSION_MAJOR "${QTVERSION}") -STRING(REGEX REPLACE "^[0-9]+\\.([0-9])+\\.[0-9]+.*" "\\1" QT_VERSION_MINOR "${QTVERSION}") -STRING(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" QT_VERSION_PATCH "${QTVERSION}") +SET(QT_VERSION_MAJOR ${Qt5Core_VERSION_MAJOR}) +SET(QT_VERSION_MINOR ${Qt5Core_VERSION_MINOR}) +SET(QT_VERSION_PATCH ${Qt5Core_VERSION_PATCH}) +SET(QT_VERSION ${Qt5Core_VERSION}) + +GET_PROPERTY(QT_QMAKE_EXECUTABLE TARGET ${Qt5Core_QMAKE_EXECUTABLE} PROPERTY IMPORTED_LOCATION) IF(NOT QT_INCLUDE_DIR) EXEC_PROGRAM(${QT_QMAKE_EXECUTABLE} ARGS "-query QT_INSTALL_HEADERS" OUTPUT_VARIABLE QTHEADERS) -- 1.8.3.2