CMakePM: Fix crash when editing CMake files without a project

Fixes: QTCREATORBUG-30023
Change-Id: Id849635dd0e7437d7ae93251130d2f26ded24def
Reviewed-by: Kai Köhne <kai.koehne@qt.io>
This commit is contained in:
Cristian Adam
2023-12-07 12:01:55 +01:00
parent 68e44b3372
commit 144194b79a

View File

@@ -314,7 +314,9 @@ static void updateCMakeConfigurationWithLocalData(CMakeConfig &cmakeCache,
return var == "CMAKE_PREFIX_PATH" || var == "CMAKE_MODULE_PATH";
};
const FilePath projectDir = ProjectTree::currentBuildSystem()->projectDirectory();
const FilePath projectDir = ProjectTree::currentBuildSystem()
? ProjectTree::currentBuildSystem()->projectDirectory()
: currentDir;
auto updateDirVariables = [currentDir, projectDir, cmakeCache](QByteArray &value) {
value.replace("${CMAKE_CURRENT_SOURCE_DIR}", currentDir.path().toUtf8());
value.replace("${CMAKE_CURRENT_LIST_DIR}", currentDir.path().toUtf8());