Example #1
0
        private static void WriteProFileOption(StreamWriter sw, ProFileOption option)
        {
            if (option.List.Count <= 0)
                return;

            if (option.IncludeComment)
                sw.WriteLine(sw.NewLine + "#" + option.ShortComment);

            if (option.AssignSymbol != ProFileOption.AssignType.AT_Function)
            {
                sw.Write(option.Name);

                switch(option.AssignSymbol)
                {
                    case ProFileOption.AssignType.AT_Equals:
                        sw.Write(" = "); break;
                    case ProFileOption.AssignType.AT_MinusEquals:
                        sw.Write(" -= "); break;
                    case ProFileOption.AssignType.AT_PlusEquals:
                        sw.Write(" += "); break;
                }

                for (int i=0; i<option.List.Count-1; i++)
                {
                    sw.Write((string)option.List[i] + option.NewOption);
                }
                sw.Write((string)option.List[option.List.Count-1] + sw.NewLine);
            }
            else
            {
                for (int i=0; i<option.List.Count; i++)
                {
                    sw.WriteLine(option.Name + "(" + (string)option.List[i] + ")");
                }
            }
        }
Example #2
0
        private static ProFileContent CreatePriFileContent(EnvDTE.Project project, string priFileDirectory)
        {
            ProFileOption option;
            QtProject qtPro = QtProject.Create(project);
            ProFileContent content = new ProFileContent(qtPro.VCProject);
            bool hasSpaces = false;

            // add the header files
            option = new ProFileOption("HEADERS");
            option.ShortComment = "Header files";
            option.IncludeComment = false;
            content.Options.Add(option);
            option.List.AddRange(HelperFunctions.GetProjectFiles(project, FilesToList.FL_HFiles));
            MakeFilesRelativePath(qtPro.VCProject, option.List, priFileDirectory);
            if (ContainsFilesWithSpaces(option.List))
                hasSpaces = true;

            // add the source files
            option = new ProFileOption("SOURCES");
            option.ShortComment = "Source files";
            option.IncludeComment = false;
            content.Options.Add(option);
            option.List.AddRange(HelperFunctions.GetProjectFiles(project, FilesToList.FL_CppFiles));
            MakeFilesRelativePath(qtPro.VCProject, option.List, priFileDirectory);
            if (ContainsFilesWithSpaces(option.List))
                hasSpaces = true;

            // add the form files
            option = new ProFileOption("FORMS");
            option.ShortComment = "Forms";
            option.IncludeComment = false;
            content.Options.Add(option);
            option.List.AddRange(HelperFunctions.GetProjectFiles(project, FilesToList.FL_UiFiles));
            MakeFilesRelativePath(qtPro.VCProject, option.List, priFileDirectory);
            if (ContainsFilesWithSpaces(option.List))
                hasSpaces = true;

            // add the translation files
            option = new ProFileOption("TRANSLATIONS");
            option.Comment = Resources.ec_Translations;
            option.ShortComment = "Translation file(s)";
            option.IncludeComment = false;
            option.List.AddRange(HelperFunctions.GetProjectFiles(project, FilesToList.FL_Translation));
            MakeFilesRelativePath(qtPro.VCProject, option.List, priFileDirectory);
            if (ContainsFilesWithSpaces(option.List))
                hasSpaces = true;
            content.Options.Add(option);

            // add the resource files
            option = new ProFileOption("RESOURCES");
            option.Comment = Resources.ec_Resources;
            option.ShortComment = "Resource file(s)";
            option.IncludeComment = false;
            content.Options.Add(option);

            foreach (VCFile resFile in qtPro.GetResourceFiles())
                option.List.Add(resFile.RelativePath.Replace('\\', '/'));

            if (hasSpaces)
                Messages.DisplayWarningMessage(SR.GetString("ExportProject_PriFileContainsSpaces"));

            return content;
        }
Example #3
0
        private static ProFileContent CreateProFileContent(EnvDTE.Project project)
        {
            ProFileOption option;
            QtProject qtPro = QtProject.Create(project);
            ProFileContent content = new ProFileContent(qtPro.VCProject);

            // hack to get active config
            string activeConfig = project.ConfigurationManager.ActiveConfiguration.ConfigurationName;
            string activePlatform = project.ConfigurationManager.ActiveConfiguration.PlatformName;
            VCConfiguration config = (VCConfiguration)((IVCCollection)qtPro.VCProject.Configurations).Item(activeConfig);
            CompilerToolWrapper compiler = CompilerToolWrapper.Create(config);
            VCLinkerTool linker = (VCLinkerTool)((IVCCollection)config.Tools).Item("VCLinkerTool");
            VCLibrarianTool libTool = (VCLibrarianTool)((IVCCollection)config.Tools).Item("VCLibrarianTool");

            string outPut = config.PrimaryOutput;
            FileInfo fi = new FileInfo(outPut);
            string destdir = HelperFunctions.GetRelativePath(qtPro.VCProject.ProjectDirectory, fi.DirectoryName);
            destdir = HelperFunctions.ChangePathFormat(destdir);
            string target = qtPro.VCProject.Name;

            option = new ProFileOption("TEMPLATE");
            option.Comment = Resources.ec_Template;
            option.ShortComment = "Template";
            option.NewOption = null; // just one option...
            option.AssignSymbol = ProFileOption.AssignType.AT_Equals;
            content.Options.Add(option);
            if (config.ConfigurationType == ConfigurationTypes.typeApplication)
                option.List.Add("app");
            else
                option.List.Add("lib");

            option = new ProFileOption("TARGET");
            option.Comment = Resources.ec_Target;
            option.ShortComment = "Target Name";
            option.NewOption = null; // just one option...
            option.AssignSymbol = ProFileOption.AssignType.AT_Equals;
            content.Options.Add(option);
            option.List.Add(target);

            option = new ProFileOption("DESTDIR");
            option.Comment = Resources.ec_DestDir;
            option.ShortComment = "Destination Directory";
            option.NewOption = null; // just one option...
            option.AssignSymbol = ProFileOption.AssignType.AT_Equals;
            content.Options.Add(option);
            option.List.Add(destdir);

            // add the qt option
            option = new ProFileOption("QT");
            ProFileOption optionQT = option;
            option.Comment = Resources.ec_Qt;
            option.ShortComment = "Qt Options";
            option.NewOption = " "; // just space between the options...
            content.Options.Add(option);

            // add the config option
            option = new ProFileOption("CONFIG");
            ProFileOption optionCONFIG = option;
            option.Comment = Resources.ec_Config;
            option.ShortComment = "Config Options";
            option.NewOption = " "; // just space between the options...
            content.Options.Add(option);

            AddModules(qtPro, optionQT, optionCONFIG);

            if (config.ConfigurationType == ConfigurationTypes.typeStaticLibrary)
                option.List.Add("staticlib");
            if (linker != null)
            {
                if (linker.GenerateDebugInformation)
                    option.List.Add("debug");
                else
                    option.List.Add("release");

                if (linker.SubSystem == subSystemOption.subSystemConsole)
                    option.List.Add("console");

                if (linker.AdditionalDependencies != null)
                {
                    if (linker.AdditionalDependencies.IndexOf("QAxServer") > -1)
                        option.List.Add("qaxserver");
                    else if (linker.AdditionalDependencies.IndexOf("QAxContainer") > -1)
                        option.List.Add("qaxcontainer");
                    else if (linker.AdditionalDependencies.IndexOf("QtHelp") > -1)
                        option.List.Add("help");
                }
            }

            if (qtPro.IsDesignerPluginProject())
            {
                option.List.Add("designer");
                option.List.Add("plugin");
            }

            // add defines
            option = new ProFileOption("DEFINES");
            option.Comment = Resources.ec_Defines;
            option.ShortComment = "Defines";
            option.NewOption = " ";
            option.AssignSymbol = ProFileOption.AssignType.AT_PlusEquals;
            content.Options.Add(option);
            AddPreprocessorDefinitions(option, compiler.GetPreprocessorDefinitions());

            // add the include path option
            option = new ProFileOption("INCLUDEPATH");
            option.Comment = Resources.ec_IncludePath;
            option.ShortComment = "Include Path";
            content.Options.Add(option);
            AddIncludePaths(project, option, compiler.GetAdditionalIncludeDirectories());

            option = new ProFileOption("LIBS");
            option.Comment = Resources.ec_Libs;
            option.ShortComment = "Additional Libraries";
            content.Options.Add(option);
            if (linker != null)
            {
                AddLibraries(project, option, linker.AdditionalLibraryDirectories,
                    linker.AdditionalDependencies);
            }
            else if (libTool != null)
            {
                AddLibraries(project, option, libTool.AdditionalLibraryDirectories,
                    libTool.AdditionalDependencies);
            }

            option = new ProFileOption("PRECOMPILED_HEADER");
            option.Comment = Resources.ec_PrecompiledHeader;
            option.ShortComment = "Using Precompiled Headers";
            option.AssignSymbol = ProFileOption.AssignType.AT_Equals;
            content.Options.Add(option);

            if (qtPro.UsesPrecompiledHeaders())
                option.List.Add(compiler.GetPrecompiledHeaderThrough());

            // add the depend path option
            option = new ProFileOption("DEPENDPATH");
            option.Comment = Resources.ec_DependPath;
            option.ShortComment = "Depend Path";
            content.Options.Add(option);
            option.List.Add(".");

            string mocDir = QtVSIPSettings.GetMocDirectory(project, activeConfig.ToLower(), activePlatform.ToLower());
            mocDir = mocDir.Replace('\\', '/');
            option = new ProFileOption("MOC_DIR");
            option.Comment = Resources.ec_MocDir;
            option.ShortComment = "Moc Directory";
            option.NewOption = null; // just one option...
            content.Options.Add(option);
            option.List.Add(mocDir);

            option = new ProFileOption("OBJECTS_DIR");
            option.Comment = Resources.ec_ObjDir;
            option.ShortComment = "Objects Directory";
            option.NewOption = null; // just one option...
            content.Options.Add(option);
            option.List.Add(config.ConfigurationName.ToLower());

            string uiDir = QtVSIPSettings.GetUicDirectory(project);
            uiDir = uiDir.Replace('\\', '/');
            option = new ProFileOption("UI_DIR");
            option.Comment = Resources.ec_UiDir;
            option.ShortComment = "UI Directory";
            option.NewOption = null; // just one option...
            content.Options.Add(option);
            option.List.Add(uiDir);

            string rccDir = QtVSIPSettings.GetRccDirectory(project);
            rccDir = rccDir.Replace('\\', '/');
            option = new ProFileOption("RCC_DIR");
            option.Comment = Resources.ec_RccDir;
            option.ShortComment = "RCC Directory";
            option.NewOption = null; // just one option...
            content.Options.Add(option);
            option.List.Add(rccDir);

            // add the include path option
            option = new ProFileOption("include");
            option.Comment = Resources.ec_Include;
            option.ShortComment = "Include file(s)";
            option.IncludeComment = false; // print the comment in the output file
            option.AssignSymbol = ProFileOption.AssignType.AT_Function;
            content.Options.Add(option);

            // add the translation files
            option = new ProFileOption("TRANSLATIONS");
            option.Comment = Resources.ec_Translations;
            option.ShortComment = "Translation files";
            option.IncludeComment = false;
            content.Options.Add(option);
            option.List.AddRange(HelperFunctions.GetProjectFiles(project, FilesToList.FL_Translation));

            // add the rc file
            if (File.Exists(qtPro.VCProject.ProjectDirectory + "\\" + project.Name + ".rc"))
            {
                option = new ProFileOption("win32:RC_FILE");
                option.Comment = Resources.ec_rcFile;
                option.ShortComment = "Windows resource file";
                option.IncludeComment = false;
                option.AssignSymbol = ProFileOption.AssignType.AT_Equals;
                content.Options.Add(option);
                option.List.Add(project.Name + ".rc");
            }

            if (qtPro.IsDesignerPluginProject())
            {
                option = new ProFileOption("target.path");
                option.ShortComment = "Install the plugin in the designer plugins directory.";
                option.IncludeComment = true;
                option.AssignSymbol = ProFileOption.AssignType.AT_Equals;
                option.List.Add("$$[QT_INSTALL_PLUGINS]/designer");
                content.Options.Add(option);

                option = new ProFileOption("INSTALLS");
                option.IncludeComment = false;
                option.AssignSymbol = ProFileOption.AssignType.AT_PlusEquals;
                option.List.Add("target");
                content.Options.Add(option);
            }

            return content;
        }
Example #4
0
        private static void AddPreprocessorDefinitions(ProFileOption option, string preprocessorDefinitions)
        {
            if (preprocessorDefinitions == null)
                return;

            string excludeList = "UNICODE WIN32 NDEBUG QDESIGNER_EXPORT_WIDGETS ";
            excludeList += "QT_THREAD_SUPPORT QT_PLUGIN QT_NO_DEBUG QT_CORE_LIB QT_GUI_LIB";

            foreach (string define in preprocessorDefinitions.Split(new char[] {';', ','}))
            {
                if (excludeList.IndexOf(define.ToUpper()) == -1)
                    option.List.Add(define);
            }
        }
Example #5
0
        private static void AddModules(QtProject qtPrj, ProFileOption optionQT, ProFileOption optionCONFIG)
        {
            foreach (QtModuleInfo moduleInfo in QtModules.Instance.GetAvailableModuleInformation())
            {
                if (!qtPrj.HasModule(moduleInfo.ModuleId))
                    continue;

                if (moduleInfo.proVarQT != null)
                    optionQT.List.Add(moduleInfo.proVarQT);
                if (moduleInfo.proVarCONFIG != null)
                    optionCONFIG.List.Add(moduleInfo.proVarCONFIG);
            }
        }
Example #6
0
        private static void AddLibraries(EnvDTE.Project project, ProFileOption option, string paths, string deps)
        {
            QtVersionManager versionManager = QtVersionManager.The();
            string qtDir = versionManager.GetInstallPath(project);
            if (qtDir == null)
                qtDir = System.Environment.GetEnvironmentVariable("QTDIR");
            if (qtDir == null)
                qtDir = "";

            qtDir = HelperFunctions.NormalizeRelativeFilePath(qtDir);

            if (paths != null)
            {
                foreach (string s in paths.Split(new char[] {';', ','}))
                {
                    string d = HelperFunctions.NormalizeRelativeFilePath(s);
                    if (!d.ToLower().StartsWith("$(qtdir)\\lib") &&
                        !d.ToLower().StartsWith(qtDir + "\\lib"))
                    {
                        if (HelperFunctions.IsAbsoluteFilePath(d))
                            d = HelperFunctions.GetRelativePath(project.FullName, d);
                        if (!HelperFunctions.IsAbsoluteFilePath(d))
                            option.List.Add("-L\"" + HelperFunctions.ChangePathFormat(d) + "\"");
                    }
                }
            }

            if (deps != null)
            {
                foreach (string s in deps.Split(new char[] {' '}))
                {
                    string d = s.ToLower();
                    if (d.Length > 0 &&
                        !d.StartsWith("$(qtdir)\\lib") &&
                        !d.StartsWith(qtDir + "\\lib") &&
                        !d.StartsWith("qt") && !d.StartsWith(".\\qt") && d != ".")
                        option.List.Add("-l" + HelperFunctions.ChangePathFormat(s).Replace(".lib", ""));
                }
            }
        }
Example #7
0
        private static void AddIncludePaths(EnvDTE.Project project, ProFileOption option, string includePaths)
        {
            if (includePaths == null)
                return;

            QtVersionManager versionManager = QtVersionManager.The();
            string qtDir = versionManager.GetInstallPath(project);
            if (qtDir == null)
                qtDir = System.Environment.GetEnvironmentVariable("QTDIR");
            if (qtDir == null)
                qtDir = "";

            qtDir = HelperFunctions.NormalizeRelativeFilePath(qtDir);

            foreach (string s in includePaths.Split(new char[] {';', ','}))
            {
                string d = HelperFunctions.NormalizeRelativeFilePath(s);
                if (!d.ToLower().StartsWith("$(qtdir)\\include") &&
                    !d.ToLower().StartsWith(qtDir + "\\include") &&
                    !d.ToLower().EndsWith("win32-msvc2005"))
                {
                    d = d.Replace("$(ConfigurationName)", project.ConfigurationManager.ActiveConfiguration.ConfigurationName);
                    d = d.Replace("$(PlatformName)", project.ConfigurationManager.ActiveConfiguration.PlatformName);
                    if (HelperFunctions.IsAbsoluteFilePath(d))
                        d = HelperFunctions.GetRelativePath(project.FullName, d);
                    if (!HelperFunctions.IsAbsoluteFilePath(d))
                        option.List.Add(HelperFunctions.ChangePathFormat(d));
                }
            }
        }
Example #8
0
        private void WriteProSolution(ProSolution prosln, bool openFile)
        {
            EnvDTE.Solution sln = prosln.ProjectSolution;
            if (string.IsNullOrEmpty(sln.FileName))
                return;

            FileInfo fi = new FileInfo(sln.FullName);
            DirectoryInfo slnDir = fi.Directory;
            bool createSlnFile = false;

            if ((slnDir != null) && (prosln.ProFiles.Count > 1))
            {
                if (MessageBox.Show(SR.GetString("ExportProject_SolutionProFileBuildIn", slnDir.FullName),
                    SR.GetString("ExportSolution"), MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    createSlnFile = true;
            }

            if (createSlnFile)
            {
                StreamWriter sw;
                string slnName = HelperFunctions.RemoveFileNameExtension(fi);
                string slnFileName = slnDir.FullName + "\\" + slnName + ".pro";

                if (File.Exists(slnFileName))
                    if (MessageBox.Show(SR.GetString("ExportProject_ExistsOverwriteQuestion", slnFileName),
                        SR.GetString("ExportSolution"), MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                        return;

                try
                {
                    sw = new StreamWriter(File.Create(slnFileName));
                }
                catch (System.Exception e)
                {
                    Messages.DisplayErrorMessage(e);
                    return;
                }

                ProFileContent content = new ProFileContent(null);

                ProFileOption option = new ProFileOption("TEMPLATE");
                option.NewOption = null; // just one option...
                option.AssignSymbol = ProFileOption.AssignType.AT_Equals;
                content.Options.Add(option);
                option.List.Add("subdirs");

                option = new ProFileOption("SUBDIRS");
                option.ShortComment = "#Projects";
                content.Options.Add(option);

                string proFullName, relativePath;
                char [] trimChars = {'\\'};
                foreach (ProFileContent profile in prosln.ProFiles)
                {
                    FileInfo fiProject = new FileInfo(profile.Project.ProjectFile);
                    string projectBaseName = HelperFunctions.RemoveFileNameExtension(fiProject);
                    proFullName = profile.Project.ProjectDirectory + projectBaseName + ".pro";
                    relativePath = HelperFunctions.GetRelativePath(slnDir.FullName, proFullName);
                    relativePath = relativePath.TrimEnd(trimChars);
                    relativePath = HelperFunctions.ChangePathFormat(relativePath.Remove(0,2));
                    option.List.Add(relativePath);
                }

                using (sw)
                {
                    sw.WriteLine(Resources.exportSolutionHeader);
                    for (int i=0; i<content.Options.Count; i++)
                    {
                        WriteProFileOption(sw, (ProFileOption)content.Options[i]);
                    }
                }

                if (openFile)
                    dteObject.OpenFile(EnvDTE.Constants.vsViewKindTextView, slnFileName).Activate();
            }
        }