/// <summary> /// Create libs from main project dependencies and linker additional dependencies /// </summary> /// <param name="lnkTool">linker tool</param> /// <returns>libs</returns> private string iCreateLibs(VCLinkerTool lnkTool) { string libs = ""; libs = lnkTool.AdditionalDependencies; if (libs != null) { libs = libs.Replace(".lib", ""); libs = libs.Replace(" ", " -l"); libs = "-l" + libs; } else { libs = ""; } for (int i = 0; i < m_VcProjDependencies.Length; i++) { if (m_VcProjDependencies[i].Equals("v_to_c")) { libs += " -LVTOC/i686-RHEL3-gcc-3.2.3/lib -lvtoc "; } } //add stdc++ and m libs libs += "-lstdc++ -lm"; return(libs); }
public void addLibsToVCProject(VCProject project) { foreach (VCConfiguration config in project.Configurations) { IVCCollection tools = config.Tools; foreach (Object tool in tools) { if (tool is VCLinkerTool) { VCLinkerTool linker = (VCLinkerTool)tool; if (config.Name == "Debug|Win32" && libs32Debug.Count > 0) { linker.AdditionalDependencies.AppendSemiColon(); linker.AdditionalDependencies += libs32Debug.ConcatenateWithSeparator(' '); } else if (config.Name == "Debug|x64" && libs64Debug.Count > 0) { linker.AdditionalDependencies.AppendSemiColon(); linker.AdditionalDependencies += libs64Debug.ConcatenateWithSeparator(' '); } else if (config.Name == "Release|Win32" && libs32Release.Count > 0) { linker.AdditionalDependencies.AppendSemiColon(); linker.AdditionalDependencies += libs32Release.ConcatenateWithSeparator(' '); } else if (config.Name == "Release|x64" && libs64Release.Count > 0) { linker.AdditionalDependencies.AppendSemiColon(); linker.AdditionalDependencies += libs64Debug.ConcatenateWithSeparator(' '); } } } } }
public static VCLinkerTool GetLinkerTool(Project project, out string reasonForFailure) { VCProject vcProject = project?.Object as VCProject; if (vcProject == null) { reasonForFailure = "Failed to retrieve VCLinkerTool since project is not a VCProject."; return(null); } VCConfiguration activeConfiguration = vcProject.ActiveConfiguration; var tools = activeConfiguration.Tools; VCLinkerTool linkerTool = null; foreach (var tool in activeConfiguration.Tools) { linkerTool = tool as VCLinkerTool; if (linkerTool != null) { break; } } if (linkerTool == null) { reasonForFailure = "Couldn't file a VCLinkerTool in VC++ Project."; return(null); } reasonForFailure = ""; return(linkerTool); }
public static VCLinkerTool GetLinkerTool(Project project) { VCProject vcProject = project?.Object as VCProject; if (vcProject == null) { throw new VCQueryFailure("Failed to retrieve VCLinkerTool since project is not a VCProject."); } VCConfiguration activeConfiguration = vcProject.ActiveConfiguration; var tools = activeConfiguration.Tools; VCLinkerTool linkerTool = null; foreach (var tool in activeConfiguration.Tools) { linkerTool = tool as VCLinkerTool; if (linkerTool != null) { break; } } if (linkerTool == null) { throw new VCQueryFailure("Couldn't file a VCLinkerTool in VC++ Project."); } return(linkerTool); }
private LibraryConfigState.State ModifyLibPath(VCLinkerTool linker, List <string> lib_dirs, string project_path, string libpack_path, bool check_only = false) { if (lib_dirs.Count == 0) { return(LibraryConfigState.State.Empty); } var full_lib_dirs = GetAbsolutePaths(lib_dirs, libpack_path); bool found = false; var project_lib_dirs = new List <string>(SplitQuoted(";", linker.AdditionalLibraryDirectories)); foreach (var project_libdir in project_lib_dirs) { string full_project_libdir = GetAbsolutePath(project_libdir, project_path); found |= full_lib_dirs.RemoveAll(n => n.Equals(full_project_libdir, StringComparison.OrdinalIgnoreCase)) > 0; } if (!check_only) { project_lib_dirs.AddRange(full_lib_dirs); linker.AdditionalLibraryDirectories = String.Join(";", project_lib_dirs.ToArray()); } return(full_lib_dirs.Count == 0 ? LibraryConfigState.State.All : found?LibraryConfigState.State.Partial : LibraryConfigState.State.None); }
private LibraryConfigState.State ModifyLibDependencies(VCLinkerTool linker, List <string> lib_files, string project_path, string libpack_path, bool check_only = false) { if (lib_files.Count == 0) { return(LibraryConfigState.State.Empty); } var lib_files_remaining = lib_files.GetRange(0, lib_files.Count); bool found = false; var project_libs = new List <string>(SplitQuoted(" ", linker.AdditionalDependencies)); foreach (var project_lib in project_libs) { found |= lib_files_remaining.Remove(project_lib); } if (!check_only) { project_libs.AddRange(lib_files_remaining); linker.AdditionalDependencies = String.Join(" ", project_libs); } return(lib_files_remaining.Count == 0 ? LibraryConfigState.State.All : found?LibraryConfigState.State.Partial : LibraryConfigState.State.None); }
private void IntegrateIntoConfiguration(VCConfiguration configuration) { string absPropFilePath = GetPropsFilePath(configuration); string relativePropFilePath = ConanPathHelper.GetRelativePath(configuration.project.ProjectDirectory, absPropFilePath); IVCCollection tools = (IVCCollection)configuration.Tools; if (tools != null) { VCLinkerTool ltool = (VCLinkerTool)tools.Item("VCLinkerTool"); if (ltool != null) { string deps = ltool.AdditionalDependencies; ltool.AdditionalDependencies = deps.Replace("$(NOINHERIT)", ""); } } foreach (VCPropertySheet sheet in configuration.PropertySheets) { if (ConanPathHelper.NormalizePath(sheet.PropertySheetFile) == ConanPathHelper.NormalizePath(absPropFilePath)) { return; } } configuration.AddPropertySheet(relativePropFilePath); configuration.CollectIntelliSenseInfo(); }
/// <summary> /// Create ldflags from all linker options /// </summary> /// <param name="lnkTool">linker tool</param> /// <returns>ldflags</returns> private string iCreateLdflags(VCLinkerTool lnkTool) { string ldflags = ""; string option = ""; //Additional Libpath option = lnkTool.AdditionalLibraryDirectories; if (option != null) { option = option.Replace(";", " -L"); option = "-L" + option; } else { option = ""; } ldflags += " " + option; //Generate Mapfile option = (lnkTool.GenerateMapFile) ? "-map" : ""; if (!(option.Equals(""))) { option += lnkTool.MapFileName; ldflags += " " + option; } return(ldflags); }
public static VCLinkerTool GetLinkerTool(Solution2 solution, string projectName, string buildConfig) { VCProject fsgdGameProject = solution.Projects.Item(projectName).Object as VCProject; VCConfiguration debug32 = fsgdGameProject.Configurations.Item(buildConfig) as VCConfiguration; VCLinkerTool tool = debug32.Tools.Item("VCLinkerTool"); return(tool); }
public static void SetAdditionalDependencies(this VCLinkerTool tool, List <string> value) { var newDependencies = PathUtilities.JoinPatches(value, " "); if (!string.Equals(newDependencies, tool.AdditionalDependencies, StringComparison.OrdinalIgnoreCase)) { tool.AdditionalDependencies = newDependencies; } }
static private void ParseLibraryDirectories(StreamWriter streamWriter, VCLinkerTool tool, int indent) { var indentText = Indent(indent); var items = tool.AdditionalLibraryDirectories.Split(';'); streamWriter.WriteLine(indentText + "link_directories("); foreach (var item in items) { streamWriter.WriteLine(Indent(indent + 1) + "{0}", item); } streamWriter.WriteLine(indentText + ")"); streamWriter.WriteLine(); }
private void DisableLinkConfig(ref VCLinkerTool linkerTool, string config) { Log("\tLinker Configuration"); if (linkerTool != null) { if (linkerTool.AdditionalOptions != null) { string newargs = DisableCodeCoverageCommandLineArguments(linkerTool.AdditionalOptions); if (linkerTool.AdditionalOptions != newargs) { linkerTool.AdditionalOptions = newargs; Log("\t\tAdditional command line arguments set to '" + newargs + "'"); } } } }
/// <summary> /// Reads miscellaneous linker settings. /// </summary> private void parseLinkerSettings_Misc(VCConfiguration vcConfiguration, VCLinkerTool linkerTool, ProjectConfigurationInfo_CPP configurationInfo) { // Whether we implicitly link in libraries we depend on. // (We are assuming that all configurations of the project have the // same link-library-dependencies setting.) m_projectInfo.LinkLibraryDependencies = Utils.call(() => (linkerTool.LinkLibraryDependencies)); // Generate debug info... bool debugInfo = Utils.call(() => (linkerTool.GenerateDebugInformation)); if (debugInfo == true && configurationInfo.getPreprocessorDefinitions().Contains("NDEBUG") == false) { configurationInfo.addCompilerFlag("-g"); } }
/// <summary> /// </summary> protected virtual void AddModuleDefinitionFile() { var dest = Path.Combine(UserPrefs.MsvcDirectory, UserPrefs.TargetName + @".def"); ProjectSources.CopyFile(ProjectSources.ModuleDefinition, dest); ReplaceParameters(dest); foreach (VCConfiguration config in Project.Configurations) { VCLinkerTool linker = ((IVCCollection)config.Tools).Item(@"VCLinkerTool"); linker.ModuleDefinitionFile = Path.GetFileName(dest); } var filter = AddFilter(@"sdk\metamod"); filter.AddFile(dest); }
private void CreateLinkConfig(ref VCLinkerTool linkerTool, List <string> additionalParamsList, string config) { Log("\tLinker Configuration"); if (linkerTool != null) { if (linkerTool.AdditionalOptions == null) { linkerTool.AdditionalOptions = " "; } string additionalParams = generateParamString(additionalParamsList, linkerTool.AdditionalOptions); if (additionalParams.Length > 0) { linkerTool.AdditionalOptions += " " + additionalParams; Log("\t\tAdditional command line arguments '" + additionalParams + "' are appended"); } } }
/// <summary> /// Finds the linker settings, such as the collection of libraries to link, /// for the configuration passed in. /// </summary> private void parseConfiguration_LinkerSettings(VCConfiguration vcConfiguration, ProjectConfigurationInfo_CPP configurationInfo) { // We get the linker-settings 'tool'... IVCCollection tools = Utils.call(() => (vcConfiguration.Tools as IVCCollection)); VCLinkerTool linkerTool = Utils.call(() => (tools.Item("VCLinkerTool") as VCLinkerTool)); if (linkerTool == null) { // Not all projects have a linker tools... return; } // And extract various details from it... parseLinkerSettings_LibraryPath(vcConfiguration, configurationInfo); parseLinkerSettings_Libraries(vcConfiguration, configurationInfo); parseLinkerSettings_Misc(vcConfiguration, linkerTool, configurationInfo); }
public void DisableTestCocoonConfig(String config, string project) { bool foundProject = false; IEnumerator e = GetVCProjectRefs(); e.Reset(); // traverse all projects to find the right one while (e.MoveNext()) { VCProject actVCP = (VCProject)e.Current; if (actVCP.Name == project) { foundProject = true; VCConfiguration vcC; vcC = (VCConfiguration)(((IVCCollection)actVCP.Configurations).Item(config)); if (vcC != null) { Log("Modifying configuration '" + config + "' for the project '" + project + "'"); // change settings for sepcified compiler IVCCollection ctools = (IVCCollection)vcC.Tools; VCLinkerTool linkerTool = (VCLinkerTool)(ctools.Item("VCLinkerTool")); VCLibrarianTool librarianTool = (VCLibrarianTool)(ctools.Item("VCLibrarianTool")); VCCLCompilerTool compilerTool = (VCCLCompilerTool)(ctools.Item("VCCLCompilerTool")); VCCustomBuildTool customBuildTool = (VCCustomBuildTool)(ctools.Item("VCCustomBuildTool")); DisableClConfig(ref compilerTool, config); DisableLinkConfig(ref linkerTool, config); DisableCustomBuildConfig(ref customBuildTool, config); DisableLibrarianConfig(ref librarianTool, config); DisableConfigForEachFile(ref actVCP, config); } else { Log("Skipping configuration '" + config + "' for the project '" + project + "'"); } } } if (!foundProject) { ShowMessageBox("Could not find the project", "Warning"); } }
public void OnBuildProjConfigBegin(string projName, string projConfig , string platform, string solConfig) { if (solConfig.Contains(" [ChartPoints]")) { extensionServ.SetMode(EMode.Build); ServiceHost serviceHost = null; try { EnvDTE.Project proj = Globals.dte.Solution.Projects.Item(projName); //!!! Needed for newly created project to update vcxproj file !!! //Orchestrate(proj.FullName); IProjectChartPoints pPnts = Globals.processor.GetProjectChartPoints(proj.Name); if (pPnts != null) { VCProject vcProj = (VCProject)proj.Object; VCConfiguration vcConfig = vcProj.Configurations.Item(projConfig); IVCCollection tools = vcConfig.Tools as IVCCollection; VCLinkerTool tool = tools.Item("VCLinkerTool") as VCLinkerTool; tool.GenerateDebugInformation = false; pPnts.Validate(); if (!serviceHostsCont.TryGetValue(proj.FullName, out serviceHost)) { serviceHostsCont.Add(proj.FullName, serviceHost); } if (serviceHost == null) { serviceHost = new ServiceHost(typeof(IPCChartPoint)); serviceHostsCont[proj.FullName] = serviceHost; //if (serviceHost.State != CommunicationState.Opening && serviceHost.State != CommunicationState.Opened) //{ NetNamedPipeBinding binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None); string address = "net.pipe://localhost/IPCChartPoint/" + System.IO.Path.GetFullPath(proj.FullName).ToLower(); serviceHost.AddServiceEndpoint(typeof(IIPCChartPoint), binding, address); serviceHost.Open(); //} } } } catch (Exception /*ex*/) { serviceHost = null; } } }
/// <summary> /// Finds the collection of additional libraries to link into this project. /// </summary> private void parseLinkerSettings_Libraries(VCConfiguration vcConfiguration, VCLinkerTool linkerTool, ProjectConfigurationInfo_CPP configurationInfo) { // The collection of libraries is stored in a space-delimited string... string strAdditionalLibraries = Utils.call(() => (linkerTool.AdditionalDependencies)); if (strAdditionalLibraries == null) { return; } List <string> additionalLibraries = Utils.split(strAdditionalLibraries, ' '); foreach (string additionalLibrary in additionalLibraries) { // We add the library to the project... string rawName = Path.GetFileNameWithoutExtension(additionalLibrary); configurationInfo.addLibraryRawName(rawName); } }
private static void ListToProjectConfig(Object tool, List <string> includes, List <string> libs) { if (tool is VCCLCompilerTool) { VCCLCompilerTool compilerTool = (VCCLCompilerTool)tool; compilerTool.AdditionalIncludeDirectories = includes.Aggregate((sum, value) => { return(sum + ";\n" + value); }); } else if (tool is VCLinkerTool) { VCLinkerTool linkerTool = (VCLinkerTool)tool; linkerTool.AdditionalDependencies = libs.Aggregate((sum, value) => { return(sum + ";\n" + value); }); } }
public void addLibsToVCProject(VCProject project) { foreach (VCConfiguration config in project.Configurations) { IVCCollection tools = config.Tools; foreach (Object tool in tools) { if (tool is VCLinkerTool) { VCLinkerTool linker = (VCLinkerTool)tool; if (config.Name == "Debug|Win32" && libs32Debug.Count > 0) { linker.AdditionalDependencies += ";\n" + libs32Debug.Aggregate((sum, value) => { return(sum + ";\n\"" + value + "\""); }); } else if (config.Name == "Debug|x64" && libs64Debug.Count > 0) { linker.AdditionalDependencies += ";\n" + libs64Debug.Aggregate((sum, value) => { return(sum + ";\n\"" + value + "\""); }); } else if (config.Name == "Release|Win32" && libs32Release.Count > 0) { linker.AdditionalDependencies += ";\n" + libs32Release.Aggregate((sum, value) => { return(sum + ";\n\"" + value + "\""); }); } else if (config.Name == "Release|x64" && libs64Release.Count > 0) { linker.AdditionalDependencies += ";\n" + libs64Debug.Aggregate((sum, value) => { return(sum + ";\n\"" + value + "\""); }); } } } } }
/// <summary> /// Finds the linker settings, such as the collection of libraries to link, /// for the configuration passed in. /// </summary> private void parseConfiguration_LinkerSettings(VCConfiguration vcConfiguration, ProjectConfigurationInfo_CPP configurationInfo) { // We get the linker-settings 'tool'... IVCCollection tools = Utils.call(() => (vcConfiguration.Tools as IVCCollection)); VCLinkerTool linkerTool = Utils.call(() => (tools.Item("VCLinkerTool") as VCLinkerTool)); if (linkerTool == null) { // Not all projects have a linker tools... return; } // And extract various details from it... parseLinkerSettings_LibraryPath(vcConfiguration, linkerTool, configurationInfo); parseLinkerSettings_Libraries(vcConfiguration, linkerTool, configurationInfo); parseLinkerSettings_Misc(vcConfiguration, linkerTool, configurationInfo); IVCCollection sheets = Utils.call(() => (vcConfiguration.PropertySheets as IVCCollection)); int numSheets = Utils.call(() => (sheets.Count)); for (int i = 1; i <= numSheets; ++i) { VCPropertySheet sheet = Utils.call(() => (sheets.Item(i) as VCPropertySheet)); if (!sheet.IsSystemPropertySheet) { // 1. The thing is that VCPropertySheet and VCConfiguration have more-or-less // identical interfaces. So we should be able to merge them fairly easily. // // 2. We should try multiple layers of inheritance IVCCollection toolsInSheet = Utils.call(() => (sheet.Tools as IVCCollection)); VCLinkerTool linkerToolInSheet = Utils.call(() => (toolsInSheet.Item("VCLinkerTool") as VCLinkerTool)); // And extract various details from it... if (linkerToolInSheet != null) { parseLinkerSettings_LibraryPath(vcConfiguration, linkerToolInSheet, configurationInfo); parseLinkerSettings_Libraries(vcConfiguration, linkerToolInSheet, configurationInfo); } } } }
/// <summary> /// Reads miscellaneous linker settings. /// </summary> private void parseLinkerSettings_Misc(VCConfiguration vcConfiguration, VCLinkerTool linkerTool, ProjectConfigurationInfo_CPP configurationInfo) { // Whether we implicitly link in libraries we depend on. // (We are assuming that all configurations of the project have the // same link-library-dependencies setting.) m_projectInfo.LinkLibraryDependencies = Utils.call(() => (linkerTool.LinkLibraryDependencies)); // Generate debug info... bool debugInfo = false; try { debugInfo = Utils.call(() => (linkerTool.GenerateDebugInformation)); } catch (Exception ex) { // TODO // Work around fix... // VS2015 or upper support /DEBUG:FASTLINK option. // But, VCLinkerTool don't support /DEBUG:FASTLINK. // GenerateDebugInformation has string "DebugFastLink", so, if we access GenerateDebugInformation, VCLinkerTool throw exception. // Visual Studio specifes the option in property sheed which is Micorsoft.Cpp.Win32.user or Microsoft.Cpp.x64.user. // It seems that it is difficult to modify the option. // So, I catch the exception and check message, if message includes "DebugFastLink", I handle GenerateDebugInformation returns true. if (ex.Message.Contains("DebugFastLink")) { debugInfo = true; } else { throw ex; } } if (debugInfo == true && configurationInfo.getPreprocessorDefinitions().Contains("NDEBUG") == false) { configurationInfo.addCompilerFlag("-g"); } }
private static void ParseProjectConfig(Object tool, List <string> includes, List <string> libs) { if (tool is VCCLCompilerTool) { VCCLCompilerTool compilerTool = (VCCLCompilerTool)tool; includes.AddRange(compilerTool.AdditionalIncludeDirectories.Split(';').Select((include) => { include = include.Replace("\n", ""); return(include.Trim()); })); } else if (tool is VCLinkerTool) { VCLinkerTool linkerTool = (VCLinkerTool)tool; libs.AddRange(linkerTool.AdditionalDependencies.Split(';').Select((lib) => { lib = lib.Replace("\n", ""); return(lib.Trim()); })); } }
static void Main(string[] args) { try { // Create a project engine VCProjectEngine projEngine = new VCProjectEngineObject(); // Load a project, change the name, add a configuration VCProject project = (VCProject)projEngine.LoadProject(@"..\..\..\MyProject\MyProject.vcproj"); if (project != null) { //Change the project's name project.Name = "Voila"; //Add a new configuration project.AddConfiguration("Whichever Name"); // Get the debug configuration and change the type to application VCConfiguration configuration = (VCConfiguration)(((IVCCollection)project.Configurations).Item("Debug")); if (configuration != null) { configuration.ConfigurationType = ConfigurationTypes.typeApplication; } else { Console.WriteLine(@"I Couldn't find the configuration"); } // Get the linker tool from the configration. VCLinkerTool linkerTool = (VCLinkerTool)(((IVCCollection)configuration.Tools).Item("VCLinkerTool")); if (linkerTool != null) { // Change the ShowProgress property to "Display All Progress Messages (/VERBOSE)" linkerTool.ShowProgress = linkProgressOption.linkProgressAll; } else { Console.WriteLine(@"I Couldn't find the linkerTool"); } // Add a cpp file called New.cpp if (project.CanAddFile("New.cpp")) { project.AddFile("New.cpp"); } else { Console.WriteLine(@"I Couldn't add the file"); } // Access the files collection IVCCollection filesCollection = (IVCCollection)project.Files; if (filesCollection != null) { // Access a cpp files called bar.cpp that is already in the project. VCFile file = (VCFile)(filesCollection.Item("Existing.cpp")); if (file != null) { // Access the release configuration of this file. VCFileConfiguration fileConfiguration = (VCFileConfiguration)(((IVCCollection)file.FileConfigurations).Item("Release|Win32")); // Get the compiler tool associated with this file. VCCLCompilerTool compilerTool = (VCCLCompilerTool)fileConfiguration.Tool; // Change the optimization property to Full Optimization (/Ox) compilerTool.Optimization = optimizeOption.optimizeFull; } else { Console.WriteLine(@"I Couldn't find the file"); } // Save the project, then remove it. project.ProjectFile = "MyNewProject.vcproj"; project.Save(); } else { Console.WriteLine(@"I Couldn't find the file collection"); } } else { Console.WriteLine(@"I Couldn't find the project"); } } catch (Exception e) { Console.WriteLine("Operation failed for the following reason: {0}", e.Message); } }
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; }
private List<String> GetLibraries(VCLinkerTool Linker) { String Libs = Linker.AdditionalDependencies; List<String> RetVal = new List<String>(Libs.Split(new char[] { ' ', ',', ';' }, StringSplitOptions.RemoveEmptyEntries)); RetVal.Sort(); return RetVal; }
private void DisableLinkConfig(ref VCLinkerTool linkerTool, string config) { Log("\tLinker Configuration"); if (linkerTool != null) { if (linkerTool.AdditionalOptions != null) { string newargs = DisableCodeCoverageCommandLineArguments(linkerTool.AdditionalOptions); if (linkerTool.AdditionalOptions != newargs) { linkerTool.AdditionalOptions = newargs; Log("\t\tAdditional command line arguments set to '" + newargs + "'"); } } } }
public void CreateTestCocoonConfig(String config, string project, List <string> additionalParamsList, List <string> additiona_includes, bool QtConfiguration) { bool foundProject = false; IEnumerator ProjectsEnumaror = GetVCProjectRefs(); ProjectsEnumaror.Reset(); // traverse all projects to find the right one while (ProjectsEnumaror.MoveNext()) { VCProject actVCP = (VCProject)ProjectsEnumaror.Current; if (actVCP.Name == project) { foundProject = true; VCConfiguration vcC = null; //vcC = (VCConfiguration)(((IVCCollection)actVCP.Configurations).Item(config)); IEnumerator ConfigurationEnumarator = ((IVCCollection)actVCP.Configurations).GetEnumerator(); for (ConfigurationEnumarator.Reset(); ConfigurationEnumarator.MoveNext();) { vcC = ConfigurationEnumarator.Current as VCConfiguration; if ((vcC != null) && (vcC.ConfigurationName == config)) { Log("Modifying configuration '" + config + "' for the project '" + project + "' for the platform '" + vcC.Name + "'"); // change settings for sepcified compiler IVCCollection ctools = (IVCCollection)vcC.Tools; VCActiveXReference cVCActiveXReference = ctools.Item("VCActiveXReference") as VCActiveXReference; VCALinkTool cVCALinkTool = ctools.Item("VCALinkTool") as VCALinkTool; VCAppVerifierTool cVCAppVerifierTool = ctools.Item("VCAppVerifierTool") as VCAppVerifierTool; VCAssemblyReference cVCAssemblyReference = ctools.Item("VCAssemblyReference") as VCAssemblyReference; VCBscMakeTool cVCBscMakeTool = ctools.Item("VCBscMakeTool") as VCBscMakeTool; VCCLCompilerTool cVCCLCompilerTool = ctools.Item("VCCLCompilerTool") as VCCLCompilerTool; VCConfiguration cVCConfiguration = ctools.Item("VCConfiguration") as VCConfiguration; VCCustomBuildRule cVCCustomBuildRule = ctools.Item("VCCustomBuildRule") as VCCustomBuildRule; VCCustomBuildTool cVCCustomBuildTool = ctools.Item("VCCustomBuildTool") as VCCustomBuildTool; VCDebugSettings cVCDebugSettings = ctools.Item("VCDebugSettings") as VCDebugSettings; VCFile cVCFile = ctools.Item("VCFile") as VCFile; VCFileConfiguration cVCFileConfiguration = ctools.Item("VCFileConfiguration") as VCFileConfiguration; VCFilter cVCFilter = ctools.Item("VCFilter") as VCFilter; VCFxCopTool cVCFxCopTool = ctools.Item("VCFxCopTool") as VCFxCopTool; VCLibrarianTool cVCLibrarianTool = ctools.Item("VCLibrarianTool") as VCLibrarianTool; VCLinkerTool cVCLinkerTool = ctools.Item("VCLinkerTool") as VCLinkerTool; VCManagedResourceCompilerTool cVCManagedResourceCompilerTool = ctools.Item("VCManagedResourceCompilerTool") as VCManagedResourceCompilerTool; VCManifestTool cVCManifestTool = ctools.Item("VCManifestTool") as VCManifestTool; VCMidlTool cVCMidlTool = ctools.Item("VCMidlTool") as VCMidlTool; VCNMakeTool cVCNMakeTool = ctools.Item("VCNMakeTool") as VCNMakeTool; VCPlatform cVCPlatform = ctools.Item("VCPlatform") as VCPlatform; VCPostBuildEventTool cVCPostBuildEventTool = ctools.Item("VCPostBuildEventTool") as VCPostBuildEventTool; VCPreBuildEventTool cVCPreBuildEventTool = ctools.Item("VCPreBuildEventTool") as VCPreBuildEventTool; VCPreLinkEventTool cVCPreLinkEventTool = ctools.Item("VCPreLinkEventTool") as VCPreLinkEventTool; VCProject cVCProject = ctools.Item("VCProject") as VCProject; VCProjectEngine cVCProjectEngine = ctools.Item("VCProjectEngine") as VCProjectEngine; VCProjectEngineEvents cVCProjectEngineEvents = ctools.Item("VCProjectEngineEvents") as VCProjectEngineEvents; VCProjectEngineObject cVCProjectEngineObject = ctools.Item("VCProjectEngineObject") as VCProjectEngineObject; VCProjectItem cVCProjectItem = ctools.Item("VCProjectItem") as VCProjectItem; VCProjectReference cVCProjectReference = ctools.Item("VCProjectReference") as VCProjectReference; VCPropertySheet cVCPropertySheet = ctools.Item("VCPropertySheet") as VCPropertySheet; VCReference cVCReference = ctools.Item("VCReference") as VCReference; VCReferences cVCReferences = ctools.Item("VCReferences") as VCReferences; VCResourceCompilerTool cVCResourceCompilerTool = ctools.Item("VCResourceCompilerTool") as VCResourceCompilerTool; VCRuntimeBooleanProperty cVCRuntimeBooleanProperty = ctools.Item("VCRuntimeBooleanProperty") as VCRuntimeBooleanProperty; VCRuntimeEnumProperty cVCRuntimeEnumProperty = ctools.Item("VCRuntimeEnumProperty") as VCRuntimeEnumProperty; VCRuntimeEnumValue cVCRuntimeEnumValue = ctools.Item("VCRuntimeEnumValue") as VCRuntimeEnumValue; VCRuntimeIntegerProperty cVCRuntimeIntegerProperty = ctools.Item("VCRuntimeIntegerProperty") as VCRuntimeIntegerProperty; VCRuntimeProperty cVCRuntimeProperty = ctools.Item("VCRuntimeProperty") as VCRuntimeProperty; VCRuntimeStringProperty cVCRuntimeStringProperty = ctools.Item("VCRuntimeStringProperty") as VCRuntimeStringProperty; VCToolFile cVCToolFile = ctools.Item("VCToolFile") as VCToolFile; VCUserMacro cVCUserMacro = ctools.Item("VCUserMacro") as VCUserMacro; VCWebDeploymentTool cVCWebDeploymentTool = ctools.Item("VCWebDeploymentTool") as VCWebDeploymentTool; VCWebServiceProxyGeneratorTool cVCWebServiceProxyGeneratorTool = ctools.Item("VCWebServiceProxyGeneratorTool") as VCWebServiceProxyGeneratorTool; VCXDCMakeTool cVCXDCMakeTool = ctools.Item("VCXDCMakeTool") as VCXDCMakeTool; VCXMLDataGeneratorTool cVCXMLDataGeneratorTool = ctools.Item("VCXMLDataGeneratorTool") as VCXMLDataGeneratorTool; VCLinkerTool linkerTool = ctools.Item("VCLinkerTool") as VCLinkerTool; VCLibrarianTool librarianTool = ctools.Item("VCLibrarianTool") as VCLibrarianTool; VCCLCompilerTool compilerTool = ctools.Item("VCCLCompilerTool") as VCCLCompilerTool; VCCustomBuildTool customBuildTool = ctools.Item("VCCustomBuildTool") as VCCustomBuildTool; string libgen = FindCslibConfig(ref compilerTool); List <string> additionalParamsListLink = new List <string>(additionalParamsList); List <string> additionalParamsListLibrarian = new List <string>(additionalParamsList); if (libgen != null) { additionalParamsListLink.Add("--cs-libgen=" + libgen); additionalParamsListLibrarian.Add("--cs-libgen=" + libgen); } if (compilerTool != null) { CreateClConfig(ref compilerTool, additionalParamsList, additiona_includes, actVCP.ProjectDirectory, config); } if (linkerTool != null) { CreateLinkConfig(ref linkerTool, additionalParamsListLink, config); } if (customBuildTool != null) { CreateCustomBuildConfig(ref customBuildTool, additionalParamsList, config); } if (librarianTool != null) { CreateLibrarianConfig(ref librarianTool, additionalParamsListLibrarian, config); } if (actVCP != null) { CreateConfigForEachFile(ref actVCP, additionalParamsList, config); } } } } } if (!foundProject) { ShowMessageBox("Could not find the project", "Warning"); } }
/****************************************************************/ #endregion /* LifeCycle */ #region Public Operations /****************************************************************/ public void ParseVcproj() { //this specifies the name of the 'rm -f' or equivalent command string rm = "rm -f -v"; //this specifies the default name for the dependencies file string dependencies = ".dependencies"; string cflags = ""; string ldflags = ""; string libs = ""; m_MakFWriter.WriteLine("# Makefile - {0}", m_ProjectName); m_MakFWriter.WriteLine(); //get the project name dependencies = m_ProjectName + ".dep"; //catch the default configuration definition = first configuration in vcproj configurations m_MakFWriter.WriteLine("ifndef CFG"); m_MakFWriter.WriteLine("CFG={0}", ((VCConfiguration)m_ConfigCollection.Item(1)).ConfigurationName); m_MakFWriter.WriteLine("endif"); //print the C++ compiler definition m_MakFWriter.WriteLine("CC=gcc"); if (m_PlatfromName.Equals("Win32")) { m_MakFWriter.WriteLine("CFLAGS=-m32 -fpic"); } else { m_MakFWriter.WriteLine("CFLAGS=-m64 -fpic"); } m_MakFWriter.WriteLine("CXX=g++"); m_MakFWriter.WriteLine("CXXFLAGS=$(CFLAGS)"); #region Config Parsing /**********************************/ foreach (VCConfiguration config in m_ConfigCollection) { //print else for "$(CFG)" section in case it is not first config in makefile //if (0 != m_NumOfConfigs) //{ // m_MakFWriter.WriteLine("else"); //} //TODO:check this issue //print ifeq "$(CFG)" "CONFIG_NAME" m_MakFWriter.WriteLine("ifeq \"$(CFG)\" \"{0}\"", config.ConfigurationName); IVCCollection toolsCollection = (IVCCollection)config.Tools; #region VCCLCompilerTool /**********************************/ VCCLCompilerTool compTool = (VCCLCompilerTool)toolsCollection.Item("VCCLCompilerTool"); if (null != compTool) { cflags = iCreateCflags(compTool); //add special include path for VTOC files for (int i = 0; i < m_VcProjDependencies.Length; i++) { if (m_VcProjDependencies[i].Equals("v_to_c")) { cflags += " -I VTOC/share/include"; } } m_MakFWriter.WriteLine("CFLAGS+={0}", cflags); } /**********************************/ #endregion VCCLCompilerTool #region VCLinkerTool /**********************************/ VCLinkerTool lnkTool = (VCLinkerTool)toolsCollection.Item("VCLinkerTool"); if (null != lnkTool) { if ((m_TargetDictionary[config.ConfigurationName].ExeFlag) || (m_TargetDictionary[config.ConfigurationName].DllFlag)) { m_MakFWriter.WriteLine("LD=$(CXX) $(CXXFLAGS)"); } m_MakFWriter.WriteLine("LDFLAGS="); libs = iCreateLibs(lnkTool); ldflags = iCreateLdflags(lnkTool); m_MakFWriter.WriteLine("LDFLAGS+={0}", ldflags); if (m_TargetDictionary[config.ConfigurationName].ExeFlag) { m_MakFWriter.WriteLine("LIBS+={0}", libs); } if (m_TargetDictionary[config.ConfigurationName].DllFlag) { m_MakFWriter.WriteLine("LIBS+= -shared {0}", libs); } } /**********************************/ #endregion VCLinkerTool #region VCLibrarianTool /**********************************/ VCLibrarianTool libTool = (VCLibrarianTool)toolsCollection.Item("VCLibrarianTool"); if (null != libTool) { m_MakFWriter.WriteLine("AR=ar"); m_MakFWriter.WriteLine("ARFLAGS=rus"); } /**********************************/ #endregion VCLibrarianTool //print target for each configuration iPrintTARGET2Makefile(config.ConfigurationName); } //close every ifeq "$(CFG)" with endif for (int i = 0; i < m_NumOfConfigs; i++) { m_MakFWriter.WriteLine("endif"); } /**********************************/ #endregion Config Parsing //print default target for first configuration in configCollection iPrintTARGET2Makefile(((VCConfiguration)m_ConfigCollection.Item(1)).ConfigurationName); //print the default target and the suffix rules m_MakFWriter.WriteLine(".PHONY: all"); m_MakFWriter.WriteLine("all: $(TARGET)"); m_MakFWriter.WriteLine(""); m_MakFWriter.WriteLine("%.o: %.c"); m_MakFWriter.WriteLine("\t$(CC) $(CFLAGS) $(CPPFLAGS) -o $@ -c $<"); m_MakFWriter.WriteLine(""); m_MakFWriter.WriteLine("%.o: %.cc"); m_MakFWriter.WriteLine("\t$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $<"); m_MakFWriter.WriteLine(""); m_MakFWriter.WriteLine("%.o: %.cpp"); m_MakFWriter.WriteLine("\t$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $<"); m_MakFWriter.WriteLine(""); m_MakFWriter.WriteLine("%.o: %.cxx"); m_MakFWriter.WriteLine("\t$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $<"); m_MakFWriter.WriteLine(""); m_MakFWriter.WriteLine("%.res: %.rc"); m_MakFWriter.WriteLine("\t$(RC) $(CPPFLAGS) -o $@ -i $<"); m_MakFWriter.WriteLine(""); #region Sources /**********************************/ iPrintGroupsAndSources(); /**********************************/ #endregion Sources //define the objects automatically from the sources in the Makefile m_MakFWriter.WriteLine("OBJS=$(patsubst %.rc,%.res,$(patsubst %.cxx,%.o,$(patsubst %.cpp,%.o,$(patsubst %.cc,%.o,$(patsubst %.c,%.o,$(filter %.c %.cc %.cpp %.cxx %.rc,$(SRCS)))))))"); m_MakFWriter.WriteLine(""); //print the target rule, according to the type of deafult target = target of first configuration in vcproj configurations list m_MakFWriter.WriteLine("$(TARGET): $(OBJS)"); VcTargetType target = m_TargetDictionary[((VCConfiguration)m_ConfigCollection.Item(1)).ConfigurationName]; if (target.ExeFlag) { m_MakFWriter.WriteLine("\t$(LD) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)"); } if (target.DllFlag) { m_MakFWriter.WriteLine("\t$(LD) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)"); } if (target.LibFlag) { m_MakFWriter.WriteLine("\t$(AR) $(ARFLAGS) $@ $(OBJS)"); } m_MakFWriter.WriteLine(""); // print the 'clean' target rule m_MakFWriter.WriteLine(".PHONY: clean"); m_MakFWriter.WriteLine("clean:"); m_MakFWriter.WriteLine("\t-{0} $(OBJS) $(TARGET) {1}", rm, dependencies); m_MakFWriter.WriteLine(""); // print the 'depends' target rule for automatic dependencies generation m_MakFWriter.WriteLine(".PHONY: depends"); m_MakFWriter.WriteLine("depends:"); m_MakFWriter.WriteLine("\t-$(CXX) $(CXXFLAGS) $(CPPFLAGS) -MM $(filter %.c %.cc %.cpp %.cxx,$(SRCS)) > {0}", dependencies); m_MakFWriter.WriteLine(""); m_MakFWriter.WriteLine("-include {0}", dependencies); m_MakFWriter.WriteLine(""); m_MakFWriter.Close(); iFixMakfile(); }
private void CreateLinkConfig(ref VCLinkerTool linkerTool, List<string> additionalParamsList, string config) { Log("\tLinker Configuration"); if (linkerTool != null) { if (linkerTool.AdditionalOptions == null) linkerTool.AdditionalOptions = " "; string additionalParams = generateParamString(additionalParamsList, linkerTool.AdditionalOptions); if (additionalParams.Length > 0) { linkerTool.AdditionalOptions += " " + additionalParams; Log("\t\tAdditional command line arguments '" + additionalParams + "' are appended"); } } }
public LinkerToolWrapper(VCLinkerTool linkerTool) { linker = linkerTool; }
/// <summary> /// Finds the library path for the configuration passed in. /// </summary> private void parseLinkerSettings_LibraryPath(VCConfiguration vcConfiguration, VCLinkerTool linkerTool, ProjectConfigurationInfo_CPP configurationInfo) { // We: // 1. Read the additional library paths (which are in a semi-colon-delimited string) // 2. Split it into separate paths // 3. Resolve any symbols // 4. Make sure all paths are relative to the project root folder // 1 & 2... string strAdditionalLibraryDirectories = Utils.call(() => (linkerTool.AdditionalLibraryDirectories)); if (strAdditionalLibraryDirectories == null) { return; } List <string> additionalLibraryDirectories = Utils.split(strAdditionalLibraryDirectories, ';', ','); foreach (string additionalLibraryDirectory in additionalLibraryDirectories) { // The string may be quoted. We need to remove the quotes... string unquotedLibraryDirectory = additionalLibraryDirectory.Trim('"'); if (unquotedLibraryDirectory == "") { continue; } // 3 & 4... string resolvedPath = Utils.call(() => (vcConfiguration.Evaluate(unquotedLibraryDirectory))); if (resolvedPath != "") { string relativePath = Utils.makeRelativePath(m_projectInfo.RootFolderAbsolute, resolvedPath); configurationInfo.addLibraryPath(relativePath); } } }
/// <summary> /// Finds the library path for the configuration passed in. /// </summary> private void parseLinkerSettings_LibraryPath(VCConfiguration vcConfiguration, VCLinkerTool linkerTool, ProjectConfigurationInfo_CPP configurationInfo) { // We: // 1. Read the additional library paths (which are in a semi-colon-delimited string) // 2. Split it into separate paths // 3. Resolve any symbols // 4. Make sure all paths are relative to the project root folder // 1 & 2... string strAdditionalLibraryDirectories = Utils.call(() => (linkerTool.AdditionalLibraryDirectories)); if (strAdditionalLibraryDirectories == null) { return; } List<string> additionalLibraryDirectories = Utils.split(strAdditionalLibraryDirectories, ';', ','); foreach (string additionalLibraryDirectory in additionalLibraryDirectories) { // The string may be quoted. We need to remove the quotes... string unquotedLibraryDirectory = additionalLibraryDirectory.Trim('"'); if (unquotedLibraryDirectory == "") { continue; } // 3 & 4... string resolvedPath = Utils.call(() => (vcConfiguration.Evaluate(unquotedLibraryDirectory))); if (resolvedPath != "") { string relativePath = Utils.makeRelativePath(m_projectInfo.RootFolderAbsolute, resolvedPath); configurationInfo.addLibraryPath(relativePath); } } }
public LinkerToolWrapper(VCLinkerTool linkerTool) { linker = linkerTool; }
/// <summary> /// Finds the collection of additional libraries to link into this project. /// </summary> private void parseLinkerSettings_Libraries(VCConfiguration vcConfiguration, VCLinkerTool linkerTool, ProjectConfigurationInfo_CPP configurationInfo) { // The collection of libraries is stored in a space-delimited string... string strAdditionalLibraries = Utils.call(() => (linkerTool.AdditionalDependencies)); if (strAdditionalLibraries == null) { return; } List<string> additionalLibraries = Utils.split(strAdditionalLibraries, ' '); foreach (string additionalLibrary in additionalLibraries) { // We add the library to the project... string rawName = Path.GetFileNameWithoutExtension(additionalLibrary); configurationInfo.addLibraryRawName(rawName); } }
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())); } }
/// <summary> /// Reads miscellaneous linker settings. /// </summary> private void parseLinkerSettings_Misc(VCConfiguration vcConfiguration, VCLinkerTool linkerTool, ProjectConfigurationInfo_CPP configurationInfo) { // Whether we implicitly link in libraries we depend on. // (We are assuming that all configurations of the project have the // same link-library-dependencies setting.) m_projectInfo.LinkLibraryDependencies = Utils.call(() => (linkerTool.LinkLibraryDependencies)); // Generate debug info... bool debugInfo = Utils.call(() => (linkerTool.GenerateDebugInformation)); if (debugInfo == true && configurationInfo.getPreprocessorDefinitions().Contains("NDEBUG") == false) { configurationInfo.addCompilerFlag("-g"); } }
private void Initialize( EnvDTE.Project prj ) { project = (VCProject)prj.Object; configurations = (IVCCollection)project.Configurations; EnvDTE.ConfigurationManager configManager = prj.ConfigurationManager; EnvDTE.Configuration activeConfig = configManager.ActiveConfiguration; string activeConfigNamePlatform = activeConfig.ConfigurationName + "|" + activeConfig.PlatformName; foreach (VCConfiguration c in project.Configurations) { if (c.Name == activeConfigNamePlatform) { config = c; break; } } Debug.Assert(config != null); if (config == null) throw new InvalidOperationException("The specified file does not have a configuration corresponding to the current active configuration."); //config = (VCConfiguration)configurations.Item(1); tools = (IVCCollection)config.Tools; cltool = (VCCLCompilerTool)tools.Item("VCCLCompilerTool"); ltool = (VCLinkerTool)tools.Item("VCLinkerTool"); }