Beispiel #1
0
 public QMake(EnvDTE.DTE dte, string fileName, bool recursiveRun, VersionInformation vi)
 {
     dteObject            = dte;
     file                 = fileName;
     recursive            = recursiveRun;
     qtVersionInformation = vi;
 }
Beispiel #2
0
        private void CreateWinCEProject(EnvDTE.DTE app, string proName, string proPath, string slnName,
                                        bool exclusive, string qtVersion, uint projType, bool usePrecompiledHeaders)
        {
            FakeFilter[] filters = { Filters.SourceFiles(), Filters.HeaderFiles(),
                                     Filters.FormFiles(),   Filters.ResourceFiles(), Filters.GeneratedFiles() };

            QtVersionManager versionManager = QtVersionManager.The();

            if (qtVersion == null)
            {
                qtVersion = versionManager.GetDefaultWinCEVersion();
            }
            VersionInformation qtVersionInfo = versionManager.GetVersionInfo(qtVersion);
            string             platformName  = null;

            try
            {
                platformName = qtVersionInfo.GetVSPlatformName();
            }
            catch
            {
                // fallback to some standard platform...
                platformName = "Windows Mobile 5.0 Pocket PC SDK (ARMV4I)";
            }

            CreateProject(app, proName, proPath, slnName, exclusive, filters, qtVersion, platformName);
            qtPro.WriteProjectBasicConfigurations(projType, usePrecompiledHeaders, qtVersionInfo);
            qtPro.AddModule(QtModule.Main);
        }
Beispiel #3
0
        protected void Init(VersionInformation versionInfo)
        {
            string filename = versionInfo.qtDir + "\\mkspecs\\default\\qmake.conf";

            fileInfo = new FileInfo(filename);

            // Starting from Qt5 beta2 there is no more "\\mkspecs\\default" folder available
            // To find location of "qmake.conf" there is a need to run "qmake -query" command
            // This is what happens below.
            if (!fileInfo.Exists)
            {
                QMakeQuery qmakeQuery = new QMakeQuery(versionInfo);

                qmakeQuery.ReadyEvent += new QMakeQuery.EventHandler(this.CloseEventHandler);
                System.Threading.Thread qmakeThread = new System.Threading.Thread(new ThreadStart(qmakeQuery.RunQMakeQuery));
                qmakeThread.Start();
                qmakeThread.Join();

                if (qmakeQuery.ErrorValue != 0)
                {
                    throw new Qt4VSException("qmake.conf not found");
                }

                if (qmakespecFolder.Length > 0)
                {
                    filename = versionInfo.qtDir + "\\mkspecs\\" + qmakespecFolder + "\\qmake.conf";
                }
            }

            Init(filename);
        }
        public VersionInformation GetVersionInfo(string name)
        {
            if (name == null)
            {
                return(null);
            }
            if (name == "$(DefaultQtVersion)")
            {
                name = GetDefaultVersion();
            }
            if (versionCache == null)
            {
                versionCache = new Hashtable();
            }

            VersionInformation vi = versionCache[name] as VersionInformation;

            if (vi != null)
            {
                return(vi);
            }

            string qtdir = GetInstallPath(name);

            vi = new VersionInformation(qtdir);
            versionCache[name] = vi;
            return(vi);
        }
Beispiel #5
0
        private FileInfo RunQmake(FileInfo mainInfo, string ext, bool recursive, VersionInformation vi)
        {
            string name = mainInfo.Name.Remove(mainInfo.Name.IndexOf('.'));

            FileInfo VCInfo = new FileInfo(mainInfo.DirectoryName + "\\" + name + ext);

            if (!VCInfo.Exists || DialogResult.Yes == MessageBox.Show(SR.GetString("ExportProject_ProjectExistsRegenerateOrReuse", VCInfo.Name),
                                                                      SR.GetString("ProjectExists"), MessageBoxButtons.YesNo, MessageBoxIcon.Question))
            {
                Messages.PaneMessage(dteObject, "--- (Import): Generating new project of " + mainInfo.Name + " file");

                InfoDialog dialog = new InfoDialog(mainInfo.Name);
                QMake      qmake  = new QMake(dteObject, mainInfo.FullName, recursive, vi);

                qmake.CloseEvent           += new QMake.ProcessEventHandler(dialog.CloseEventHandler);
                qmake.PaneMessageDataEvent += new QMake.ProcessEventHandlerArg(this.PaneMessageDataReceived);

                System.Threading.Thread qmakeThread = new System.Threading.Thread(new ThreadStart(qmake.RunQMake));
                qmakeThread.Start();
                dialog.ShowDialog();
                qmakeThread.Join();

                if (qmake.ErrorValue == 0)
                {
                    return(VCInfo);
                }
            }

            return(null);
        }
Beispiel #6
0
 private static bool CheckQtVersion(VersionInformation vi)
 {
     if (!vi.qt4Version)
     {
         Messages.DisplayWarningMessage(SR.GetString("ExportProject_EditProjectFileManually"));
         return(false);
     }
     return(true);
 }
Beispiel #7
0
        private string GetWinCEPlatformName(string qtVersion, QtVersionManager versionManager)
        {
            VersionInformation vi = versionManager.GetVersionInfo(qtVersion);

            try
            {
                return(vi.GetVSPlatformName());
            }
            catch
            {
                return("(unknown platform)");
            }
        }
Beispiel #8
0
        /// <summary>
        /// Returns the Windows CE Qt builds which are available.
        /// </summary>
        /// <returns>List of string</returns>
        public ArrayList GetQtWinCEVersions(EnvDTE.DTE dte)
        {
            ArrayList        list = new ArrayList();
            QtVersionManager vm   = QtVersionManager.The();

            foreach (string qtVersion in vm.GetVersions())
            {
                VersionInformation vi           = vm.GetVersionInfo(qtVersion);
                string             platformName = GetWinCEPlatformName(qtVersion, vm);
                if (vi.IsWinCEVersion() && HelperFunctions.IsPlatformAvailable(dte, platformName))
                {
                    list.Add(qtVersion);
                }
            }
            return(list);
        }
Beispiel #9
0
        private void ImportSolution(FileInfo mainInfo, string qtVersion)
        {
            VersionInformation versionInfo = QtVersionManager.The().GetVersionInfo(qtVersion);
            FileInfo           VCInfo      = RunQmake(mainInfo, ".sln", true, versionInfo);

            if (null == VCInfo)
            {
                return;
            }
            ReplaceAbsoluteQtDirInSolution(VCInfo);

            try
            {
                if (CheckQtVersion(versionInfo))
                {
                    dteObject.Solution.Open(VCInfo.FullName);
                    if (qtVersion != null)
                    {
                        QtVersionManager.The().SaveSolutionQtVersion(dteObject.Solution, qtVersion);
                        foreach (Project prj in HelperFunctions.ProjectsInSolution(dteObject))
                        {
                            QtVersionManager.The().SaveProjectQtVersion(prj, qtVersion);
                            QtProject qtPro = QtProject.Create(prj);
                            qtPro.SetQtEnvironment();
                            ApplyPostImportSteps(qtPro);
                        }
                    }
                }

                Messages.PaneMessage(dteObject, "--- (Import): Finished opening " + VCInfo.Name);
            }
            catch (Exception e)
            {
                Messages.DisplayCriticalErrorMessage(e);
            }
        }
Beispiel #10
0
        public void CreatePlatform(string oldPlatform, string newPlatform,
                                   VersionInformation viOld, VersionInformation viNew, ref bool newProjectCreated)
        {
            try
            {
                ConfigurationManager cfgMgr = envPro.ConfigurationManager;
                cfgMgr.AddPlatform(newPlatform, oldPlatform, true);
                vcPro.AddPlatform(newPlatform);
                newProjectCreated = false;
            }
            catch
            {
                // That stupid ConfigurationManager can't handle platform names
                // containing dots (e.g. "Windows Mobile 5.0 Pocket PC SDK (ARMV4I)")
                // So we have to do it the nasty way...
                string projectFileName = envPro.FullName;
                envPro.Save(null);
                dte.Solution.Remove(envPro);
                AddPlatformToVCProj(projectFileName, oldPlatform, newPlatform);
                envPro = dte.Solution.AddFromFile(projectFileName, false);
                vcPro = (VCProject)envPro.Object;
                newProjectCreated = true;
            }

            // update the platform settings
            foreach (VCConfiguration config in (IVCCollection)vcPro.Configurations)
            {
                VCPlatform vcplatform = (VCPlatform)config.Platform;
                if (vcplatform.Name == newPlatform)
                {
                    if (viOld != null)
                        RemovePlatformDependencies(config, viOld);
                    SetupConfiguration(config, viNew);
                }
            }

            SelectSolutionPlatform(newPlatform);
        }
Beispiel #11
0
        public void SetupConfiguration(VCConfiguration config, VersionInformation viNew)
        {
            bool isWinPlatform = (!viNew.IsWinCEVersion());

            CompilerToolWrapper compiler = CompilerToolWrapper.Create(config);
            SimpleSet ppdefs = new SimpleSet(compiler.PreprocessorDefinitions);
            ICollection newPPDefs = viNew.GetQMakeConfEntry("DEFINES").Split(new char[] { ' ', '\t' });
            compiler.SetPreprocessorDefinitions(ppdefs.Union(newPPDefs).JoinElements(','));

            #if ENABLE_WINCE
            // search prepocessor definitions for Qt modules and add deployment settings
            if (!isWinPlatform)
            {
                DeploymentToolWrapper deploymentTool = DeploymentToolWrapper.Create(config);
                if (deploymentTool != null)
                {
                    deploymentTool.Clear();
                    deploymentTool.AddWinCEMSVCStandardLib(IsDebugConfiguration(config), dte);

                    List<QtModuleInfo> availableQtModules = QtModules.Instance.GetAvailableModuleInformation();
                    foreach (string s in ppdefs.Elements)
                    {
                        foreach (QtModuleInfo moduleInfo in availableQtModules)
                        {
                            if (moduleInfo.Defines.Contains(s))
                                AddDeploySettings(deploymentTool, moduleInfo.ModuleId, config, null, viNew);
                        }
                    }
                }
            }
            #endif

            VCLinkerTool linker = (VCLinkerTool)((IVCCollection)config.Tools).Item("VCLinkerTool");
            if (linker == null)
                return;

            if (isWinPlatform)
                linker.SubSystem = subSystemOption.subSystemWindows;
            else
                linker.SubSystem = subSystemOption.subSystemNotSet;

            SetTargetMachine(linker, viNew);
        }
Beispiel #12
0
 private static bool CheckQtVersion(VersionInformation vi)
 {
     if (!vi.qt4Version)
     {
         Messages.DisplayWarningMessage(SR.GetString("ExportProject_EditProjectFileManually"));
         return false;
     }
     return true;
 }
Beispiel #13
0
        private FileInfo RunQmake(FileInfo mainInfo, string ext, bool recursive, VersionInformation vi)
        {
            string name = mainInfo.Name.Remove(mainInfo.Name.IndexOf('.'));

            FileInfo VCInfo = new FileInfo(mainInfo.DirectoryName + "\\" + name + ext);

            if (!VCInfo.Exists || DialogResult.Yes == MessageBox.Show(SR.GetString("ExportProject_ProjectExistsRegenerateOrReuse", VCInfo.Name),
                SR.GetString("ProjectExists"), MessageBoxButtons.YesNo, MessageBoxIcon.Question))
            {
                Messages.PaneMessage(dteObject, "--- (Import): Generating new project of " + mainInfo.Name + " file");

                InfoDialog dialog = new InfoDialog(mainInfo.Name);
                QMake qmake = new QMake(dteObject, mainInfo.FullName, recursive, vi);

                qmake.CloseEvent += new QMake.ProcessEventHandler(dialog.CloseEventHandler);
                qmake.PaneMessageDataEvent += new QMake.ProcessEventHandlerArg(this.PaneMessageDataReceived);

                System.Threading.Thread qmakeThread = new System.Threading.Thread(new ThreadStart(qmake.RunQMake));
                qmakeThread.Start();
                dialog.ShowDialog();
                qmakeThread.Join();

                if (qmake.ErrorValue == 0)
                    return VCInfo;
            }

            return null;
        }
        /// <summary>
        /// Check if all Qt versions are valid and readable.
        /// </summary>
        /// Also sets the default Qt version to the newest version, if needed.
        /// <param name="errorMessage"></param>
        /// <returns>true, if we found an invalid version</returns>
        public bool HasInvalidVersions(out string errorMessage)
        {
            List <QtVersion> validVersions   = new List <QtVersion>();
            List <string>    invalidVersions = new List <string>();

            foreach (string v in GetVersions())
            {
                if (v == "$(DefaultQtVersion)")
                {
                    continue;
                }
                try
                {
                    VersionInformation vi        = new VersionInformation(GetInstallPath(v));
                    QtVersion          qtVersion = new QtVersion();
                    qtVersion.name = v;
                    qtVersion.vi   = vi;
                    validVersions.Add(qtVersion);
                }
                catch (Exception)
                {
                    invalidVersions.Add(v);
                }
            }

            if (invalidVersions.Count > 0)
            {
                errorMessage = "These Qt version are inaccessible:\n";
                foreach (string invalidVersion in invalidVersions)
                {
                    errorMessage += invalidVersion + " in " + GetInstallPath(invalidVersion) + "\n";
                }
                errorMessage += "Make sure that you have read access to all files in your Qt directories.";

                // Is the default Qt version invalid?
                bool   isDefaultQtVersionInvalid = false;
                string defaultQtVersionName      = GetDefaultVersion();
                if (String.IsNullOrEmpty(defaultQtVersionName))
                {
                    isDefaultQtVersionInvalid = true;
                }
                else
                {
                    foreach (string name in invalidVersions)
                    {
                        if (name == defaultQtVersionName)
                        {
                            isDefaultQtVersionInvalid = true;
                            break;
                        }
                    }
                }

                // find the newest valid Qt version that can be used as default version
                if (isDefaultQtVersionInvalid && validVersions.Count > 0)
                {
                    QtVersion defaultQtVersion = null;
                    foreach (QtVersion v in validVersions)
                    {
                        if (v.vi.IsWinCEVersion())
                        {
                            continue;
                        }
                        if (defaultQtVersion == null)
                        {
                            defaultQtVersion = v;
                            continue;
                        }
                        if (defaultQtVersion.vi.qtMajor < v.vi.qtMajor ||
                            (defaultQtVersion.vi.qtMajor == v.vi.qtMajor && (defaultQtVersion.vi.qtMinor < v.vi.qtMinor ||
                                                                             (defaultQtVersion.vi.qtMinor == v.vi.qtMinor && defaultQtVersion.vi.qtPatch < v.vi.qtPatch))))
                        {
                            defaultQtVersion = v;
                        }
                    }
                    if (defaultQtVersion != null)
                    {
                        SaveDefaultVersion(defaultQtVersion.name);
                    }
                }

                return(true);
            }
            errorMessage = null;
            return(false);
        }
Beispiel #15
0
 public QMakeConf(VersionInformation versionInfo)
 {
     Init(versionInfo);
 }
Beispiel #16
0
        private void CreateProject(EnvDTE.DTE app, string proName,
                                   string proPath, string slnName, bool exclusive, FakeFilter[] filters,
                                   string qtVersion, string platformName)
        {
            QtVersionManager versionManager = QtVersionManager.The();

            if (qtVersion == null)
            {
                qtVersion = "$(DefaultQtVersion)";
            }

            if (qtVersion == null)
            {
                throw new Qt4VSException("Unable to find a Qt build!\r\n"
                                         + "To solve this problem specify a Qt build");
            }

            string   solutionPath = "";
            Solution newSolution  = app.Solution;

            if (platformName == null)
            {
                string tmpQtVersion = versionManager.GetSolutionQtVersion(newSolution);
                qtVersion = tmpQtVersion != null ? tmpQtVersion : qtVersion;
                try
                {
                    VersionInformation vi = new VersionInformation(versionManager.GetInstallPath(qtVersion));
                    if (vi.is64Bit())
                    {
                        platformName = "x64";
                    }
                    else
                    {
                        platformName = "Win32";
                    }
                }
                catch (Exception e)
                {
                    Messages.DisplayErrorMessage(e);
                }
            }

            if (!string.IsNullOrEmpty(slnName) && (exclusive == true))
            {
                solutionPath = proPath.Substring(0, proPath.LastIndexOf("\\"));
                newSolution.Create(solutionPath, slnName);
            }

            System.IO.Directory.CreateDirectory(proPath);
            string templatePath = HelperFunctions.CreateProjectTemplateFile(filters, true, platformName);

            pro = newSolution.AddFromTemplate(templatePath, proPath, proName, exclusive);

            HelperFunctions.ReleaseProjectTemplateFile();

            qtPro = QtProject.Create(pro);
            QtVSIPSettings.SaveUicDirectory(pro, null);
            QtVSIPSettings.SaveMocDirectory(pro, null);
            QtVSIPSettings.SaveMocOptions(pro, null);
            QtVSIPSettings.SaveRccDirectory(pro, null);
            QtVSIPSettings.SaveLUpdateOnBuild(pro);
            QtVSIPSettings.SaveLUpdateOptions(pro, null);
            QtVSIPSettings.SaveLReleaseOptions(pro, null);
            QtVSIPSettings.SaveDesignerOptions(pro, null);
            QtVSIPSettings.SaveLinguistOptions(pro, null);
            QtVSIPSettings.SaveAssistantOptions(pro, null);

            foreach (string kPlatformName in (Array)pro.ConfigurationManager.PlatformNames)
            {
                versionManager.SaveProjectQtVersion(pro, "$(DefaultQtVersion)", kPlatformName);
            }

            qtPro.MarkAsQtProject("v1.0");
            qtPro.AddDirectories();
            qtPro.SelectSolutionPlatform(platformName);

            if (!string.IsNullOrEmpty(slnName) && (exclusive == true))
            {
                newSolution.SaveAs(solutionPath + "\\" + slnName + ".sln");
            }
        }
Beispiel #17
0
        public void WriteProjectBasicConfigurations(uint type, bool usePrecompiledHeader, VersionInformation vi)
        {
            ConfigurationTypes configType = ConfigurationTypes.typeApplication;
            string targetExtension = ".exe";
            string qtVersion = null;
            QtVersionManager vm = QtVersionManager.The();
            if (vi == null)
            {
                qtVersion = vm.GetDefaultVersion();
                vi = vm.GetVersionInfo(qtVersion);
            }

            switch (type & TemplateType.ProjectType)
            {
                case TemplateType.DynamicLibrary:
                    configType = ConfigurationTypes.typeDynamicLibrary;
                    targetExtension = ".dll";
                    break;
                case TemplateType.StaticLibrary:
                    configType = ConfigurationTypes.typeStaticLibrary;
                    targetExtension = ".lib";
                    break;
            }

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

                // for some stupid reason you have to set this for it to be updated...
                // the default value is the same... +platform now
            #if (VS2010 || VS2012 || VS2013)
                config.OutputDirectory = "$(SolutionDir)$(Platform)\\$(Configuration)\\";
            #else
                config.OutputDirectory = "$(SolutionDir)$(PlatformName)\\$(ConfigurationName)";
            #endif

            #if ENABLE_WINCE
                // This is mainly for Visual Studio consistency compared with a smartdevice MFC project.
                config.IntermediateDirectory = config.OutputDirectory;
            #endif

                // add some common defines
                compiler.SetPreprocessorDefinitions(vi.GetQMakeConfEntry("DEFINES").Replace(" ", ","));

                if (!vi.IsStaticBuild())
                {
                    compiler.AddPreprocessorDefinition("QT_DLL");
                }

                if (linker != null)
                {
                    if (vi.IsWinCEVersion())
                    {
                        linker.SubSystem = subSystemOption.subSystemNotSet;
                        SetTargetMachine(linker, vi);
                    }
                    else
                    {
                        if ((type & TemplateType.ConsoleSystem) != 0)
                            linker.SubSystem = subSystemOption.subSystemConsole;
                        else
                            linker.SubSystem = subSystemOption.subSystemWindows;
                    }
                    linker.OutputFile = "$(OutDir)\\$(ProjectName)" + targetExtension;
                    linker.AdditionalLibraryDirectories = "$(QTDIR)\\lib";
                    if (vi.IsStaticBuild())
                    {
                        linker.AdditionalDependencies = vi.GetQMakeConfEntry("QMAKE_LIBS_CORE");
                        if ((type & TemplateType.GUISystem) != 0)
                        {
                            linker.AdditionalDependencies += " " + vi.GetQMakeConfEntry("QMAKE_LIBS_GUI");
                            if (vi.IsWinCEVersion())
                                linker.AdditionalDependencies += " qmenu_wince.res";
                        }
                    }
                }
                else
                {
                    librarian.OutputFile = "$(OutDir)\\$(ProjectName)" + targetExtension;
                    librarian.AdditionalLibraryDirectories = "$(QTDIR)\\lib";
                }

                if ((type & TemplateType.GUISystem) != 0)
                    compiler.SetAdditionalIncludeDirectories(QtVSIPSettings.GetUicDirectory(envPro) + ";");

                if ((type & TemplateType.PluginProject) != 0)
                {
                    compiler.AddPreprocessorDefinition("QT_PLUGIN");
                }

                bool isDebugConfiguration = false;
                if (config.Name.StartsWith("Release"))
                {
                    compiler.AddPreprocessorDefinition("QT_NO_DEBUG,NDEBUG");
                    compiler.SetDebugInformationFormat(debugOption.debugDisabled);
                    compiler.SetRuntimeLibrary(runtimeLibraryOption.rtMultiThreadedDLL);
                }
                else if (config.Name.StartsWith("Debug"))
                {
                    isDebugConfiguration = true;
                    compiler.SetOptimization(optimizeOption.optimizeDisabled);
                    compiler.SetDebugInformationFormat(debugOption.debugEnabled);
                    compiler.SetRuntimeLibrary(runtimeLibraryOption.rtMultiThreadedDebugDLL);
                }
                compiler.AddAdditionalIncludeDirectories(
                    ".;" + "$(QTDIR)\\include;" + QtVSIPSettings.GetMocDirectory(envPro));

                compiler.SetTreatWChar_tAsBuiltInType(true);

                if (linker != null)
                    linker.GenerateDebugInformation = isDebugConfiguration;

            #if ENABLE_WINCE
                if (vi.IsWinCEVersion())
                {
                    compiler.SetWarningLevel(warningLevelOption.warningLevel_3);
                    compiler.SetBufferSecurityCheck(isDebugConfiguration);
                    DeploymentToolWrapper deploymentTool = DeploymentToolWrapper.Create(config);
                    if (deploymentTool != null)
                    {
                        deploymentTool.AddWinCEMSVCStandardLib(isDebugConfiguration, dte);

                        string signatureFile = vi.GetSignatureFile();
                        if (signatureFile != null)
                        {
                            Object postBuildEventToolObj = ((IVCCollection)config.Tools).Item("VCPostBuildEventTool");
                            VCPostBuildEventTool postBuildEventTool = postBuildEventToolObj as VCPostBuildEventTool;
                            if (postBuildEventTool != null)
                            {
                                string cmdline = postBuildEventTool.CommandLine;
                                if (cmdline == null)
                                    cmdline = "";
                                if (cmdline.Length > 0)
                                    postBuildEventTool.CommandLine += "\n";
                                cmdline += "signtool sign /F " + signatureFile + " \"$(TargetPath)\"";
                                postBuildEventTool.CommandLine = cmdline;
                            }
                        }
                    }
                    IVCCollection tools = ((IVCCollection)config.Tools);
                    object cst = tools.Item("VCCodeSignTool");
                    if (cst != null)
                    {
                        Type t = cst.GetType();
                        object r = t.InvokeMember("ExecutionBucket",
                            System.Reflection.BindingFlags.GetProperty,
                            null, cst, null);
                        if (r != null)
                            config.ExcludeBuckets = r.ToString();
                    }
                }
            #endif

                if (usePrecompiledHeader)
                    UsePrecompiledHeaders(config);
            }
            if ((type & TemplateType.PluginProject) != 0)
                MarkAsDesignerPluginProject();
        }
Beispiel #18
0
        private void AddDeploySettings(DeploymentToolWrapper deploymentTool, QtModule module,
                                       VCConfiguration config, QtModuleInfo moduleInfo,
                                       VersionInformation versionInfo)
        {
            // for static Qt builds it doesn't make sense
            // to add deployment settings for Qt modules
            if (versionInfo.IsStaticBuild())
                return;

            if (moduleInfo == null)
                moduleInfo = QtModules.Instance.ModuleInformation(module);

            if (moduleInfo == null || !moduleInfo.HasDLL)
                return;

            if (deploymentTool == null)
                deploymentTool = DeploymentToolWrapper.Create(config);
            if (deploymentTool == null)
                return;

            string destDir = deploymentTool.RemoteDirectory;
            const string qtSrcDir = "$(QTDIR)\\lib";
            string filename = moduleInfo.GetDllFileName(IsDebugConfiguration(config));

            if (deploymentTool.GetAdditionalFiles().IndexOf(filename) < 0)
                deploymentTool.Add(filename, qtSrcDir, destDir);

            // add dependent modules
            foreach (QtModule dependentModule in moduleInfo.dependentModules)
                AddDeploySettings(deploymentTool, dependentModule, config, null, versionInfo);
        }
Beispiel #19
0
 public List<string> GetLibs(bool isDebugCfg, VersionInformation vi)
 {
     return GetLibs(isDebugCfg, vi.IsStaticBuild(), vi.IsWinCEVersion());
 }
Beispiel #20
0
        private void CreateProject(EnvDTE.DTE app, string proName,
            string proPath, string slnName, bool exclusive, FakeFilter[] filters,
            string qtVersion, string platformName)
        {
            QtVersionManager versionManager = QtVersionManager.The();
            if (qtVersion == null)
                qtVersion = "$(DefaultQtVersion)";

            if (qtVersion == null)
                throw new Qt4VSException("Unable to find a Qt build!\r\n"
                    + "To solve this problem specify a Qt build");

            string solutionPath = "";
            Solution newSolution = app.Solution;

            if (platformName == null)
            {
                string tmpQtVersion = versionManager.GetSolutionQtVersion(newSolution);
                qtVersion = tmpQtVersion != null ? tmpQtVersion : qtVersion;
                try
                {
                    VersionInformation vi = new VersionInformation(versionManager.GetInstallPath(qtVersion));
                    if (vi.is64Bit())
                        platformName = "x64";
                    else
                        platformName = "Win32";
                }
                catch (Exception e)
                {
                    Messages.DisplayErrorMessage(e);
                }
            }

            if (!string.IsNullOrEmpty(slnName) && (exclusive == true))
            {
                solutionPath = proPath.Substring(0, proPath.LastIndexOf("\\"));
                newSolution.Create(solutionPath, slnName);
            }

            System.IO.Directory.CreateDirectory(proPath);
            string templatePath = HelperFunctions.CreateProjectTemplateFile(filters, true, platformName);

            pro = newSolution.AddFromTemplate(templatePath, proPath, proName, exclusive);

            HelperFunctions.ReleaseProjectTemplateFile();

            qtPro = QtProject.Create(pro);
            QtVSIPSettings.SaveUicDirectory(pro, null);
            QtVSIPSettings.SaveMocDirectory(pro, null);
            QtVSIPSettings.SaveMocOptions(pro, null);
            QtVSIPSettings.SaveRccDirectory(pro, null);
            QtVSIPSettings.SaveLUpdateOnBuild(pro);
            QtVSIPSettings.SaveLUpdateOptions(pro, null);
            QtVSIPSettings.SaveLReleaseOptions(pro, null);
            QtVSIPSettings.SaveDesignerOptions(pro, null);
            QtVSIPSettings.SaveLinguistOptions(pro, null);
            QtVSIPSettings.SaveAssistantOptions(pro, null);

            foreach (string kPlatformName in (Array)pro.ConfigurationManager.PlatformNames)
            {
                versionManager.SaveProjectQtVersion(pro, "$(DefaultQtVersion)", kPlatformName);
            }

            qtPro.MarkAsQtProject("v1.0");
            qtPro.AddDirectories();
            qtPro.SelectSolutionPlatform(platformName);

            if (!string.IsNullOrEmpty(slnName) && (exclusive == true))
                newSolution.SaveAs(solutionPath + "\\" + slnName + ".sln");
        }
Beispiel #21
0
 public List <string> GetLibs(bool isDebugCfg, VersionInformation vi)
 {
     return(GetLibs(isDebugCfg, vi.IsStaticBuild(), vi.IsWinCEVersion()));
 }
Beispiel #22
0
        public VersionInformation GetVersionInfo(string name)
        {
            if (name == null)
                return null;
            if (name == "$(DefaultQtVersion)")
                name = GetDefaultVersion();
            if (versionCache == null)
                versionCache = new Hashtable();

            VersionInformation vi = versionCache[name] as VersionInformation;
            if (vi != null)
                return vi;

            string qtdir = GetInstallPath(name);
            vi = new VersionInformation(qtdir);
            versionCache[name] = vi;
            return vi;
        }
Beispiel #23
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())
                        {
                            linker.AdditionalDependencies =
                                Regex.Replace(linker.AdditionalDependencies, "Qt(\\S+)4\\.lib", "Qt${1}.lib");
                            linker.AdditionalDependencies =
                                Regex.Replace(linker.AdditionalDependencies, "(phonond?)4\\.lib", "${1}.lib");
                            if (compiler != null)
                                compiler.RemovePreprocessorDefinition("QT_DLL");
                        }
                        else
                        {
                            linker.AdditionalDependencies =
                                Regex.Replace(linker.AdditionalDependencies, "Qt(\\S+[^4])\\.lib", "Qt${1}4.lib");
                            linker.AdditionalDependencies =
                                Regex.Replace(linker.AdditionalDependencies, "(phonond?)\\.lib", "${1}4.lib");
                            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+)4\\.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
                }
            }
        }
        private void okButton_Click(object sender, EventArgs e)
        {
            QtVersionManager vm = QtVersionManager.The();
            VersionInformation versionInfo = null;
            try
            {
                versionInfo = new VersionInformation(pathBox.Text);
            }
            catch (Exception exception)
            {
                if (nameBox.Text == "$(QTDIR)")
                {
                    string defaultVersion = vm.GetDefaultVersion();
                    versionInfo = vm.GetVersionInfo(defaultVersion);
                }
                else
                {
                    Messages.DisplayErrorMessage(exception.Message);
                    return;
                }
            }

            if (versionInfo.IsWinCEVersion())
            {
                // check whether we have an SDK installed for this platform
                string platformName = versionInfo.GetVSPlatformName();
                if (!HelperFunctions.IsPlatformAvailable(Connect._applicationObject, platformName))
                {
                    MessageBox.Show(SR.GetString("AddQtVersionDialog_PlatformNotFoundError", platformName),
                                    null, MessageBoxButtons.OK,
                                    MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                    return;
                }
            }

            string makefileGenerator = versionInfo.GetQMakeConfEntry("MAKEFILE_GENERATOR");
            if (makefileGenerator != "MSVC.NET" && makefileGenerator != "MSBUILD")
            {
                MessageBox.Show(SR.GetString("AddQtVersionDialog_IncorrectMakefileGenerator", makefileGenerator),
                                            null, MessageBoxButtons.OK,
                                            MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                return;
            }
            vm.SaveVersion(nameBox.Text, pathBox.Text);
            DialogResult = DialogResult.OK;
            Close();
        }
Beispiel #25
0
 public static void RemovePlatformDependencies(VCConfiguration config, VersionInformation viOld)
 {
     CompilerToolWrapper compiler = CompilerToolWrapper.Create(config);
     SimpleSet minuend = new SimpleSet(compiler.PreprocessorDefinitions);
     SimpleSet subtrahend = new SimpleSet(viOld.GetQMakeConfEntry("DEFINES").Split(new char[] { ' ', '\t' }));
     compiler.SetPreprocessorDefinitions(minuend.Minus(subtrahend).JoinElements(','));
 }
Beispiel #26
0
        protected void Init(VersionInformation versionInfo)
        {
            string filename = versionInfo.qtDir + "\\mkspecs\\default\\qmake.conf";
            fileInfo = new FileInfo(filename);

            // Starting from Qt5 beta2 there is no more "\\mkspecs\\default" folder available
            // To find location of "qmake.conf" there is a need to run "qmake -query" command
            // This is what happens below.
            if (!fileInfo.Exists)
            {
                QMakeQuery qmakeQuery = new QMakeQuery(versionInfo);

                qmakeQuery.ReadyEvent += new QMakeQuery.EventHandler(this.CloseEventHandler);
                System.Threading.Thread qmakeThread = new System.Threading.Thread(new ThreadStart(qmakeQuery.RunQMakeQuery));
                qmakeThread.Start();
                qmakeThread.Join();

                if (qmakeQuery.ErrorValue != 0)
                {
                    throw new Qt4VSException("qmake.conf not found");
                }

                if (qmakespecFolder.Length > 0)
                {
                    filename = versionInfo.qtDir + "\\mkspecs\\" + qmakespecFolder + "\\qmake.conf";
                }
            }

            Init(filename);
        }
Beispiel #27
0
        private static void SetTargetMachine(VCLinkerTool linker, VersionInformation versionInfo)
        {
            String qMakeLFlagsWindows = versionInfo.GetQMakeConfEntry("QMAKE_LFLAGS_WINDOWS");
            Regex rex = new Regex("/MACHINE:(\\S+)");
            Match match = rex.Match(qMakeLFlagsWindows);
            if (match.Success)
            {
                linker.TargetMachine = HelperFunctions.TranslateMachineType(match.Groups[1].Value);
            }
            else
            {
                string platformName = versionInfo.GetVSPlatformName();
                if (platformName == "Win32")
                    linker.TargetMachine = machineTypeOption.machineX86;
                else if (platformName == "x64")
                    linker.TargetMachine = machineTypeOption.machineAMD64;
                else
                    linker.TargetMachine = machineTypeOption.machineNotSet;
            }

            String subsystemOption = "";
            String linkerOptions = linker.AdditionalOptions;
            if (linkerOptions == null)
                linkerOptions = "";

            rex = new Regex("(/SUBSYSTEM:\\S+)");
            match = rex.Match(qMakeLFlagsWindows);
            if (match.Success)
                subsystemOption = match.Groups[1].Value;

            match = rex.Match(linkerOptions);
            if (match.Success)
            {
                linkerOptions = rex.Replace(linkerOptions, subsystemOption);
            }
            else
            {
                if (linkerOptions.Length > 0)
                    linkerOptions += " ";
                linkerOptions += subsystemOption;
            }
            linker.AdditionalOptions = linkerOptions;
        }
Beispiel #28
0
        /// <summary>
        /// Check if all Qt versions are valid and readable.
        /// </summary>
        /// Also sets the default Qt version to the newest version, if needed.
        /// <param name="errorMessage"></param>
        /// <returns>true, if we found an invalid version</returns>
        public bool HasInvalidVersions(out string errorMessage)
        {
            List<QtVersion> validVersions = new List<QtVersion>();
            List<string> invalidVersions = new List<string>();

            foreach (string v in GetVersions())
            {
                if (v == "$(DefaultQtVersion)")
                    continue;
                try
                {
                    VersionInformation vi = new VersionInformation(GetInstallPath(v));
                    QtVersion qtVersion = new QtVersion();
                    qtVersion.name = v;
                    qtVersion.vi = vi;
                    validVersions.Add(qtVersion);
                }
                catch (Exception)
                {
                    invalidVersions.Add(v);
                }
            }

            if (invalidVersions.Count > 0)
            {
                errorMessage = "These Qt version are inaccessible:\n";
                foreach (string invalidVersion in invalidVersions)
                    errorMessage += invalidVersion + " in " + GetInstallPath(invalidVersion) + "\n";
                errorMessage += "Make sure that you have read access to all files in your Qt directories.";

                // Is the default Qt version invalid?
                bool isDefaultQtVersionInvalid = false;
                string defaultQtVersionName = GetDefaultVersion();
                if (String.IsNullOrEmpty(defaultQtVersionName))
                {
                    isDefaultQtVersionInvalid = true;
                }
                else
                {
                    foreach (string name in invalidVersions)
                    {
                        if (name == defaultQtVersionName)
                        {
                            isDefaultQtVersionInvalid = true;
                            break;
                        }
                    }
                }

                // find the newest valid Qt version that can be used as default version
                if (isDefaultQtVersionInvalid && validVersions.Count > 0)
                {
                    QtVersion defaultQtVersion = null;
                    foreach (QtVersion v in validVersions)
                    {
                        if (v.vi.IsWinCEVersion())
                            continue;
                        if (defaultQtVersion == null)
                        {
                            defaultQtVersion = v;
                            continue;
                        }
                        if (defaultQtVersion.vi.qtMajor < v.vi.qtMajor ||
                               (defaultQtVersion.vi.qtMajor == v.vi.qtMajor && (defaultQtVersion.vi.qtMinor < v.vi.qtMinor ||
                                   (defaultQtVersion.vi.qtMinor == v.vi.qtMinor && defaultQtVersion.vi.qtPatch < v.vi.qtPatch))))
                        {
                            defaultQtVersion = v;
                        }
                    }
                    if (defaultQtVersion != null)
                        SaveDefaultVersion(defaultQtVersion.name);
                }

                return true;
            }
            errorMessage = null;
            return false;
        }
Beispiel #29
0
        /// <summary>
        /// Adds a moc step to a given file for this project.
        /// </summary>
        /// <param name="file">file</param>
        public void AddMocStep(VCFile file)
        {
            string oldItemType = file.ItemType;
            try
            {
                string mocFileName = GetMocFileName(file.FullPath);
                if (mocFileName == null)
                    return;

                bool hasDifferentMocFilePerConfig = QtVSIPSettings.HasDifferentMocFilePerConfig(envPro);
                bool hasDifferentMocFilePerPlatform = QtVSIPSettings.HasDifferentMocFilePerPlatform(envPro);
                bool mocableIsCPP = mocFileName.ToLower().EndsWith(".moc");

            #if (VS2010 || VS2012 || VS2013)
                if (!mocableIsCPP && file.ItemType != "CustomBuild")
                {
                    file.ItemType = "CustomBuild";
                }
            #endif

            #if VS2013
                file = Update(this, file);
            #endif

            #region Add moc for each configuration
                foreach (VCFileConfiguration config in (IVCCollection)file.FileConfigurations)
                {
                    string name = ((VCCustomBuildTool)config.Tool).toolName;
                    VCConfiguration vcConfig = config.ProjectConfiguration as VCConfiguration;
                    VCPlatform platform = vcConfig.Platform as VCPlatform;
                    string platformName = platform.Name;

                    string mocRelPath = GetRelativeMocFilePath(file.FullPath, vcConfig.ConfigurationName, platformName);
                    string platformFilterName = null;
                    string configFilterName = null;

                    if (mocRelPath.Contains(platformName))
                    {
                        platformFilterName = platformName;
                    }

                    if (mocRelPath.Contains(vcConfig.ConfigurationName))
                    {
                        configFilterName = vcConfig.ConfigurationName;
                    }

                    VCFile mocFile = GetFileFromProject(mocRelPath);
                    if (mocFile == null)
                    {
                        FileInfo fi = new FileInfo(this.VCProject.ProjectDirectory + "\\" + mocRelPath);
                        if (!fi.Directory.Exists)
                            fi.Directory.Create();
                        mocFile = AddFileInSubfilter(Filters.GeneratedFiles(), platformFilterName, configFilterName, mocRelPath);
            #if (VS2010 || VS2012 || VS2013)
                        if (mocFileName.ToLower().EndsWith(".moc"))
                        {
                            ProjectItem mocFileItem = mocFile.Object as ProjectItem;
                            if (mocFileItem != null)
                                HelperFunctions.EnsureCustomBuildToolAvailable(mocFileItem);
                        }
            #endif
                    }

                    if (mocFile == null)
                        throw new Qt4VSException(SR.GetString("QtProject_CannotAddMocStep", file.FullPath));

                    VCCustomBuildTool tool = null;

                    string fileToMoc = null;
                    if (!mocableIsCPP)
                    {
                        tool = HelperFunctions.GetCustomBuildTool(config);
                        fileToMoc = ProjectMacros.Path;
                    }
                    else
                    {
                        VCFileConfiguration mocConf = GetVCFileConfigurationByName(mocFile, vcConfig.Name);
                        tool = HelperFunctions.GetCustomBuildTool(mocConf);
                        fileToMoc = HelperFunctions.GetRelativePath(vcPro.ProjectDirectory, file.FullPath);
                    }

                    if (tool == null)
                        throw new Qt4VSException(SR.GetString("QtProject_CannotFindCustomBuildTool", file.FullPath));

                    if (hasDifferentMocFilePerPlatform && hasDifferentMocFilePerConfig)
                    {
                        foreach (VCFileConfiguration mocConf in (IVCCollection)mocFile.FileConfigurations)
                        {
                            VCConfiguration projectCfg = mocConf.ProjectConfiguration as VCConfiguration;
                            if (projectCfg.Name != vcConfig.Name || (IsMoccedFileIncluded(file) && !mocableIsCPP))
                            {
                                if (!mocConf.ExcludedFromBuild)
                                    mocConf.ExcludedFromBuild = true;
                            }
                            else
                            {
                                if (mocConf.ExcludedFromBuild != config.ExcludedFromBuild)
                                    mocConf.ExcludedFromBuild = config.ExcludedFromBuild;
                            }
                        }
                    }
                    else if (hasDifferentMocFilePerPlatform)
                    {
                        foreach (VCFileConfiguration mocConf in (IVCCollection)mocFile.FileConfigurations)
                        {
                            VCConfiguration projectCfg = mocConf.ProjectConfiguration as VCConfiguration;
                            VCPlatform mocConfPlatform = projectCfg.Platform as VCPlatform;
                            if (projectCfg.ConfigurationName != vcConfig.ConfigurationName)
                                continue;

                            bool exclude = mocConfPlatform.Name != platformName || (IsMoccedFileIncluded(file) && !mocableIsCPP);
                            if (exclude)
                            {
                                if (mocConf.ExcludedFromBuild != exclude)
                                    mocConf.ExcludedFromBuild = exclude;
                            }
                            else
                            {
                                if (mocConf.ExcludedFromBuild != config.ExcludedFromBuild)
                                    mocConf.ExcludedFromBuild = config.ExcludedFromBuild;
                            }
                        }
                    }
                    else if (hasDifferentMocFilePerConfig)
                    {
                        foreach (VCFileConfiguration mocConf in (IVCCollection)mocFile.FileConfigurations)
                        {
                            VCConfiguration projectCfg = mocConf.ProjectConfiguration as VCConfiguration;
                            VCPlatform mocConfPlatform = projectCfg.Platform as VCPlatform;
                            if (platformName != mocConfPlatform.Name)
                                continue;

                            if (projectCfg.Name != vcConfig.Name || (IsMoccedFileIncluded(file) && !mocableIsCPP))
                            {
                                if (!mocConf.ExcludedFromBuild)
                                    mocConf.ExcludedFromBuild = true;
                            }
                            else
                            {
                                if (mocConf.ExcludedFromBuild != config.ExcludedFromBuild)
                                    mocConf.ExcludedFromBuild = config.ExcludedFromBuild;
                            }
                        }
                    }
                    else
                    {
                        VCFileConfiguration moccedFileConfig = GetVCFileConfigurationByName(mocFile, config.Name);
                        if (moccedFileConfig != null)
                        {
                            VCFile cppFile = GetCppFileForMocStep(file);
                            if (cppFile != null && IsMoccedFileIncluded(cppFile))
                            {
                                if (!moccedFileConfig.ExcludedFromBuild)
                                {
                                    moccedFileConfig.ExcludedFromBuild = true;
                                }
                            }
                            else if (moccedFileConfig.ExcludedFromBuild != config.ExcludedFromBuild)
                                moccedFileConfig.ExcludedFromBuild = config.ExcludedFromBuild;
                        }
                    }

                    string dps = tool.AdditionalDependencies;
                    if (dps.IndexOf("\"" + Resources.moc4Command + "\"") < 0)
                    {
                        if (dps.Length > 0 && !dps.EndsWith(";"))
                            dps += ";";
                        tool.AdditionalDependencies = dps + "\"" + Resources.moc4Command + "\";" + fileToMoc;
                    }

                    tool.Description = "Moc'ing " + file.Name + "...";

                    string inputMocFile = ProjectMacros.Path;
                    if (mocableIsCPP)
                        inputMocFile = file.RelativePath;
                    string output = tool.Outputs;
                    string outputMocFile = "";
                    string outputMocMacro = "";
                    string baseFileName = file.Name.Remove(file.Name.LastIndexOf('.'));
                    string pattern = "(\"(.*\\\\" + mocFileName + ")\"|(\\S*"
                        + mocFileName + "))";
                    System.Text.RegularExpressions.Regex regExp = new Regex(pattern);
                    MatchCollection matchList = regExp.Matches(tool.Outputs.Replace(ProjectMacros.Name, baseFileName));
                    if (matchList.Count > 0)
                    {
                        if (matchList[0].Length > 0)
                        {
                            outputMocFile = matchList[0].ToString();
                        }
                        else if (matchList[1].Length > 1)
                        {
                            outputMocFile = matchList[1].ToString();
                        }
                        if (outputMocFile.StartsWith("\""))
                            outputMocFile = outputMocFile.Substring(1);
                        if (outputMocFile.EndsWith("\""))
                            outputMocFile = outputMocFile.Substring(0, outputMocFile.Length-1);
                        string outputMocPath = Path.GetDirectoryName(outputMocFile);
                        string stringToReplace = Path.GetFileName(outputMocFile);
                        outputMocMacro = outputMocPath + "\\" + stringToReplace.Replace(baseFileName, ProjectMacros.Name);
                    }
                    else
                    {
                        outputMocFile = GetRelativeMocFilePath(file.FullPath);
                        string outputMocPath = Path.GetDirectoryName(outputMocFile);
                        string stringToReplace = Path.GetFileName(outputMocFile);
                        outputMocMacro = outputMocPath + "\\" + stringToReplace.Replace(baseFileName, ProjectMacros.Name);
                        if (output.Length > 0 && !output.EndsWith(";"))
                            output += ";";
                        tool.Outputs = output + "\"" + outputMocMacro + "\"";
                    }

                    string newCmdLine = "\"" + Resources.moc4Command + "\" " + QtVSIPSettings.GetMocOptions(envPro)
                        + " \"" + inputMocFile + "\" -o \""
                        + outputMocMacro + "\"";

                    // Tell moc to include the PCH header if we are using precompiled headers in the project
                    CompilerToolWrapper compiler = CompilerToolWrapper.Create(vcConfig);
                    if (compiler.GetUsePrecompiledHeader() != pchOption.pchNone)
                    {
                        newCmdLine += " " + GetPCHMocOptions(file, compiler);
                    }

                    QtVersionManager versionManager = QtVersionManager.The();
                    VersionInformation versionInfo = new VersionInformation(versionManager.GetInstallPath(envPro));
                    bool mocSupportsIncludes = (versionInfo.qtMajor == 4 && versionInfo.qtMinor >= 2)
                        || versionInfo.qtMajor >= 5;

                    string strDefinesIncludes = "";
                    VCFile cppPropertyFile;
                    if (!mocableIsCPP)
                        cppPropertyFile = GetCppFileForMocStep(file);
                    else
                        cppPropertyFile = GetCppFileForMocStep(mocFile);
                    VCFileConfiguration defineIncludeConfig;
                    if (cppPropertyFile != null)
                        defineIncludeConfig = GetVCFileConfigurationByName(cppPropertyFile, config.Name);
                    else
                        // No file specific defines/includes but at least the project defines/includes are added
                        defineIncludeConfig = config;
                    strDefinesIncludes += GetDefines(defineIncludeConfig);
                    strDefinesIncludes += GetIncludes(defineIncludeConfig);
                    int cmdLineLength = newCmdLine.Length + strDefinesIncludes.Length + 1;
                    if (cmdLineLength > HelperFunctions.GetMaximumCommandLineLength() && mocSupportsIncludes)
                    {
                        // Command line is too long. We must use an options file.
                        string mocIncludeCommands = "";
                        string mocIncludeFile = "\"" + outputMocFile + ".inc\"";
                        string redirectOp = " > ";
                        int maxCmdLineLength = HelperFunctions.GetMaximumCommandLineLength() - (mocIncludeFile.Length + 1);

                        string[] options = strDefinesIncludes.Split(' ');

                        int i = options.Length - 1;
                        for (; i >= 0; --i)
                        {
                            if (options[i].Length == 0)
                                continue;
                            mocIncludeCommands += "echo " + options[i] + redirectOp + mocIncludeFile + "\r\n";
                            cmdLineLength -= options[i].Length + 1;
                            if (cmdLineLength < maxCmdLineLength)
                                break;
                            if (i == options.Length - 1)    // first loop
                                redirectOp = " >> ";
                        }
                        strDefinesIncludes = "@" + mocIncludeFile;
                        for (int k = 0; k < i; ++k)
                            if (options[k].Length > 0)
                                strDefinesIncludes += " " + options[k];

                        newCmdLine = mocIncludeCommands + newCmdLine + " " + strDefinesIncludes;
                    }
                    else
                    {
                        newCmdLine = newCmdLine + " " + strDefinesIncludes;
                    }

                    if (tool.CommandLine.Trim().Length > 0)
                    {
                        string cmdLine = tool.CommandLine;

                        // remove the moc option file commands
                        {
                            Regex rex = new Regex("^echo.+[.](moc|cpp)[.]inc\"\r\n", RegexOptions.Multiline);
                            cmdLine = rex.Replace(cmdLine, "");
                        }

                        Match m = System.Text.RegularExpressions.Regex.Match(cmdLine,
                            @"(\S*moc.exe|""\S+:\\\.*moc.exe"")");

                        if (m.Success)
                        {
                            int start = m.Index;
                            int end = cmdLine.IndexOf("&&", start);
                            int a = cmdLine.IndexOf("\r\n", start);
                            if ((a > -1 && a < end) || (end < 0 && a > -1))
                                end = a;
                            if (end < 0)
                                end = cmdLine.Length;
                            tool.CommandLine = cmdLine.Replace(cmdLine.Substring(start, end - start), newCmdLine);
                        }
                        else
                        {
                            tool.CommandLine = cmdLine + "\r\n" + newCmdLine;
                        }
                    }
                    else
                    {
                        tool.CommandLine = newCmdLine;
                    }
                }
            #endregion
            }
            catch
            {
                file.ItemType = oldItemType;
                throw new Qt4VSException(SR.GetString("QtProject_CannotAddMocStep", file.FullPath));
            }
        }
Beispiel #30
0
        public void ImportProject(FileInfo mainInfo, string qtVersion)
        {
            VersionInformation versionInfo = QtVersionManager.The().GetVersionInfo(qtVersion);
            FileInfo           VCInfo      = RunQmake(mainInfo, projectFileExtension, false, versionInfo);

            if (null == VCInfo)
            {
                return;
            }

            ReplaceAbsoluteQtDirInProject(VCInfo);

            try
            {
                if (CheckQtVersion(versionInfo))
                {
                    // no need to add the project again if it's already there...
                    if (!HelperFunctions.IsProjectInSolution(dteObject, VCInfo.FullName))
                    {
                        try
                        {
                            dteObject.Solution.AddFromFile(VCInfo.FullName, false);
                        }
                        catch (Exception /*exception*/)
                        {
                            Messages.PaneMessage(dteObject, "--- (Import): Generated project could not be loaded.");
                            Messages.PaneMessage(dteObject, "--- (Import): Please look in the output above for errors and warnings.");
                            return;
                        }
                        Messages.PaneMessage(dteObject, "--- (Import): Added " + VCInfo.Name + " to Solution");
                    }
                    else
                    {
                        Messages.PaneMessage(dteObject, "Project already in Solution");
                    }

                    EnvDTE.Project pro = null;
                    foreach (EnvDTE.Project p in HelperFunctions.ProjectsInSolution(dteObject))
                    {
                        if (p.FullName.ToLower() == VCInfo.FullName.ToLower())
                        {
                            pro = p;
                            break;
                        }
                    }
                    if (pro != null)
                    {
                        QtProject qtPro = QtProject.Create(pro);
                        qtPro.SetQtEnvironment();
                        string platformName = versionInfo.GetVSPlatformName();

                        if (qtVersion != null)
                        {
                            QtVersionManager.The().SaveProjectQtVersion(pro, qtVersion, platformName);
                        }
                        if (!qtPro.SelectSolutionPlatform(platformName) || !qtPro.HasPlatform(platformName))
                        {
                            bool newProject = false;
                            qtPro.CreatePlatform("Win32", platformName, null, versionInfo, ref newProject);
                            if (!qtPro.SelectSolutionPlatform(platformName))
                            {
                                Messages.PaneMessage(dteObject, "Can't select the platform " + platformName + ".");
                            }
                        }

                        // try to figure out if the project is a plugin project
                        try
                        {
                            string          activeConfig = pro.ConfigurationManager.ActiveConfiguration.ConfigurationName;
                            VCConfiguration config       = (VCConfiguration)((IVCCollection)qtPro.VCProject.Configurations).Item(activeConfig);
                            if (config.ConfigurationType == ConfigurationTypes.typeDynamicLibrary)
                            {
                                CompilerToolWrapper compiler = CompilerToolWrapper.Create(config);
                                VCLinkerTool        linker   = (VCLinkerTool)((IVCCollection)config.Tools).Item("VCLinkerTool");
                                if (compiler.GetPreprocessorDefinitions().IndexOf("QT_PLUGIN") > -1 &&
                                    compiler.GetPreprocessorDefinitions().IndexOf("QDESIGNER_EXPORT_WIDGETS") > -1 &&
                                    compiler.GetAdditionalIncludeDirectories().IndexOf("QtDesigner") > -1 &&
                                    linker.AdditionalDependencies.IndexOf("QtDesigner") > -1)
                                {
                                    qtPro.MarkAsDesignerPluginProject();
                                }
                            }
                        }
                        catch (Exception)
                        { }

                        ApplyPostImportSteps(qtPro);
                    }
                }
            }
            catch (Exception e)
            {
                Messages.DisplayCriticalErrorMessage(SR.GetString("ExportProject_ProjectOrSolutionCorrupt", e.ToString()));
            }
        }
Beispiel #31
0
 public QMakeQuery(VersionInformation vi)
     : base(null, "", false, vi)
 {
     qtVersionInformation = vi;
 }
Beispiel #32
0
 public QMakeConf(VersionInformation versionInfo)
 {
     Init(versionInfo);
 }