From ea0643c3abd7e7821dcb7bdb8dfeff3a0e3b69c4 Mon Sep 17 00:00:00 2001 From: Tobias Hunger Date: Mon, 19 Sep 2016 11:53:30 +0200 Subject: [PATCH] CMake: Hint at Qt version to be used Set variables to hint at the Qt version being used. QT_QMAKE_EXECUTABLE is used to point to qmake (only relevant for Qt4), and CMAKE_PREFIX_PATH is set to point to the QT_INSTALL_LIBS directory which should hold a cmake folder with all the information on the Qt5 version being used. Update the warnings on the kit based on whether a Qt4 or a Qt5 is used in the kit. Change-Id: I77f95febd4c42c15568ebaf3f82bf82464058f61 Reviewed-by: Tim Jenssen Reviewed-by: Gunnar Roth --- .../cmakekitinformation.cpp | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/plugins/cmakeprojectmanager/cmakekitinformation.cpp b/src/plugins/cmakeprojectmanager/cmakekitinformation.cpp index 78dde5c272d..eb07090ba59 100644 --- a/src/plugins/cmakeprojectmanager/cmakekitinformation.cpp +++ b/src/plugins/cmakeprojectmanager/cmakekitinformation.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include @@ -39,6 +40,8 @@ #include #include +#include + using namespace ProjectExplorer; namespace CMakeProjectManager { @@ -448,9 +451,10 @@ KitConfigWidget *CMakeGeneratorKitInformation::createConfigWidget(Kit *k) const static const char CONFIGURATION_ID[] = "CMake.ConfigurationKitInformation"; -static const char CMAKE_QMAKE_KEY[] = "QT_QMAKE_EXECUTABLE"; static const char CMAKE_C_TOOLCHAIN_KEY[] = "CMAKE_C_COMPILER"; static const char CMAKE_CXX_TOOLCHAIN_KEY[] = "CMAKE_CXX_COMPILER"; +static const char CMAKE_QMAKE_KEY[] = "QT_QMAKE_EXECUTABLE"; +static const char CMAKE_PREFIX_PATH_KEY[] = "CMAKE_PREFIX_PATH"; CMakeConfigurationKitInformation::CMakeConfigurationKitInformation() { @@ -500,7 +504,11 @@ CMakeConfig CMakeConfigurationKitInformation::defaultConfiguration(const Kit *k) { Q_UNUSED(k); CMakeConfig config; + // Qt4: config << CMakeConfigItem(CMAKE_QMAKE_KEY, "%{Qt:qmakeExecutable}"); + // Qt5: + config << CMakeConfigItem(CMAKE_PREFIX_PATH_KEY, "%{Qt:QT_INSTALL_LIBS}"); + config << CMakeConfigItem(CMAKE_C_TOOLCHAIN_KEY, "%{Compiler:Executable:C}"); config << CMakeConfigItem(CMAKE_CXX_TOOLCHAIN_KEY, "%{Compiler:Executable:Cxx}"); @@ -525,7 +533,9 @@ QList CMakeConfigurationKitInformation::validate(const Kit *k) const const ToolChain *const tcCxx = ToolChainKitInformation::toolChain(k, ToolChain::Language::Cxx); const CMakeConfig config = configuration(k); + const bool isQt4 = version && version->qtVersion() < QtSupport::QtVersionNumber(5, 0, 0); Utils::FileName qmakePath; + QStringList qtLibDirs; Utils::FileName tcCPath; Utils::FileName tcCxxPath; foreach (const CMakeConfigItem &i, config) { @@ -538,12 +548,14 @@ QList CMakeConfigurationKitInformation::validate(const Kit *k) const tcCPath = expandedValue; else if (i.key == CMAKE_CXX_TOOLCHAIN_KEY) tcCxxPath = expandedValue; + else if (i.key == CMAKE_PREFIX_PATH_KEY) + qtLibDirs = CMakeConfigItem::cmakeSplitValue(expandedValue.toString()); } QList result; // Validate Qt: if (qmakePath.isEmpty()) { - if (version && version->isValid()) { + if (version && version->isValid() && isQt4) { result << Task(Task::Warning, tr("CMake configuration has no path to qmake binary set, " "even though the kit has a valid Qt version."), Utils::FileName(), -1, Core::Id(Constants::TASK_CATEGORY_BUILDSYSTEM)); @@ -553,13 +565,20 @@ QList CMakeConfigurationKitInformation::validate(const Kit *k) const result << Task(Task::Warning, tr("CMake configuration has a path to a qmake binary set, " "even though the kit has no valid Qt version."), Utils::FileName(), -1, Core::Id(Constants::TASK_CATEGORY_BUILDSYSTEM)); - } else if (qmakePath != version->qmakeCommand()) { + } else if (qmakePath != version->qmakeCommand() && isQt4) { result << Task(Task::Warning, tr("CMake configuration has a path to a qmake binary set " "that does not match the qmake binary path " "configured in the Qt version."), Utils::FileName(), -1, Core::Id(Constants::TASK_CATEGORY_BUILDSYSTEM)); } } + if (!qtLibDirs.contains(version->qmakeProperty("QT_INSTALL_LIBS")) && !isQt4) { + if (version && version->isValid()) { + result << Task(Task::Warning, tr("CMake configuration has no CMAKE_PREFIX_PATH set " + "that points to the kit Qt version."), + Utils::FileName(), -1, Core::Id(Constants::TASK_CATEGORY_BUILDSYSTEM)); + } + } // Validate Toolchains: if (tcCPath.isEmpty()) {