Skip to content

Commit

Permalink
add VCPKG_INSTALL_OPTIONS support.
Browse files Browse the repository at this point in the history
  • Loading branch information
JackBoosY committed Mar 26, 2023
1 parent db6bbe5 commit 7fed514
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 30 deletions.
9 changes: 0 additions & 9 deletions CHANGELOG.md

This file was deleted.

7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# vcpkg CMake Tools

[Vcpkg VSCode CMake extension](https://marketplace.visualstudio.com/items?itemName=JackBoosY.vcpkg-cmake-tools) provides vcpkg integration in VSCode.

It's still WIP, please help us to improve it in [github](https://github.com/JackBoosY/vcpkg-vscode-extension).

## Requirements
Expand All @@ -15,7 +16,9 @@ It's still WIP, please help us to improve it in [github](https://github.com/Jack
1. Ctrl + Shift + P
2. Search vcpkg.
3. Select `vcpkg: Enable vcpkg`.

a. Extension will automaticly enable vcpkg if you already set environment variable `VCPKG_ROOT` or already set vcpkg path in settings.

b. If environment variable `VCPKG_ROOT` is not set, please choose vcpkg root folder.
4. Extension will select the triplet (dynamic) according to your system architecture, vcpkg toolchain will be added into cmake settings.

Expand Down Expand Up @@ -43,6 +46,10 @@ It's still WIP, please help us to improve it in [github](https://github.com/Jack

## Release Notes

### 0.0.4

- Support VCPKG_INSTALL_OPTIONS

### 0.0.3

- Update document.
Expand Down
26 changes: 10 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"icon": "images/vcpkg-logo.png",
"publisher": "JackBoosY",
"license": "MIT",
"version": "0.0.3",
"version": "0.0.4",
"engines": {
"vscode": "^1.76.0"
},
Expand Down Expand Up @@ -108,12 +108,6 @@
"description": "Installed Directory",
"scope": "resource"
},
"vcpkg.general.additionalOptions": {
"type": "string",
"default": "",
"description": "Addtional options",
"scope": "resource"
},
"vcpkg.target.useStaticLib": {
"type": "boolean",
"default": false,
Expand All @@ -138,15 +132,15 @@
"description": "Host triplet",
"scope": "resource"
},
"vcpkg.target.configuration": {
"type": "string",
"default": "Debug",
"description": "Vcpkg Configuration",
"scope": "resource",
"enum": [
"Debug",
"Release"
]
"vcpkg.target.additionalOptions": {
"type": "array",
"items": {
"type": "string",
"title": "Vcpkg install options"
},
"default": [],
"description": "Additional vcpkg options",
"scope": "resource"
}
}
}
Expand Down
117 changes: 112 additions & 5 deletions src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ export class ConfigurationManager implements vscode.Disposable
private _installDependenciesConfig = 'general.installDependencies';
private _autoLinkConfig = 'general.autolink';
private _installDirectoryConfig = 'general.installDirectory';
private _additionalOptionsConfig = 'general.additionalOptions';
private _additionalOptionsConfig = 'target.additionalOptions';
private _useStaticLibConfig = 'target.useStaticLib';
private _vcpkgUseDynamicCRTConfig = 'target.useDynamicCRT';
private _targetTripletConfig = 'target.defaultTriplet';
private _hostTripletConfig = 'target.hostTriplet';
private _vcpkgConfigurationConfig = 'target.configuration';

private _cmakeOptionConfig = 'configureArgs';
private _configConfigSettingConfig = 'configureSettings';

private _vcpkgManifestModeConfig = 'VCPKG_MANIFEST_MODE';
private _vcpkgTargetTripletConfig = 'VCPKG_TARGET_TRIPLET';
private _vcpkgInstallOptionsConfig = 'VCPKG_INSTALL_OPTIONS';
private _cmakeOptionPrefix = '-D';
private _cmakeOptionEanble = '=ON';
private _cmakeOptionDisable = '=OFF';
Expand Down Expand Up @@ -142,6 +142,11 @@ export class ConfigurationManager implements vscode.Disposable
return newSettings;
}

private isStaticLib(triplet : string)
{
return triplet?.endsWith('-static');
}

private async addVcpkgToolchain(vcpkgRoot : string)
{
let cleanConfig = this.getCleanVcpkgToolchian();
Expand All @@ -160,16 +165,16 @@ export class ConfigurationManager implements vscode.Disposable

if (isStatic)
{
if (!currTriplet?.endsWith('-static'))
if (!this.isStaticLib(currTriplet as string))
{
currTriplet += '-static';
}
}
else
{
if (currTriplet?.endsWith('-static'))
if (this.isStaticLib(currTriplet as string))
{
currTriplet.substring(0, currTriplet.length - '-static'.length);
(currTriplet as string).substring(0, (currTriplet as string).length - '-static'.length);
}
}

Expand Down Expand Up @@ -199,6 +204,9 @@ export class ConfigurationManager implements vscode.Disposable

this.updateCurrentTripletSetting();
this.addVcpkgToolchain(vcpkgPath);

// disable manifest mode by default
this.disableManifest();
}

async enableVcpkg() {
Expand Down Expand Up @@ -352,6 +360,105 @@ export class ConfigurationManager implements vscode.Disposable
vscode.window.showInformationMessage('Now use dynamic library / triplet');
}

async onConfigurationChanged(event : vscode.ConfigurationChangeEvent)
{
this.logInfo('detect configuration changed.');
if (event.affectsConfiguration('vcpkg.' + this._enableVcpkgConfig))
{
this.logInfo('detect vcpkg enable configuration changed.');
if (workspace.getConfiguration('vcpkg').get<boolean>(this._enableVcpkgConfig))
{
this.enableVcpkg();
}
else
{
this.disableVcpkg();
}
}
else if (event.affectsConfiguration('vcpkg.' + this._vcpkgPathConfig))
{
this.logInfo('detect vcpkg path configuration changed.');
this.disableVcpkg();
this.enableVcpkg();
}
else if (event.affectsConfiguration('vcpkg.' + this._useManifestConfig))
{
this.logInfo('detect vcpkg manifest configuration changed.');
if (workspace.getConfiguration('vcpkg').get<boolean>(this._useManifestConfig))
{
this.enableManifest();
}
else
{
this.disableManifest();
}
}
else if (event.affectsConfiguration('vcpkg.' + this._installDependenciesConfig))
{
}
else if (event.affectsConfiguration('vcpkg.' + this._autoLinkConfig))
{
}
else if (event.affectsConfiguration('vcpkg.' + this._installDirectoryConfig))
{
}
else if (event.affectsConfiguration('vcpkg.' + this._additionalOptionsConfig))
{
this.logInfo('detect vcpkg install option configuration changed.');
let extraOptCfgs = workspace.getConfiguration('vcpkg').get<Array<string>>(this._additionalOptionsConfig);
let extraOptions = this._cmakeOptionPrefix + this._vcpkgInstallOptionsConfig + '="';
if (extraOptCfgs !== undefined)
{
for (let curr in extraOptCfgs)
{
extraOptions += extraOptCfgs[curr] + ';';

this.logInfo('add extra vcpkg instal option: ' + extraOptCfgs[curr]);
}

}

extraOptions += '"';

let cmakeConfigs = this.getAndCleanCMakeOptions(this._additionalOptionsConfig);
cmakeConfigs?.push(extraOptions);

await workspace.getConfiguration('cmake').update(this._cmakeOptionConfig, cmakeConfigs);
}
else if (event.affectsConfiguration('vcpkg.' + this._useStaticLibConfig))
{
this.logInfo('detect vcpkg static lib configuration changed.');
if (workspace.getConfiguration('vcpkg').get<boolean>(this._useStaticLibConfig))
{
this.useStaticLib();
}
else
{
this.useDynamicLib();
}
}
else if (event.affectsConfiguration('vcpkg.' + this._vcpkgUseDynamicCRTConfig))
{
if (process.platform === "win32")
{

}
}
else if (event.affectsConfiguration('vcpkg.' + this._targetTripletConfig))
{
this.logInfo('detect vcpkg target triplet configuration changed.');
let currSel = workspace.getConfiguration('vcpkg').get<string>(this._targetTripletConfig);
if (this.isStaticLib(currSel as string))
{
this.useStaticLib();
}
else
{
this.useDynamicLib();
}
}
}

dispose(): void {
this.disposables.forEach((item) => item.dispose());
}
Expand Down
3 changes: 3 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ export function activate(context: vscode.ExtensionContext) {

// use dynamic lib
disposables.push(vscode.commands.registerCommand('vcpkg-integration.use_dynamic_lib', async() => await configMgr.useDynamicLib()));

// config changed event
disposables.push(vscode.workspace.onDidChangeConfiguration(async(event) => await configMgr.onConfigurationChanged(event)));
}

// This method is called when your extension is deactivated
Expand Down

0 comments on commit 7fed514

Please sign in to comment.