Skip to content
This repository has been archived by the owner on Dec 14, 2021. It is now read-only.

Commit

Permalink
use language standard from visual studio project settings
Browse files Browse the repository at this point in the history
  • Loading branch information
mlangkabel committed Sep 16, 2019
1 parent 6ed549b commit 127bd8a
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 10 deletions.
16 changes: 12 additions & 4 deletions SourcetrailExtension/SolutionParser/SolutionParser.cs
Expand Up @@ -88,8 +88,9 @@ public void CreateCompileCommands(Project project, string solutionConfigurationN
projectPlatformName = solutionPlatformName;
}

IVCConfigurationWrapper vcProjectConfiguration = vcProject.getConfiguration(projectConfigurationName, projectPlatformName);
string cppStandard = "";

IVCConfigurationWrapper vcProjectConfiguration = vcProject.getConfiguration(projectConfigurationName, projectPlatformName);
if (vcProjectConfiguration != null && vcProjectConfiguration.isValid())
{
SetCompatibilityVersionFlag(vcProject, vcProjectConfiguration);
Expand Down Expand Up @@ -139,10 +140,17 @@ public void CreateCompileCommands(Project project, string solutionConfigurationN
{
commandFlags += " -include \"" + file + "\" ";
}
}

string cppStandard = Utility.ProjectUtility.GetCppStandardForProject(vcProject);
Logging.Logging.LogInfo("Found C++ standard " + cppStandard + ".");
if (vcProjectConfiguration.GetCLCompilerTool() != null && vcProjectConfiguration.GetCLCompilerTool().isValid())
{
cppStandard = vcProjectConfiguration.GetCLCompilerTool().GetLanguageStandard();
}
}
if (cppStandard.Length == 0)
{
cppStandard = Utility.ProjectUtility.GetCppStandardForProject(vcProject);
}
Logging.Logging.LogInfo("Found C++ standard \"" + cppStandard + "\".");

bool isMakefileProject = vcProjectConfiguration.isMakefileConfiguration();

Expand Down
20 changes: 14 additions & 6 deletions SourcetrailExtension/Utility/ProjectUtility.cs
Expand Up @@ -361,26 +361,34 @@ static public string GetCppStandardForProject(IVCProjectWrapper project)
{
string result = "";

string toolset = project.GetWrappedVersion();
string justNumbers = new String(toolset.Where(Char.IsDigit).ToArray());
string vsVersion = project.GetWrappedVersion();
string justNumbers = new String(vsVersion.Where(Char.IsDigit).ToArray());
int versionNumber = int.Parse(justNumbers);

if (versionNumber < 120) // version 11 (2012)
if (versionNumber < 120) // version 11 (2012)
{
result = "c++11";
}
else if (versionNumber < 130) // version 12 (2013)
else if (versionNumber < 130) // version 12 (2013)
{
result = "c++14";
}
else if (versionNumber < 150) // version 14 (2015)
else if (versionNumber < 150) // version 14 (2015)
{
result = "c++14";
}
else if (versionNumber < 160) // version 15 (2017)
else if (versionNumber < 160) // version 15 (2017)
{
result = "c++14";
}
else if (versionNumber < 170) // version 16 (2019)
{
result = "c++17";
}
else // fallback
{
result = "c++17";
}

return result;
}
Expand Down
10 changes: 10 additions & 0 deletions VCProjectEngineWrapper/VCCLCompilerToolWrapper.cs
Expand Up @@ -76,6 +76,16 @@ public string GetToolPath()
return _wrapped.ToolPath;
}

public string GetLanguageStandard()
{
string rawStandardString = _wrappedRules.GetEvaluatedPropertyValue("LanguageStandard");
if (rawStandardString != "stdcpplatest" && rawStandardString.IndexOf("stdcpp") == 0)
{
return rawStandardString.Replace("stdcpp", "c++");
}
return "";
}

public string[] GetAdditionalIncludeDirectories()
{
return _wrappedRules.GetEvaluatedPropertyValue("AdditionalIncludeDirectories").SplitPaths();
Expand Down
Expand Up @@ -25,6 +25,7 @@ public interface IVCCLCompilerToolWrapper
bool GetCompilesAsC();
bool GetCompilesAsCPlusPlus();
string GetToolPath();
string GetLanguageStandard();
string[] GetAdditionalIncludeDirectories();
string[] GetPreprocessorDefinitions();
string[] GetForcedIncludeFiles();
Expand Down

0 comments on commit 127bd8a

Please sign in to comment.