1 //===- HeaderSearchOptions.h ------------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_CLANG_LEX_HEADERSEARCHOPTIONS_H
10 #define LLVM_CLANG_LEX_HEADERSEARCHOPTIONS_H
12 #include "clang/Basic/LLVM.h"
13 #include "llvm/ADT/CachedHashString.h"
14 #include "llvm/ADT/SetVector.h"
15 #include "llvm/ADT/StringRef.h"
25 /// IncludeDirGroup - Identifies the group an include Entry belongs to,
26 /// representing its relative positive in the search list.
27 /// \#include directives whose paths are enclosed by string quotes ("")
28 /// start searching at the Quoted group (specified by '-iquote'),
29 /// then search the Angled group, then the System group, etc.
30 enum IncludeDirGroup {
31 /// '\#include ""' paths, added by 'gcc -iquote'.
34 /// Paths for '\#include <>' added by '-I'.
37 /// Like Angled, but marks header maps used when building frameworks.
40 /// Like Angled, but marks system directories.
43 /// Like System, but headers are implicitly wrapped in extern "C".
46 /// Like System, but only used for C.
49 /// Like System, but only used for C++.
52 /// Like System, but only used for ObjC.
55 /// Like System, but only used for ObjC++.
58 /// Like System, but searched after the system directories.
62 } // namespace frontend
64 /// HeaderSearchOptions - Helper class for storing options related to the
65 /// initialization of the HeaderSearch object.
66 class HeaderSearchOptions {
70 frontend::IncludeDirGroup Group;
71 unsigned IsFramework : 1;
73 /// IgnoreSysRoot - This is false if an absolute path should be treated
74 /// relative to the sysroot, or true if it should always be the absolute
76 unsigned IgnoreSysRoot : 1;
78 Entry(StringRef path, frontend::IncludeDirGroup group, bool isFramework,
80 : Path(path), Group(group), IsFramework(isFramework),
81 IgnoreSysRoot(ignoreSysRoot) {}
84 struct SystemHeaderPrefix {
85 /// A prefix to be matched against paths in \#include directives.
88 /// True if paths beginning with this prefix should be treated as system
92 SystemHeaderPrefix(StringRef Prefix, bool IsSystemHeader)
93 : Prefix(Prefix), IsSystemHeader(IsSystemHeader) {}
96 /// If non-empty, the directory to use as a "virtual system root" for include
100 /// User specified include entries.
101 std::vector<Entry> UserEntries;
103 /// User-specified system header prefixes.
104 std::vector<SystemHeaderPrefix> SystemHeaderPrefixes;
106 /// The directory which holds the compiler resource files (builtin includes,
108 std::string ResourceDir;
110 /// The directory used for the module cache.
111 std::string ModuleCachePath;
113 /// The directory used for a user build.
114 std::string ModuleUserBuildPath;
116 /// The mapping of module names to prebuilt module files.
117 std::map<std::string, std::string> PrebuiltModuleFiles;
119 /// The directories used to load prebuilt module files.
120 std::vector<std::string> PrebuiltModulePaths;
122 /// The module/pch container format.
123 std::string ModuleFormat;
125 /// Whether we should disable the use of the hash string within the
128 /// Note: Only used for testing!
129 unsigned DisableModuleHash : 1;
131 /// Implicit module maps. This option is enabld by default when
132 /// modules is enabled.
133 unsigned ImplicitModuleMaps : 1;
135 /// Set the 'home directory' of a module map file to the current
136 /// working directory (or the home directory of the module map file that
137 /// contained the 'extern module' directive importing this module map file
138 /// if any) rather than the directory containing the module map file.
140 /// The home directory is where we look for files named in the module map
142 unsigned ModuleMapFileHomeIsCwd : 1;
144 /// The interval (in seconds) between pruning operations.
146 /// This operation is expensive, because it requires Clang to walk through
147 /// the directory structure of the module cache, stat()'ing and removing
150 /// The default value is large, e.g., the operation runs once a week.
151 unsigned ModuleCachePruneInterval = 7 * 24 * 60 * 60;
153 /// The time (in seconds) after which an unused module file will be
154 /// considered unused and will, therefore, be pruned.
156 /// When the module cache is pruned, any module file that has not been
157 /// accessed in this many seconds will be removed. The default value is
158 /// large, e.g., a month, to avoid forcing infrequently-used modules to be
159 /// regenerated often.
160 unsigned ModuleCachePruneAfter = 31 * 24 * 60 * 60;
162 /// The time in seconds when the build session started.
164 /// This time is used by other optimizations in header search and module
166 uint64_t BuildSessionTimestamp = 0;
168 /// The set of macro names that should be ignored for the purposes
169 /// of computing the module hash.
170 llvm::SmallSetVector<llvm::CachedHashString, 16> ModulesIgnoreMacros;
172 /// The set of user-provided virtual filesystem overlay files.
173 std::vector<std::string> VFSOverlayFiles;
175 /// Include the compiler builtin includes.
176 unsigned UseBuiltinIncludes : 1;
178 /// Include the system standard include search directories.
179 unsigned UseStandardSystemIncludes : 1;
181 /// Include the system standard C++ library include search directories.
182 unsigned UseStandardCXXIncludes : 1;
184 /// Use libc++ instead of the default libstdc++.
185 unsigned UseLibcxx : 1;
187 /// Whether header search information should be output as for -v.
188 unsigned Verbose : 1;
190 /// If true, skip verifying input files used by modules if the
191 /// module was already verified during this build session (see
192 /// \c BuildSessionTimestamp).
193 unsigned ModulesValidateOncePerBuildSession : 1;
195 /// Whether to validate system input files when a module is loaded.
196 unsigned ModulesValidateSystemHeaders : 1;
198 /// Whether the module includes debug information (-gmodules).
199 unsigned UseDebugInfo : 1;
201 unsigned ModulesValidateDiagnosticOptions : 1;
203 unsigned ModulesHashContent : 1;
205 HeaderSearchOptions(StringRef _Sysroot = "/")
206 : Sysroot(_Sysroot), ModuleFormat("raw"), DisableModuleHash(false),
207 ImplicitModuleMaps(false), ModuleMapFileHomeIsCwd(false),
208 UseBuiltinIncludes(true), UseStandardSystemIncludes(true),
209 UseStandardCXXIncludes(true), UseLibcxx(false), Verbose(false),
210 ModulesValidateOncePerBuildSession(false),
211 ModulesValidateSystemHeaders(false), UseDebugInfo(false),
212 ModulesValidateDiagnosticOptions(true), ModulesHashContent(false) {}
214 /// AddPath - Add the \p Path path to the specified \p Group list.
215 void AddPath(StringRef Path, frontend::IncludeDirGroup Group,
216 bool IsFramework, bool IgnoreSysRoot) {
217 UserEntries.emplace_back(Path, Group, IsFramework, IgnoreSysRoot);
220 /// AddSystemHeaderPrefix - Override whether \#include directives naming a
221 /// path starting with \p Prefix should be considered as naming a system
223 void AddSystemHeaderPrefix(StringRef Prefix, bool IsSystemHeader) {
224 SystemHeaderPrefixes.emplace_back(Prefix, IsSystemHeader);
227 void AddVFSOverlayFile(StringRef Name) {
228 VFSOverlayFiles.push_back(Name);
231 void AddPrebuiltModulePath(StringRef Name) {
232 PrebuiltModulePaths.push_back(Name);
238 #endif // LLVM_CLANG_LEX_HEADERSEARCHOPTIONS_H