Skip to content

Commit

Permalink
Merge pull request #134 from conan-io/custom_install_path
Browse files Browse the repository at this point in the history
Add configuration option to customize installation directory
  • Loading branch information
SSE4 authored Jul 16, 2019
2 parents a913ea0 + 0e9485f commit fab8c5e
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 4 deletions.
10 changes: 10 additions & 0 deletions Conan.VisualStudio/ConanOptionsPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace Conan.VisualStudio
public class ConanOptionsPage : DialogPage
{
private string _conanExecutablePath;
private string _conanInstallationPath;
private bool? _conanInstallOnlyActiveConfiguration;
private ConanGeneratorType? _conanGenerator;
private bool? _conanInstallAutomatically;
Expand All @@ -22,6 +23,15 @@ public string ConanExecutablePath
set => _conanExecutablePath = value;
}

[Category("Conan")]
[DisplayName("Conan installation directory")]
[Description(@"Path to the conan installation directory, may use macro like $(OutDir) or $(ProjectDir). Absolute or relative to the project directory.")]
public string ConanInstallationPath
{
get => _conanInstallationPath ?? (_conanInstallationPath = "$(OutDir).conan");
set => _conanInstallationPath = value;
}

[Category("Conan")]
[DisplayName("Install only active configuration")]
[Description(@"Install only active configuration, or all configurations")]
Expand Down
7 changes: 6 additions & 1 deletion Conan.VisualStudio/Services/ConanService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Conan.VisualStudio.Services
internal class ConanService : IConanService
{
private readonly ISettingsService _settingsService;
private readonly Core.IErrorListService _errorListService;
private readonly IErrorListService _errorListService;
private readonly IVcProjectService _vcProjectService;

public ConanService(ISettingsService settingsService, Core.IErrorListService errorListService, IVcProjectService vcProjectService)
Expand Down Expand Up @@ -53,9 +53,14 @@ private void IntegrateIntoConfiguration(VCConfiguration configuration)
foreach (VCPropertySheet sheet in configuration.PropertySheets)
{
if (ConanPathHelper.NormalizePath(sheet.PropertySheetFile) == ConanPathHelper.NormalizePath(absPropFilePath))
{
string msg = $"[Conan.VisualStudio] Property sheet '{absPropFilePath}' already added to project {configuration.project.Name}";
Logger.Log(msg);
return;
}
}
configuration.AddPropertySheet(relativePropFilePath);
Logger.Log($"[Conan.VisualStudio] Property sheet '{absPropFilePath}' added to project {configuration.project.Name}");
configuration.CollectIntelliSenseInfo();
}

Expand Down
4 changes: 4 additions & 0 deletions Conan.VisualStudio/Services/ISettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ public interface ISettingsService
/// <returns>Executable path. May be <c>null</c> if Conan not found.</returns>
string GetConanExecutablePath();

/// <summary>Returns Conan installation path - to be used as target for the "conan install" command.</summary>
/// <returns>Installation path. Might contain visual studio macro definitions (like $(OutDir)). Relative path is evaluated against project directory</returns>
string GetConanInstallationPath();

/// <summary>Returns True if install only active configuration, as defined in the project options.</summary>
/// <returns>Boolean flag describing conan installation mode</returns>
bool GetConanInstallOnlyActiveConfiguration();
Expand Down
8 changes: 5 additions & 3 deletions Conan.VisualStudio/Services/VcProjectService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,13 @@ internal static string GetArchitecture(string platformName)
private static string GetInstallationDirectoryImpl(ISettingsService settingsService, VCConfiguration configuration)
{
string installPath = ".conan";
if (settingsService != null && settingsService.GetConanGenerator() == ConanGeneratorType.visual_studio)
if (settingsService != null)
{
IVCRulePropertyStorage generalSettings = configuration.Rules.Item("ConfigurationGeneral");
string outputDirectory = generalSettings.GetEvaluatedPropertyValue("OutDir");
return Path.Combine(outputDirectory, installPath);
installPath = configuration.Evaluate(settingsService.GetConanInstallationPath());
if (!Path.IsPathRooted(installPath))
installPath = Path.Combine(configuration.project.ProjectDirectory, installPath);
return installPath;
}
return Path.Combine(configuration.project.ProjectDirectory, installPath);
}
Expand Down
5 changes: 5 additions & 0 deletions Conan.VisualStudio/Services/VisualStudioSettingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ public string GetConanExecutablePath()
return GetConanPage().ConanExecutablePath;
}

public string GetConanInstallationPath()
{
return GetConanPage().ConanInstallationPath;
}

public bool GetConanInstallOnlyActiveConfiguration()
{
return GetConanPage().ConanInstallOnlyActiveConfiguration;
Expand Down
13 changes: 13 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,16 @@ It is important to take into account:
of the Configuration and the Platform.
* For Conan profiles, the value declared will be used verbatim for the `--profile` argument
in the `conan install` command, and rules related to profile lookup applies.


## Extension configuration

There are several options available to the user to configure the extension, all of them can
be accessed through the 'Tools' > 'Conan Package Management' > 'Options...' menu:

![Conan Extension Options](images/conan-vs-extension-options.png)

* **Conan installation directory**: path where the `conanbuildinfo.props` file will be
generated. This path is common for all the configurations so making use of Visual Studio
dynamic directories like `$(Platform)` or `$(Configuration)` will be needed to avoid
overriding the file for different configurations.
Binary file added docs/images/conan-vs-extension-options.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit fab8c5e

Please sign in to comment.