static private List <string> GetIncludeDirectories(IVCCLCompilerToolWrapper compilerTool) { List <string> includeDirectories = new List <string>(); if (compilerTool != null && compilerTool.isValid()) { includeDirectories.AddRange(compilerTool.GetAdditionalIncludeDirectories()); } else { Logging.Logging.LogWarning("No CL Compiler Tool provided"); } return(includeDirectories); }
static private int GetCLMajorVersion(IVCCLCompilerToolWrapper compilerTool, IVCConfigurationWrapper vcProjectConfig) { Logging.Logging.LogInfo("Looking up CL.exe (C++ compiler)"); if (compilerTool == null || !compilerTool.isValid() || vcProjectConfig == null || !vcProjectConfig.isValid()) { return(-1); } try { IVCPlatformWrapper platform = vcProjectConfig.GetPlatform(); List <string> finalDirectories = new List <string>(); foreach (string directory in platform.GetExecutableDirectories().Split(';')) { IPathResolver resolver = new VsPathResolver(""); finalDirectories.AddRange(resolver.ResolveVsMacroInPath(directory, vcProjectConfig)); } string toolPath = compilerTool.GetToolPath(); Logging.Logging.LogInfo("Found " + finalDirectories.Count.ToString() + " possible compiler directories."); foreach (string fd in finalDirectories) { string path = fd + "\\" + toolPath; if (File.Exists(path)) { FileVersionInfo info = FileVersionInfo.GetVersionInfo(path); int version = info.FileMajorPart; Logging.Logging.LogInfo("Found compiler location. Compiler tool version is " + version.ToString()); return(version); } } } catch (Exception e) { Logging.Logging.LogError("Exception: " + e.Message); } Logging.Logging.LogWarning("Failed to find C++ compiler tool."); return(-1); }
static private List <string> GetPreprocessorDefinitions(IVCCLCompilerToolWrapper compilerTool) { List <string> preprocessorDefinitions = new List <string>(); if (compilerTool != null && compilerTool.isValid()) { preprocessorDefinitions = compilerTool.GetPreprocessorDefinitions() .Select(x => x.Replace("\\\"", "\"")) .Where(x => !string.IsNullOrWhiteSpace(x)) .Distinct() .ToList(); } else { Logging.Logging.LogWarning("No CL Compiler Tool provided"); } return(preprocessorDefinitions); }
private void SetCompatibilityVersionFlag(IVCProjectWrapper project, IVCConfigurationWrapper vcProjectConfiguration) { Logging.Logging.LogInfo("Determining CL.exe (C++ compiler) version"); int majorCompilerVersion = -1; { IVCCLCompilerToolWrapper compilerTool = vcProjectConfiguration.GetCLCompilerTool(); if (compilerTool != null && compilerTool.isValid()) { majorCompilerVersion = GetCLMajorVersion(compilerTool, vcProjectConfiguration); } } if (majorCompilerVersion > -1) { Logging.Logging.LogInfo("Found compiler version " + majorCompilerVersion.ToString()); _compatibilityVersionFlag = _compatibilityVersionFlagBase + majorCompilerVersion.ToString(); return; } }
private CompileCommand CreateCompileCommand(ProjectItem item, string commandFlags, string vcStandard, string cStandard, bool isMakefileProject) { Logging.Logging.LogInfo("Starting to create Command Object from item \"" + Logging.Obfuscation.NameObfuscator.GetObfuscatedName(item.Name) + "\""); try { DTE dte = item.DTE; if (dte == null) { Logging.Logging.LogError("Failed to retrieve DTE object. Abort creating command object."); } IVCFileWrapper vcFile = VCFileWrapperFactory.create(item.Object); IVCCLCompilerToolWrapper compilerTool = null; if (!isMakefileProject) { List <IVCFileConfigurationWrapper> vcFileConfigurations = vcFile.GetFileConfigurations(); foreach (IVCFileConfigurationWrapper vcFileConfiguration in vcFileConfigurations) { if (vcFileConfiguration != null && vcFileConfiguration.isValid()) { compilerTool = vcFileConfiguration.GetCLCompilerTool(); if (compilerTool != null && compilerTool.isValid()) { break; } } } } if (CheckIsSourceFile(item)) { string additionalOptions = ""; if (compilerTool != null && compilerTool.isValid()) { additionalOptions = compilerTool.GetAdditionalOptions(); if (additionalOptions == "$(NOINHERIT)") { additionalOptions = ""; } } string languageStandardOption; if (additionalOptions.Contains("-std=")) { // if a language standard was defined in the additional options we do not need to set the language standard again. languageStandardOption = ""; } else { if (compilerTool != null && compilerTool.isValid() && compilerTool.GetCompilesAsC()) { languageStandardOption = "-std=" + cStandard; } else if (compilerTool != null && compilerTool.isValid() && compilerTool.GetCompilesAsCPlusPlus()) { languageStandardOption = "-std=" + vcStandard; } else { // we cannot derive the language from the compiler tool, so we need to check the file extension if (ProjectUtility.HasProperty(item.Properties, "Extension") && _cFileExtensions.Contains(item.Properties.Item("Extension").Value.ToString().Substring(1)) // extension property starts with "." ) { languageStandardOption = "-std=" + cStandard; } else { languageStandardOption = "-std=" + vcStandard; } } } CompileCommand command = new CompileCommand(); string relativeFilePath = item.Properties.Item("RelativePath").Value.ToString(); command.File = _pathResolver.GetAsAbsoluteCanonicalPath(relativeFilePath, vcFile.GetProject()); command.File = command.File.Replace('\\', '/'); command.Directory = _pathResolver.GetCompilationDatabaseFilePath(); command.Command = "clang-tool " + commandFlags; command.Command += languageStandardOption + " "; command.Command += additionalOptions + " "; command.Command += "\"" + command.File + "\""; return(command); } } catch (Exception e) { Logging.Logging.LogError("Exception: " + e.Message); } Logging.Logging.LogError("Failed to create command object."); return(null); }