/// <summary> /// Find all include files and add them to this object. /// </summary> public void FindIncludeFiles() { // Find all *.cmake files in the same directory as the current source file, // excluding cmake_install.cmake, which is generated by CMake during // configuration. string dirPath = Path.GetDirectoryName(_sourceFilePath); IEnumerable <string> files = GetFilesFromDir(dirPath); AddItems(files, GetIncludeFileItemType()); // Find all *.cmake files in the Modules directory inside the CMake // installation, if there is one. string pathToModules = CMakePath.FindCMakeModules(); bool foundModules = false; if (pathToModules != null) { foundModules = true; files = GetFilesFromDir(pathToModules, true); AddItems(files, GetModuleItemType()); } if (!foundModules) { // If we couldn't find modules in a CMake installation, show a default // hard-code listing. AddItems(GetDefaultModules(), GetModuleItemType()); } }
private void UpdateIncludeCacheItem(string include) { string curFileDir = Path.GetDirectoryName(GetFilePath()); string path = null; bool needUpdate = true; if (_includeCache.ContainsKey(include) && File.Exists(_includeCache[include].FileName)) { path = _includeCache[include].FileName; needUpdate = (File.GetLastWriteTime(path) != _includeCache[include].TimeStamp); } else { path = Path.Combine(curFileDir, include + ".cmake"); if (!File.Exists(path)) { path = Path.Combine(CMakePath.FindCMakeModules(), include + ".cmake"); if (!File.Exists(path)) { path = null; } } } if (path != null && needUpdate) { try { string[] includeLines = File.ReadAllLines(path); bool rootRef = _includeCache.ContainsKey(include) && _includeCache[include].RootRef; _includeCache[include] = new IncludeCacheEntry() { FileName = path, TimeStamp = File.GetLastWriteTime(path), RootRef = rootRef, Variables = CMakeParsing.ParseForVariables(includeLines), EnvVariables = CMakeParsing.ParseForEnvVariables( includeLines), CacheVariables = CMakeParsing.ParseForCacheVariables( includeLines), Functions = CMakeParsing.ParseForFunctionNames(includeLines, false), Macros = CMakeParsing.ParseForFunctionNames(includeLines, true), Dependencies = CMakeParsing.ParseForIncludes(includeLines) }; foreach (string dependency in _includeCache[include].Dependencies) { UpdateIncludeCacheItem(dependency); } } catch (IOException) { // Just ignore any errors. } } }
/// <summary> /// Open the specified CMake Help HTML file in Visual Studio's built-in web /// browser. /// </summary> /// <param name="fileName">The name of HTML file to open.</param> public void OpenCMakeHelpPage(params string[] fileNames) { // Attempt to find CMake in the registry. string location = CMakePath.FindCMakeHelp(); // If we found CMake, attempt to open the request help page in // Visual Studio's built-in web browser. if (location != null) { foreach (string fileName in fileNames) { string absolutePath = Path.Combine(location, fileName); int hashPos = absolutePath.IndexOf('#'); string strippedPath = hashPos >= 0 ? absolutePath.Substring(0, hashPos) : absolutePath; if (File.Exists(strippedPath)) { OpenWebPage(absolutePath); break; } } } else { // Display an error message that CMake could not be found. MessageBox.Show(CMakeStrings.CMakeNotFound, CMakeStrings.MessageBoxTitle, MessageBoxButtons.OK, MessageBoxIcon.Stop); } }
private void CMakeMenuCallback(object sender, EventArgs e) { // Attempt to find CMake in the registry. string location = CMakePath.FindCMake(); // If we found CMake, attempt to spawn it. if (location != null) { bool launchFailed = false; try { Process process = Process.Start(Path.Combine(location, "bin\\cmake-gui.exe")); if (process != null) { process.Dispose(); } else { launchFailed = true; } } catch (Exception) { launchFailed = true; } if (launchFailed) { // Display an error message that CMake failed to launch. MessageBox.Show(CMakeStrings.FailedToLaunchCMake, CMakeStrings.MessageBoxTitle, MessageBoxButtons.OK, MessageBoxIcon.Stop); } } else { // Display an error message that CMake could not be found. MessageBox.Show(CMakeStrings.CMakeNotFound, CMakeStrings.MessageBoxTitle, MessageBoxButtons.OK, MessageBoxIcon.Stop); } }
private static List <string> GetStandardVariables(CMakeVariableType type) { List <string> vars = new List <string>(); switch (type) { case CMakeVariableType.Variable: case CMakeVariableType.CacheVariable: // All cache variables also serve as ordinary CMake variables, but not // the other way around. if (type == CMakeVariableType.Variable) { vars.AddRange(_standardVariables); } vars.AddRange(_standardCacheVariables); string path = CMakePath.FindCMakeModules(); if (path != null) { IEnumerable <string> languages = CMakeLanguageDeclarations.GetLanguagesFromDir(path); foreach (string language in languages) { if (type == CMakeVariableType.Variable) { vars.AddRange(_standardLangVariables.Select( x => string.Format(x, language))); } vars.AddRange(_standardLangCacheVariables.Select( x => string.Format(x, language))); } } break; case CMakeVariableType.EnvVariable: vars.AddRange(_standardEnvVariables); break; } return(vars); }
private string GetCurrentTokenFileName(out string extraSearchPath) { // Obtain the name of the file referenced by the current token if there is // one or null otherwise. int line; int col; extraSearchPath = null; if (TextView == null || TextView.GetCaretPos(out line, out col) != VSConstants.S_OK) { return(null); } TokenInfo tokenInfo = Source.GetTokenInfo(line, col); if (tokenInfo == null || (tokenInfo.Token != (int)CMakeToken.FileName && tokenInfo.Token != (int)CMakeToken.Identifier)) { return(null); } string text = Source.GetText(tokenInfo.ToTextSpan(line)); if (string.IsNullOrEmpty(text)) { return(null); } // If the string specifies a file name with an extension, just return it // regardless or where it is found. if (tokenInfo.Token == (int)CMakeToken.FileName && text.IndexOf('.') >= 0) { return(text); } // An identifier or path may reference a file if appears as a parameter to // one of certain commands, such as INCLUDE or FIND_PACKAGE. Parse to find // the command to which the token is a parameter, if any, and handle it // accordingly. CMakeParsing.TokenData tokenData; if (!CMakeParsing.ParseForToken(Source.GetLines(), line, col, out tokenData) || !tokenData.InParens) { return(null); } switch (tokenData.Command) { case CMakeCommandId.Include: if (tokenData.ParameterIndex == 0) { extraSearchPath = CMakePath.FindCMakeModules(); return(string.Format("{0}.cmake", Source.GetText(tokenInfo.ToTextSpan(line)))); } break; case CMakeCommandId.FindPackage: if (tokenData.ParameterIndex == 0) { extraSearchPath = CMakePath.FindCMakeModules(); return(string.Format("Find{0}.cmake", Source.GetText(tokenInfo.ToTextSpan(line)))); } break; case CMakeCommandId.AddSubdirectory: if (tokenData.ParameterIndex == 0) { return(Path.Combine(Source.GetText(tokenInfo.ToTextSpan(line)), "CMakeLists.txt")); } break; } return(null); }