Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Set correct compiler.runtime based on GUI preferences #235

Merged
merged 3 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 49 additions & 11 deletions ConanProfilesManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,22 @@ private string getConanCompilerVersion(string platformToolset)
return msvcVersionMap[platformToolset];
}

private string GetRuntimeLibraryType(runtimeLibraryOption runtimeLibraryValue)
{
switch (runtimeLibraryValue)
{
case runtimeLibraryOption.rtMultiThreaded:
case runtimeLibraryOption.rtMultiThreadedDebug:
return "static";
case runtimeLibraryOption.rtMultiThreadedDLL:
case runtimeLibraryOption.rtMultiThreadedDebugDLL:
return "dynamic";
default:
return "dynamic";
}
}


private string getConanCppstd(string languageStandard)
{
// https://learn.microsoft.com/en-us/cpp/build/reference/std-specify-language-standard-version?view=msvc-170
Expand Down Expand Up @@ -89,30 +105,52 @@ public void GenerateProfilesForProject(Project project)
string profileName = getProfileName(vcConfig);
string profilePath = System.IO.Path.Combine(conanProjectDirectory, profileName);

if (!File.Exists(profilePath))
{
string toolset = vcConfig.Evaluate("$(PlatformToolset)").ToString();
string compilerVersion = getConanCompilerVersion(toolset);
string arch = getConanArch(vcConfig.Evaluate("$(PlatformName)").ToString());
IVCRulePropertyStorage generalRule = vcConfig.Rules.Item("ConfigurationGeneral") as IVCRulePropertyStorage;
string languageStandard = generalRule == null ? null : generalRule.GetEvaluatedPropertyValue("LanguageStandard");
string cppStd = getConanCppstd(languageStandard);
string buildType = vcConfig.ConfigurationName;
string profileContent =
string toolset = vcConfig.Evaluate("$(PlatformToolset)").ToString();
string compilerVersion = getConanCompilerVersion(toolset);
string arch = getConanArch(vcConfig.Evaluate("$(PlatformName)").ToString());
IVCRulePropertyStorage generalRule = vcConfig.Rules.Item("ConfigurationGeneral") as IVCRulePropertyStorage;
string languageStandard = generalRule == null ? null : generalRule.GetEvaluatedPropertyValue("LanguageStandard");
string cppStd = getConanCppstd(languageStandard);

var tools = (IVCCollection) vcConfig.Tools;
var vcCTool = (VCCLCompilerTool) tools.Item("VCCLCompilerTool");

string runtime = GetRuntimeLibraryType(vcCTool.RuntimeLibrary);

string buildType = vcConfig.ConfigurationName;
string profileContent =
$@"
[settings]
arch={arch}
build_type={buildType}
compiler=msvc
compiler.cppstd={cppStd}
compiler.runtime=dynamic
compiler.runtime={runtime}
" +
$@"
compiler.runtime_type={buildType}
compiler.version={compilerVersion}
os=Windows
";

bool shouldWriteFile = true;

if (File.Exists(profilePath))
{
string existingProfileContent = File.ReadAllText(profilePath);
if (existingProfileContent == profileContent)
{
shouldWriteFile = false;
}
}

if (shouldWriteFile)
{
File.WriteAllText(profilePath, profileContent);
// We create this .runconan file to indicate that there were changes in the profile and that
// Conan should run, this file is removed by the script that launches conan to reset the state
string runConanFilePath = System.IO.Path.Combine(conanProjectDirectory, ".runconan");
File.WriteAllText(runConanFilePath, "");
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions ProjectConfigurationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,14 @@ echo Checking changes in conanfile.py
if %errorlevel% equ 1 set performInstall=1
)

REM Check for the .runconan file that indicates changes in profiles

if exist "".conan\.runconan"" (
echo Changes in profiles detected
set performInstall=1
del "".conan\.runconan""
)

if %performInstall% equ 1 (
REM Echo changes detected
echo Changes detected, executing conan install...
Expand Down
Loading