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 <alexandru.croitor@qt.io>
Reviewed-by: Cristian Adam <cristian.adam@qt.io>
This commit is contained in:
Tobias Hunger
2019-07-26 15:09:12 +02:00
parent 4aee38e04c
commit 02e224fcfa

View File

@@ -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()) {