aboutsummaryrefslogtreecommitdiffstats
path: root/qt-cpp
diff options
context:
space:
mode:
authorOrkun Tokdemir <orkun.tokdemir@qt.io>2024-10-23 17:36:46 +0200
committerOrkun Tokdemir <orkun.tokdemir@qt.io>2024-11-13 10:50:06 +0000
commitb6caeb951b55f8a0e8cb8412313393a7492394e7 (patch)
tree5460375d6c145037cc6dc43a360cd63ec2cefb5b /qt-cpp
parent2f270f45e8181bb816c79d655eaf23f9bd4a4b39 (diff)
qt-cpp: Set `cmake.cmakePath` with cmake exe inside Qt installation root
* Update package.json * Add `qt-cpp.doNotAskForCMakePath` Fixes: VSCODEEXT-102 Change-Id: Ia31715e40a4e0abc0aa42c9ef3d76033786fcbea Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
Diffstat (limited to 'qt-cpp')
-rw-r--r--qt-cpp/package.json11
-rw-r--r--qt-cpp/src/extension.ts3
-rw-r--r--qt-cpp/src/kit-manager.ts67
-rw-r--r--qt-cpp/src/util/get-qt-paths.ts17
4 files changed, 96 insertions, 2 deletions
diff --git a/qt-cpp/package.json b/qt-cpp/package.json
index d947374..3302a28 100644
--- a/qt-cpp/package.json
+++ b/qt-cpp/package.json
@@ -65,6 +65,17 @@
"main": "./out/extension.js",
"l10n": "./l10n",
"contributes": {
+ "configuration": {
+ "title": "Qt C++ Configuration",
+ "properties": {
+ "qt-cpp.doNotAskForCMakePath": {
+ "type": "boolean",
+ "default": false,
+ "markdownDescription": "Do not ask for setting [`#cmake.cmakePath#`](https://vector-of-bool.github.io/docs/vscode-cmake-tools/settings.html#cmake-cmakepath).\n\nCMake Tools search the PATH environment variable, and make some \n\neducated guesses on where to find CMake.",
+ "scope": "machine"
+ }
+ }
+ },
"commands": [
{
"command": "qt-cpp.scanForQtKits",
diff --git a/qt-cpp/src/extension.ts b/qt-cpp/src/extension.ts
index 30f9b4a..c4d1da3 100644
--- a/qt-cpp/src/extension.ts
+++ b/qt-cpp/src/extension.ts
@@ -34,7 +34,7 @@ import {
qmlImportPathCommand
} from '@cmd/launch-variables';
import { createCppProject, CppProjectManager, CppProject } from '@/project';
-import { KitManager } from '@/kit-manager';
+import { KitManager, tryToUseCMakeFromQtTools } from '@/kit-manager';
import { wasmStartTaskProvider, WASMStartTaskProvider } from '@task/wasm-start';
import { EXTENSION_ID } from '@/constants';
@@ -86,6 +86,7 @@ export async function activate(context: vscode.ExtensionContext) {
logger.info('Received config change:', message.config as unknown as string);
processMessage(message);
});
+ void tryToUseCMakeFromQtTools();
await kitManager.checkForAllQtInstallations();
await initCoreValues();
diff --git a/qt-cpp/src/kit-manager.ts b/qt-cpp/src/kit-manager.ts
index 5c45e59..bac8fd6 100644
--- a/qt-cpp/src/kit-manager.ts
+++ b/qt-cpp/src/kit-manager.ts
@@ -28,6 +28,7 @@ import { CppProject } from '@/project';
import { coreAPI } from '@/extension';
import { GlobalStateManager } from '@/state';
import { IsQtKit } from '@cmd/register-qt-path';
+import { EXTENSION_ID } from '@/constants';
const logger = createLogger('kit-manager');
@@ -243,6 +244,10 @@ export class KitManager {
qtInsRoot: string,
workspaceFolder?: vscode.WorkspaceFolder
) {
+ // Set only for the global workspace
+ if (!workspaceFolder && qtInsRoot) {
+ void tryToUseCMakeFromQtTools();
+ }
const qtInstallations = await findQtKits(qtInsRoot);
if (qtInsRoot) {
KitManager.showQtInstallationsMessage(qtInsRoot, qtInstallations);
@@ -827,3 +832,65 @@ export function getCurrentGlobalAdditionalQtPaths(): QtAdditionalPath[] {
) ?? []
);
}
+
+export async function tryToUseCMakeFromQtTools() {
+ if (getDoNotAskForCMakePath()) {
+ logger.info('doNotAskForCMakePath is set');
+ return;
+ }
+ // check if cmake.cmakePath is set
+ const cmakePathConfig = 'cmakePath';
+ const cmakeConfig = vscode.workspace.getConfiguration('cmake');
+
+ const IsCustomCmakePath =
+ cmakeConfig.get<string>(cmakePathConfig) !== 'cmake';
+ if (IsCustomCmakePath || commandExists.sync('cmake')) {
+ return;
+ }
+
+ const cmakeExePath = await qtPath.locateCMakeExecutable(
+ getCurrentGlobalQtInstallationRoot()
+ );
+ if (!cmakeExePath) {
+ return;
+ }
+ const setCMakePath = () => {
+ logger.info(`Setting cmakePath to ${cmakeExePath}`);
+ void cmakeConfig.update(
+ cmakePathConfig,
+ cmakeExePath,
+ vscode.ConfigurationTarget.Global
+ );
+ };
+ // Ask users if they want to set cmakePath to the cmake executable found in Qt installation
+ const message = `CMake executable found in Qt installation: "${cmakeExePath}"`;
+ logger.info(message);
+ const use = 'Use';
+ void vscode.window
+ .showInformationMessage(
+ `${message}, would you like to use it?`,
+ use,
+ 'Do not ask again'
+ )
+ .then((selection) => {
+ if (selection === use) {
+ setCMakePath();
+ } else if (selection === 'Do not ask again') {
+ void setDoNotAskForCMakePath(true);
+ }
+ });
+}
+
+async function setDoNotAskForCMakePath(value: boolean) {
+ await vscode.workspace
+ .getConfiguration(EXTENSION_ID)
+ .update('doNotAskForCMakePath', value, vscode.ConfigurationTarget.Global);
+}
+
+function getDoNotAskForCMakePath(): boolean {
+ return (
+ vscode.workspace
+ .getConfiguration(EXTENSION_ID)
+ .get<boolean>('doNotAskForCMakePath') ?? false
+ );
+}
diff --git a/qt-cpp/src/util/get-qt-paths.ts b/qt-cpp/src/util/get-qt-paths.ts
index 4b16bc5..2fc4f08 100644
--- a/qt-cpp/src/util/get-qt-paths.ts
+++ b/qt-cpp/src/util/get-qt-paths.ts
@@ -5,7 +5,7 @@ import * as path from 'path';
import * as fs from 'fs/promises';
import * as fsutil from '@util/fs';
-import { OSExeSuffix } from 'qt-lib';
+import { OSExeSuffix, IsMacOS } from 'qt-lib';
const QtToolchainCMakeFileName = 'qt.toolchain.cmake';
const NinjaFileName = 'ninja' + OSExeSuffix;
@@ -116,3 +116,18 @@ export async function locateCMakeQtToolchainFile(installation: string) {
return '';
}
+
+export async function locateCMakeExecutable(rootIns: string) {
+ const cmakeExePath = path.join(
+ rootIns,
+ `Tools`,
+ 'CMake',
+ IsMacOS ? path.join('CMake.app', 'Contents') : '',
+ 'bin',
+ `cmake${OSExeSuffix}`
+ );
+ if (await fsutil.exists(cmakeExePath)) {
+ return cmakeExePath;
+ }
+ return undefined;
+}