bool BuildDirManager::hasConfigChanged() { checkConfiguration(); const QByteArray GENERATOR_KEY = "CMAKE_GENERATOR"; const QByteArray EXTRA_GENERATOR_KEY = "CMAKE_EXTRA_GENERATOR"; const QByteArray CMAKE_COMMAND_KEY = "CMAKE_COMMAND"; const QByteArray CMAKE_C_COMPILER_KEY = "CMAKE_C_COMPILER"; const QByteArray CMAKE_CXX_COMPILER_KEY = "CMAKE_CXX_COMPILER"; const QByteArrayList criticalKeys = {GENERATOR_KEY, CMAKE_COMMAND_KEY, CMAKE_C_COMPILER_KEY, CMAKE_CXX_COMPILER_KEY}; const CMakeConfig currentConfig = takeCMakeConfiguration(); const CMakeTool *tool = m_parameters.cmakeTool(); QTC_ASSERT(tool, return false); // No cmake... we should not have ended up here in the first place const QString extraKitGenerator = m_parameters.extraGenerator; const QString mainKitGenerator = m_parameters.generator; CMakeConfig targetConfig = m_parameters.configuration; targetConfig.append(CMakeConfigItem(GENERATOR_KEY, CMakeConfigItem::INTERNAL, QByteArray(), mainKitGenerator.toUtf8())); if (!extraKitGenerator.isEmpty()) targetConfig.append(CMakeConfigItem(EXTRA_GENERATOR_KEY, CMakeConfigItem::INTERNAL, QByteArray(), extraKitGenerator.toUtf8())); targetConfig.append(CMakeConfigItem(CMAKE_COMMAND_KEY, CMakeConfigItem::INTERNAL, QByteArray(), tool->cmakeExecutable().toUserOutput().toUtf8())); Utils::sort(targetConfig, CMakeConfigItem::sortOperator()); bool mustReparse = false; auto ccit = currentConfig.constBegin(); auto kcit = targetConfig.constBegin(); while (ccit != currentConfig.constEnd() && kcit != targetConfig.constEnd()) { if (ccit->key == kcit->key) { if (ccit->value != kcit->value) { if (criticalKeys.contains(kcit->key)) { clearCache(); return false; // no need to trigger a new reader, clearCache will do that } mustReparse = true; } ++ccit; ++kcit; } else { if (ccit->key < kcit->key) { ++ccit; } else { ++kcit; mustReparse = true; } } } // If we have keys that do not exist yet, then reparse. // // The critical keys *must* be set in cmake configuration, so those were already // handled above. return mustReparse || kcit != targetConfig.constEnd(); }
static CMakeConfig removeDuplicates(const CMakeConfig &config) { CMakeConfig result; // Remove duplicates (last value wins): QSet<QByteArray> knownKeys; for (int i = config.count() - 1; i >= 0; --i) { const CMakeConfigItem &item = config.at(i); if (knownKeys.contains(item.key)) continue; result.append(item); knownKeys.insert(item.key); } Utils::sort(result, CMakeConfigItem::sortOperator()); return result; }