Esempio n. 1
0
        public static string GetQtDirFromQMakeProject(Project project)
        {
            VCProject vcProject = project.Object as VCProject;
            if (vcProject == null)
                return null;

            try
            {
                foreach (VCConfiguration projectConfig in vcProject.Configurations as IVCCollection)
                {
                    CompilerToolWrapper compiler = CompilerToolWrapper.Create(projectConfig);
                    if (compiler != null)
                    {
                        List<string> additionalIncludeDirectories = compiler.AdditionalIncludeDirectories;
                        if (additionalIncludeDirectories != null)
                        {
                            foreach (string dir in additionalIncludeDirectories)
                            {
                                string subdir = Path.GetFileName(dir);
                                if (subdir != "QtCore" && subdir != "QtGui")    // looking for Qt include directories
                                    continue;
                                string dirName = Path.GetDirectoryName(dir);    // cd ..
                                dirName = Path.GetDirectoryName(dirName);       // cd ..
                                if (!Path.IsPathRooted(dirName))
                                {
                                    string projectDir = Path.GetDirectoryName(project.FullName);
                                    dirName = Path.Combine(projectDir, dirName);
                                    dirName = Path.GetFullPath(dirName);
                                }
                                return dirName;
                            }
                        }
                    }

                    VCLinkerTool linker = (VCLinkerTool)((IVCCollection)projectConfig.Tools).Item("VCLinkerTool");
                    if (linker != null)
                    {
                        LinkerToolWrapper linkerWrapper = new LinkerToolWrapper(linker);
                        List<string> linkerPaths = linkerWrapper.AdditionalDependencies;
                        if (linkerPaths != null)
                        {
                            foreach (string library in linkerPaths)
                            {
                                string lowerLibrary = library.ToLower();
                                int idx = lowerLibrary.IndexOf("\\lib\\qtmain.lib");
                                if (idx == -1)
                                    idx = lowerLibrary.IndexOf("\\lib\\qtmaind.lib");
                                if (idx == -1)
                                    idx = lowerLibrary.IndexOf("\\lib\\qtcore5.lib");
                                if (idx == -1)
                                    idx = lowerLibrary.IndexOf("\\lib\\qtcored5.lib");
                                if (idx == -1)
                                    continue;

                                string dirName = Path.GetDirectoryName(library);
                                dirName = Path.GetDirectoryName(dirName);   // cd ..
                                if (!Path.IsPathRooted(dirName))
                                {
                                    string projectDir = Path.GetDirectoryName(project.FullName);
                                    dirName = Path.Combine(projectDir, dirName);
                                    dirName = Path.GetFullPath(dirName);
                                }

                                return dirName;
                            }
                        }

                        linkerPaths = linkerWrapper.AdditionalLibraryDirectories;
                        if (linker != null && linkerPaths != null)
                        {
                            foreach (string libDir in linkerPaths)
                            {
                                string dirName = libDir;
                                if (!Path.IsPathRooted(dirName))
                                {
                                    string projectDir = Path.GetDirectoryName(project.FullName);
                                    dirName = Path.Combine(projectDir, dirName);
                                    dirName = Path.GetFullPath(dirName);
                                }

                                if (File.Exists(dirName + "\\qtmain.lib") ||
                                    File.Exists(dirName + "\\qtmaind.lib") ||
                                    File.Exists(dirName + "\\QtCore5.lib") ||
                                    File.Exists(dirName + "\\QtCored5.lib"))
                                {
                                    return Path.GetDirectoryName(dirName);
                                }
                            }
                        }
                    }
                }
            }
            catch { }

            return null;
        }
Esempio n. 2
0
 public static void CleanupQMakeDependencies(EnvDTE.Project project)
 {
     VCProject vcPro = (VCProject)project.Object;
     // clean up qmake mess
     Regex rxp1 = new Regex("\\bQt\\w+d?5?\\.lib\\b");
     Regex rxp2 = new Regex("\\bQAx\\w+\\.lib\\b");
     Regex rxp3 = new Regex("\\bqtmaind?.lib\\b");
     Regex rxp4 = new Regex("\\bphonond?5?\\.lib\\b");
     foreach (VCConfiguration cfg in (IVCCollection)vcPro.Configurations)
     {
         VCLinkerTool linker = (VCLinkerTool)((IVCCollection)cfg.Tools).Item("VCLinkerTool");
         if (linker == null || linker.AdditionalDependencies == null)
             continue;
         LinkerToolWrapper linkerWrapper = new LinkerToolWrapper(linker);
         List<string> deps = linkerWrapper.AdditionalDependencies;
         List<string> newDeps = new List<string>();
         foreach (string lib in deps)
         {
             Match m1 = rxp1.Match(lib);
             Match m2 = rxp2.Match(lib);
             Match m3 = rxp3.Match(lib);
             Match m4 = rxp4.Match(lib);
             if (m1.Success)
                 newDeps.Add(m1.ToString());
             else if (m2.Success)
                 newDeps.Add(m2.ToString());
             else if (m3.Success)
                 newDeps.Add(m3.ToString());
             else if (m4.Success)
                 newDeps.Add(m4.ToString());
             else
                 newDeps.Add(lib);
         }
         // Remove Duplicates
         Dictionary<string, int> uniques = new Dictionary<string,int>();
         foreach (string dep in newDeps)
         {
             uniques[dep] = 1;
         }
         List<string> uniqueList = new List<string>(uniques.Keys);
         linkerWrapper.AdditionalDependencies = uniqueList;
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Toggles the kind of a project. If the project is a QMake generated project (qmake -tp vc)
        /// it is transformed to an Add-in Qt project and vice versa.
        /// </summary>
        /// <param name="project">Project</param>
        /// <returns></returns>
        public static void ToggleProjectKind(EnvDTE.Project project)
        {
            string qtDir = null;
            VCProject vcPro = (VCProject)project.Object;
            if (!IsQMakeProject(project))
                return;

            if (IsQt5Project(project))
            {
                QtProject qtPro = QtProject.Create(project);
                QtVersionManager vm = QtVersionManager.The(HelperFunctions.GetProjectPlatformName(project));

                qtDir = vm.GetInstallPath(project);

                foreach (string global in (string[])project.Globals.VariableNames)
                {
                    if (global.StartsWith("Qt5Version"))
                    {
                        project.Globals.set_VariablePersists(global, false);
                    }
                }

                foreach (VCConfiguration config in (IVCCollection)vcPro.Configurations)
                {
                    CompilerToolWrapper compiler = CompilerToolWrapper.Create(config);
                    VCLinkerTool linker = (VCLinkerTool)((IVCCollection)config.Tools).Item("VCLinkerTool");
                    VCLibrarianTool librarian = (VCLibrarianTool)((IVCCollection)config.Tools).Item("VCLibrarianTool");
                    if (compiler != null)
                    {
                        string additionalIncludes = compiler.GetAdditionalIncludeDirectories();
                        additionalIncludes = ReplaceCaseInsensitive(additionalIncludes, "$(QTDIR)", qtDir);
                        compiler.SetAdditionalIncludeDirectories(additionalIncludes);
                    }
                    if (linker != null)
                    {
                        linker.AdditionalLibraryDirectories = ReplaceCaseInsensitive(linker.AdditionalLibraryDirectories, "$(QTDIR)", qtDir);
                        linker.AdditionalDependencies = AddFullPathToAdditionalDependencies(qtDir, linker.AdditionalDependencies);
                    }
                    else
                    {
                        librarian.AdditionalLibraryDirectories = ReplaceCaseInsensitive(librarian.AdditionalLibraryDirectories, "$(QTDIR)", qtDir);
                        librarian.AdditionalDependencies = AddFullPathToAdditionalDependencies(qtDir, librarian.AdditionalDependencies);
                    }
                }

                ReplaceInCustomBuildTools(project, "$(QTDIR)", qtDir);
            }
            else if (IsQMakeProject(project))
            {
                qtDir = GetQtDirFromQMakeProject(project);

                QtVersionManager vm = QtVersionManager.The(HelperFunctions.GetProjectPlatformName(project));

                string qtVersion = vm.GetQtVersionFromInstallDir(qtDir);
                if (qtVersion == null)
                    qtVersion = "$(DefaultQtVersion)";
                if (qtDir == null)
                    qtDir = vm.GetInstallPath(qtVersion);
                VersionInformation vi = vm.GetVersionInfo(qtVersion);
                string platformName = vi.GetVSPlatformName();
                vm.SaveProjectQtVersion(project, qtVersion, platformName);
                QtProject qtPro = QtProject.Create(project);
                if (!qtPro.SelectSolutionPlatform(platformName) || !qtPro.HasPlatform(platformName))
                {
                    bool newProject = false;
                    qtPro.CreatePlatform("Win32", platformName, null, vi, ref newProject);
                    if (!qtPro.SelectSolutionPlatform(platformName))
                    {
                        Messages.PaneMessage(project.DTE, "Can't select the platform " + platformName + ".");
                    }
                }

                string activeConfig = project.ConfigurationManager.ActiveConfiguration.ConfigurationName;
                VCConfiguration activeVCConfig = (VCConfiguration)((IVCCollection)qtPro.VCProject.Configurations).Item(activeConfig);
                if (activeVCConfig.ConfigurationType == ConfigurationTypes.typeDynamicLibrary)
                {
                    CompilerToolWrapper compiler = CompilerToolWrapper.Create(activeVCConfig);
                    VCLinkerTool linker = (VCLinkerTool)((IVCCollection)activeVCConfig.Tools).Item("VCLinkerTool");
                    string ppdefs = compiler.GetPreprocessorDefinitions();
                    if (ppdefs != null
                        && ppdefs.IndexOf("QT_PLUGIN") > -1
                        && ppdefs.IndexOf("QDESIGNER_EXPORT_WIDGETS") > -1
                        && ppdefs.IndexOf("QtDesigner") > -1
                        && linker.AdditionalDependencies != null
                        && linker.AdditionalDependencies.IndexOf("QtDesigner") > -1)
                    {
                        qtPro.MarkAsDesignerPluginProject();
                    }
                }

                HelperFunctions.CleanupQMakeDependencies(project);

                foreach (VCConfiguration config in (IVCCollection)vcPro.Configurations)
                {
                    CompilerToolWrapper compiler = CompilerToolWrapper.Create(config);
                    VCLinkerTool linker = (VCLinkerTool)((IVCCollection)config.Tools).Item("VCLinkerTool");

                    if (compiler != null)
                    {
                        List<string> additionalIncludes = compiler.AdditionalIncludeDirectories;
                        if (additionalIncludes != null)
                        {
                            ReplaceDirectory(ref additionalIncludes, qtDir, "$(QTDIR)", project);
                            compiler.AdditionalIncludeDirectories = additionalIncludes;
                        }
                    }
                    if (linker != null)
                    {
                        LinkerToolWrapper linkerToolWrapper = new LinkerToolWrapper(linker);
                        List<string> additionalLibraries = linkerToolWrapper.AdditionalLibraryDirectories;
                        if (additionalLibraries != null)
                        {
                            ReplaceDirectory(ref additionalLibraries, qtDir, "$(QTDIR)", project);
                            linkerToolWrapper.AdditionalLibraryDirectories = additionalLibraries;
                        }
                    }
                }

                ReplaceInCustomBuildTools(project, qtDir, "$(QTDIR)");
                qtPro.TranslateFilterNames();
            }
            else
            {
                QtVersionManager vm = QtVersionManager.The(HelperFunctions.GetProjectPlatformName(project));

                string qtVersion = vm.GetQtVersionFromInstallDir(qtDir);
                if (qtVersion == null)
                    qtVersion = "$(DefaultQtVersion)";
                if (qtDir == null)
                    qtDir = vm.GetInstallPath(qtVersion);

                VersionInformation vi = vm.GetVersionInfo(qtVersion);
                string platformName = vi.GetVSPlatformName();

                vm.SaveProjectQtVersion(project, qtVersion, platformName);
                QtProject qtPro = QtProject.Create(project);
                qtPro.MarkAsQtProject("v1.0");

                if (!qtPro.SelectSolutionPlatform(platformName) || !qtPro.HasPlatform(platformName))
                {
                    bool newProject = false;
                    qtPro.CreatePlatform("Win32", platformName, null, vi, ref newProject);
                    if (!qtPro.SelectSolutionPlatform(platformName))
                    {
                        Messages.PaneMessage(project.DTE, "Can't select the platform " + platformName + ".");
                    }
                }

                foreach (VCConfiguration config in (IVCCollection)vcPro.Configurations)
                {
                    CompilerToolWrapper compiler = CompilerToolWrapper.Create(config);
                    VCLinkerTool linker = (VCLinkerTool)((IVCCollection)config.Tools).Item("VCLinkerTool");

                    if (compiler != null)
                    {
                        List<string> additionalIncludes = compiler.AdditionalIncludeDirectories;
                        if (additionalIncludes != null)
                        {
                            additionalIncludes.Add("$(QTDIR)\\include");
                            compiler.AdditionalIncludeDirectories = additionalIncludes;
                        }
                    }
                    if (linker != null)
                    {
                        LinkerToolWrapper linkerToolWrapper = new LinkerToolWrapper(linker);
                        List<string> additionalLibraries = linkerToolWrapper.AdditionalLibraryDirectories;
                        if (additionalLibraries != null)
                        {
                            additionalLibraries.Add("$(QTDIR)\\lib");
                            linkerToolWrapper.AdditionalLibraryDirectories = additionalLibraries;
                        }
                        if (config.ConfigurationType == ConfigurationTypes.typeApplication)
                        {
                            List<string> additionalDependencies = linkerToolWrapper.AdditionalDependencies;
                            if (additionalDependencies != null)
                            {
                                if (config.ConfigurationName.IndexOf("Debug") != -1)
                                {
                                    additionalDependencies.Add("qtmaind.lib");
                                }
                                else
                                {
                                    additionalDependencies.Add("qtmain.lib");
                                }
                                linkerToolWrapper.AdditionalDependencies = additionalDependencies;
                            }
                        }
                    }
                }

                qtPro.TranslateFilterNames();
            }
            project.Save(project.FullName);
        }
Esempio n. 4
0
        public void UpdateModules(VersionInformation oldVersion, VersionInformation newVersion)
        {
            foreach (VCConfiguration config in (IVCCollection)vcPro.Configurations)
            {
                VCLinkerTool linker = (VCLinkerTool)((IVCCollection)config.Tools).Item("VCLinkerTool");

                if (linker != null)
                {
                    if (oldVersion == null || oldVersion.IsWinCEVersion() != newVersion.IsWinCEVersion())
                    {
                        LinkerToolWrapper linkerWrapper = new LinkerToolWrapper(linker);
                        List<string> additionalDependencies = linkerWrapper.AdditionalDependencies;

                        List<string> libsDesktop = new List<string>();
                        List<string> libsWinCE = new List<string>();
                        foreach (QtModuleInfo module in QtModules.Instance.GetAvailableModuleInformation())
                        {
                            if (HasModule(module.ModuleId))
                            {
                                libsDesktop.AddRange(module.AdditionalLibraries);
                                libsWinCE.AddRange(module.AdditionalLibrariesWinCE);
                            }
                        }
                        List<string> libsToAdd = null;
                        List<string> libsToRemove = null;
                        if (newVersion.IsWinCEVersion())
                        {
                            libsToAdd = libsWinCE;
                            libsToRemove = libsDesktop;
                        }
                        else
                        {
                            libsToAdd = libsDesktop;
                            libsToRemove = libsWinCE;
                        }

                        bool changed = false;
                        foreach (string libToRemove in libsToRemove)
                        {
                            if (additionalDependencies.Remove(libToRemove))
                                changed = true;
                        }
                        foreach (string libToAdd in libsToAdd)
                        {
                            if (!additionalDependencies.Contains(libToAdd))
                            {
                                additionalDependencies.Add(libToAdd);
                                changed = true;
                            }
                        }
                        if (changed)
                            linkerWrapper.AdditionalDependencies = additionalDependencies;
                    }

            #if ENABLE_WINCE
                    if (newVersion.IsWinCEVersion() && newVersion.IsStaticBuild() &&
                        oldVersion != null &&
                        !(oldVersion.IsWinCEVersion() && oldVersion.IsStaticBuild()) &&
                        config.DeploymentTool != null)
                    {
                        RemoveQtDeploys(config);
                    }
            #endif

                    if (oldVersion == null || newVersion.IsStaticBuild() != oldVersion.IsStaticBuild())
                    {
                        CompilerToolWrapper compiler = CompilerToolWrapper.Create(config);
                        if (newVersion.IsStaticBuild())
                        {
                            if (compiler != null)
                                compiler.RemovePreprocessorDefinition("QT_DLL");
                        }
                        else
                        {
                            if (compiler != null)
                                compiler.AddPreprocessorDefinition("QT_DLL");
                        }
                    }

            #if ENABLE_WINCE
                    if (newVersion.IsWinCEVersion() && !newVersion.IsStaticBuild() &&
                        (oldVersion == null ||
                        !(oldVersion.IsWinCEVersion() && !oldVersion.IsStaticBuild())) &&
                        config.DeploymentTool != null)
                    {
                        MatchCollection matches = Regex.Matches(linker.AdditionalDependencies, "Qt(\\S+)5\\.lib");
                        foreach (Match m in matches)
                        {
                            string moduleName = m.ToString().Substring(0, m.ToString().Length - 5);
                            if (config.ConfigurationName.StartsWith("Debug"))
                                moduleName = moduleName.Substring(0, moduleName.Length - 1);
                            QtModule module = QtModules.Instance.ModuleIdByName(moduleName);
                            AddDeploySettings(null, module, config, null, newVersion);
                        }
                    }
            #endif
                }
            }
        }
Esempio n. 5
0
        public void RemoveModule(QtModule module)
        {
            foreach (VCConfiguration config in (IVCCollection)vcPro.Configurations)
            {
                CompilerToolWrapper compiler = CompilerToolWrapper.Create(config);
                VCLinkerTool linker = (VCLinkerTool)((IVCCollection)config.Tools).Item("VCLinkerTool");

                QtModuleInfo info = QtModules.Instance.ModuleInformation(module);
                if (compiler != null)
                {
                    foreach (string define in info.Defines)
                        compiler.RemovePreprocessorDefinition(define);
                    List<string> additionalIncludeDirs = compiler.AdditionalIncludeDirectories;
                    if (additionalIncludeDirs != null)
                    {
                        List<string> lst = new List<string>(additionalIncludeDirs);
                        if (!String.IsNullOrEmpty(info.IncludePath))
                        {
                            lst.Remove(info.IncludePath);
                            lst.Remove('\"' + info.IncludePath + '\"');
                        }
                        compiler.AdditionalIncludeDirectories = lst;
                    }
                }
                if (linker != null && linker.AdditionalDependencies != null)
                {
                    LinkerToolWrapper linkerWrapper = new LinkerToolWrapper(linker);
                    QtVersionManager vm = QtVersionManager.The();
                    VersionInformation versionInfo = vm.GetVersionInfo(this.Project);
                    if (versionInfo == null)
                        versionInfo = vm.GetVersionInfo(vm.GetDefaultVersion());

                    List<string> moduleLibs = info.GetLibs(IsDebugConfiguration(config), versionInfo);
                    List<string> additionalDependencies = linkerWrapper.AdditionalDependencies;
                    bool dependenciesChanged = false;
                    foreach (string moduleLib in moduleLibs)
                        if (additionalDependencies.Remove(moduleLib))
                            dependenciesChanged = true;
                    if (dependenciesChanged)
                        linkerWrapper.AdditionalDependencies = additionalDependencies;
                }

            #if ENABLE_WINCE
                if (info.HasDLL && config.DeploymentTool != null)
                    RemoveDeploySettings(null, module, config, info);
            #endif
            }
        }
Esempio n. 6
0
        public bool HasModule(QtModule module)
        {
            bool foundInIncludes = false;
            bool foundInLibs = false;

            QtVersionManager vm = QtVersionManager.The();
            VersionInformation versionInfo = vm.GetVersionInfo(this.Project);
            if (versionInfo == null)
                versionInfo = vm.GetVersionInfo(vm.GetDefaultVersion());

            foreach (VCConfiguration config in (IVCCollection)vcPro.Configurations)
            {
                CompilerToolWrapper compiler = CompilerToolWrapper.Create(config);
                VCLinkerTool linker = (VCLinkerTool)((IVCCollection)config.Tools).Item("VCLinkerTool");

                QtModuleInfo info = QtModules.Instance.ModuleInformation(module);
                if (compiler != null)
                {
                    string incPath = info.GetIncludePath();
                    if (String.IsNullOrEmpty(incPath))
                        break;
                    if (compiler.GetAdditionalIncludeDirectories() == null)
                        continue;

                    string fixedIncludeDir = FixFilePathForComparison(incPath);
                    string[] includeDirs = compiler.GetAdditionalIncludeDirectoriesList();
                    foreach (string dir in includeDirs)
                    {
                        if (FixFilePathForComparison(dir) == fixedIncludeDir)
                        {
                            foundInIncludes = true;
                            break;
                        }
                    }
                }

                if (foundInIncludes)
                    break;

                List<string> libs = null;
                if (linker != null)
                {
                    LinkerToolWrapper linkerWrapper = new LinkerToolWrapper(linker);
                    libs = linkerWrapper.AdditionalDependencies;
                }

                if (libs != null)
                {
                    foundInLibs = true;
                    List<string> moduleLibs = info.GetLibs(IsDebugConfiguration(config), versionInfo);
                    foreach (string moduleLib in moduleLibs)
                    {
                        if (!libs.Contains(moduleLib))
                        {
                            foundInLibs = false;
                            break;
                        }
                    }
                }
            }
            return foundInIncludes || foundInLibs;
        }
Esempio n. 7
0
        public void AddModule(QtModule module)
        {
            if (HasModule(module))
                return;

            QtVersionManager vm = QtVersionManager.The();
            VersionInformation versionInfo = vm.GetVersionInfo(this.Project);
            if (versionInfo == null)
                versionInfo = vm.GetVersionInfo(vm.GetDefaultVersion());

            foreach (VCConfiguration config in (IVCCollection)vcPro.Configurations)
            {
                CompilerToolWrapper compiler = CompilerToolWrapper.Create(config);
                VCLinkerTool linker = (VCLinkerTool)((IVCCollection)config.Tools).Item("VCLinkerTool");

                QtModuleInfo info = QtModules.Instance.ModuleInformation(module);
                if (compiler != null)
                {
                    foreach(string define in info.Defines)
                        compiler.AddPreprocessorDefinition(define);

                    string incPath = info.GetIncludePath();
                    if (!String.IsNullOrEmpty(incPath))
                        compiler.AddAdditionalIncludeDirectories(incPath);
                }
                if (linker != null)
                {
                    List<string> moduleLibs = info.GetLibs(IsDebugConfiguration(config), versionInfo);
                    LinkerToolWrapper linkerWrapper = new LinkerToolWrapper(linker);
                    List<string> additionalDeps = linkerWrapper.AdditionalDependencies;
                    bool dependenciesChanged = false;
                    if (additionalDeps == null || additionalDeps.Count == 0)
                    {
                        additionalDeps = moduleLibs;
                        dependenciesChanged = true;
                    }
                    else
                    {
                        foreach (string moduleLib in moduleLibs)
                            if (!additionalDeps.Contains(moduleLib))
                            {
                                additionalDeps.Add(moduleLib);
                                dependenciesChanged = true;
                            }
                    }
                    if (dependenciesChanged)
                        linkerWrapper.AdditionalDependencies = additionalDeps;
                }

            #if ENABLE_WINCE
                if (info.HasDLL && config.DeploymentTool != null)
                    AddDeploySettings(null, module, config, info, versionInfo);
            #endif
            }
        }