Beispiel #1
0
        public static void CreateCompilationDatabase(AsyncPackage package, string compileCommand)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            var myOutput   = new ExtensionOutput(package, "CLang Output", ExtensionOutput.DefaultOutputWindowGuid);
            var dteService = package.GetService <EnvDTE.DTE, EnvDTE.DTE>();
            var cppSupport = new CppProject(dteService);
            var project    = cppSupport.GetProjectFromSelected();

            if (project == null)
            {
                return;
            }
            cppSupport.Save(project); // ensure that project is saved before we do anything
            var hierarchy = cppSupport.ToHierarchy(project as EnvDTE.Project);
            var visitor   = new CompilationDatabaseVisitor(myOutput, cppSupport, compileCommand);

            cppSupport.VisitHierarchy(hierarchy, visitor);
            var    directory       = new FileInfo(project.FileName).DirectoryName;
            var    outputFile      = GetCompileDatabasePath(directory);
            string compileDatabase = JsonConvert.SerializeObject(visitor.CompileDatabase);

            File.WriteAllText(outputFile, compileDatabase);
        }
Beispiel #2
0
 public CompilationDatabaseVisitor(ExtensionOutput output, CppProject project, string compileCommand)
 {
     m_output         = output;
     m_project        = project;
     m_compileCommand = compileCommand;
 }
        public CompilerSettings(CppProject project, ProjectItem prjItem)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            var vcProject     = prjItem.ContainingProject.Object as VCProject;
            var file          = prjItem.Object;
            var activeSetting = project.GetActiveConfiguration(prjItem.ContainingProject);

            AddSettingsFromVCFile(this, file, activeSetting);
            AddSettingsFromVCProject(this, vcProject, activeSetting);

            if (FullIncludes.Count > 0)
            {
                var newList = CppProject.ExpandMacros(vcProject, activeSetting, FullIncludes.Aggregate((e, e1) => e + ";" + e1)).Split(';').ToList();
                FullIncludes.Clear();
                foreach (var x in newList)
                {
                    if (x.Length > 0)
                    {
                        FullIncludes.Add(x);
                    }
                }
            }

            if (AdditionalIncludeDirectories.Count > 0)
            {
                var newList = CppProject.ExpandMacros(vcProject, activeSetting, AdditionalIncludeDirectories.Aggregate((e, e1) => e + ";" + e1)).Split(';').ToList();
                AdditionalIncludeDirectories.Clear();
                foreach (var x in newList)
                {
                    if (x.Length > 0)
                    {
                        AdditionalIncludeDirectories.Add(x);
                    }
                }
            }

            if (PreprocessorDefinitions.Count > 0)
            {
                var newList = CppProject.ExpandMacros(vcProject, activeSetting, PreprocessorDefinitions.Aggregate((e, e1) => e + ";" + e1)).Split(';').ToList();
                PreprocessorDefinitions.Clear();
                foreach (var x in newList)
                {
                    var t = x.Trim();
                    if (t == "\\\"\\\"")
                    {
                        continue;
                    }
                    if (t.Length > 0)
                    {
                        PreprocessorDefinitions.Add(t);
                    }
                }
            }

            if (ForcedIncludeFiles.Count > 0)
            {
                var newList = CppProject.ExpandMacros(vcProject, activeSetting, ForcedIncludeFiles.Aggregate((e, e1) => e + ";" + e1)).Split(';').ToList();
                ForcedIncludeFiles.Clear();
                ForcedIncludeFiles.AddRange(newList);
            }
        }