/// <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. } } }
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); }