From 02e224fcfa7135f1e32adb02a14426ea153ae618 Mon Sep 17 00:00:00 2001 From: Tobias Hunger Date: Fri, 26 Jul 2019 15:09:12 +0200 Subject: [PATCH] CMake: Support CMAKE_CURRENT_LIST_DIR and CMAKE_CURRENT_SOURCE_DIR Support CMAKE_CURRENT_LIST_DIR and CMAKE_CURRENT_SOURCE_DIR as variables in filenames when handling links in the CMake editor. Having a way to find out variable values in CMake would be nice, till that arrives, we have to live with hacks to make the most common variables work:-/ Task-number: QTCREATORBUG-21065 Change-Id: Iffaaae8665e0662226d08b88de37b66d5a5fc4d4 Reviewed-by: Alexandru Croitor Reviewed-by: Cristian Adam --- src/plugins/cmakeprojectmanager/cmakeeditor.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/plugins/cmakeprojectmanager/cmakeeditor.cpp b/src/plugins/cmakeprojectmanager/cmakeeditor.cpp index 042cb363c8a..d3a4fd1d29a 100644 --- a/src/plugins/cmakeprojectmanager/cmakeeditor.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeeditor.cpp @@ -130,12 +130,9 @@ void CMakeEditorWidget::contextMenuEvent(QContextMenuEvent *e) static bool isValidFileNameChar(const QChar &c) { - return c.isLetterOrNumber() - || c == QLatin1Char('.') - || c == QLatin1Char('_') - || c == QLatin1Char('-') - || c == QLatin1Char('/') - || c == QLatin1Char('\\'); + return c.isLetterOrNumber() || c == QLatin1Char('.') || c == QLatin1Char('_') + || c == QLatin1Char('-') || c == QLatin1Char('/') || c == QLatin1Char('\\') || c == '{' + || c == '}' || c == '$'; } void CMakeEditorWidget::findLinkAt(const QTextCursor &cursor, @@ -185,9 +182,12 @@ void CMakeEditorWidget::findLinkAt(const QTextCursor &cursor, if (buffer.isEmpty()) return processLinkCallback(link); - // TODO: Resolve variables - QDir dir(textDocument()->filePath().toFileInfo().absolutePath()); + buffer.replace("${CMAKE_CURRENT_SOURCE_DIR}", dir.path()); + buffer.replace("${CMAKE_CURRENT_LIST_DIR}", dir.path()); + + // TODO: Resolve more variables + QString fileName = dir.filePath(buffer); QFileInfo fi(fileName); if (fi.exists()) {