cmake_parser/doc/command/
mod.rs

1pub mod common;
2pub mod ctest;
3pub mod deprecated;
4pub mod project;
5pub mod scripting;
6
7/// CMake command.
8///
9/// Reference: <https://cmake.org/cmake/help/v3.26/manual/cmake-commands.7.html>
10#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
11pub enum Command<'t> {
12    /// Add preprocessor definitions to the compilation of source files.
13    AddCompileDefinitions(Box<project::AddCompileDefinitions<'t>>),
14    /// Adds options to the compilation of source files.
15    AddCompileOptions(Box<project::AddCompileOptions<'t>>),
16    /// Add a custom build rule to the generated build system.
17    AddCustomCommand(Box<project::AddCustomCommand<'t>>),
18    /// Add a target with no output so it will always be built.
19    AddCustomTarget(Box<project::AddCustomTarget<'t>>),
20    /// Add -D define flags to the compilation of source files.
21    AddDefinitions(Box<project::AddDefinitions<'t>>),
22    /// Add a dependency between top-level targets.
23    AddDependencies(Box<project::AddDependencies<'t>>),
24    /// Add an executable to the project using the specified source files.
25    AddExecutable(Box<project::AddExecutable<'t>>),
26    /// Add a library to the project using the specified source files.
27    AddLibrary(Box<project::AddLibrary<'t>>),
28    /// Add options to the link step for executable, shared library or module library targets in the current directory and below that are added after this command is invoked.
29    AddLinkOptions(Box<project::AddLinkOptions<'t>>),
30    /// Add a subdirectory to the build.
31    AddSubdirectory(Box<project::AddSubdirectory<'t>>),
32    /// Add a test to the project to be run by ctest.
33    AddTest(Box<project::AddTest<'t>>),
34    /// Find all source files in a directory.
35    AuxSourceDirectory(Box<project::AuxSourceDirectory<'t>>),
36    /// Get a command line to build the current project.
37    BuildCommand(Box<project::BuildCommand<'t>>),
38    /// Create a test driver and source list for building test programs.
39    CreateTestSourceList(Box<project::CreateTestSourceList<'t>>),
40    /// Define and document custom properties.
41    DefineProperty(Box<project::DefineProperty<'t>>),
42    /// Enable languages (CXX/C/OBJC/OBJCXX/Fortran/etc)
43    EnableLanguage(Box<project::EnableLanguage<'t>>),
44    /// Enable testing for current directory and below.
45    EnableTesting,
46    /// Export targets or packages for outside projects to use them directly from the current project's build tree, without installation.
47    Export(Box<project::Export<'t>>),
48    /// Create FLTK user interfaces Wrappers.
49    FLTKWrapUI(Box<project::FLTKWrapUI<'t>>),
50    /// Get a property for a source file.
51    GetSourceFileProperty(Box<project::GetSourceFileProperty<'t>>),
52    /// Get a property from a target.
53    GetTargetProperty(Box<project::GetTargetProperty<'t>>),
54    /// Get a property of the test.
55    GetTestProperty(Box<project::GetTestProperty<'t>>),
56    /// Add include directories to the build.
57    IncludeDirectories(Box<project::IncludeDirectories<'t>>),
58    /// Include an external Microsoft project file in a workspace.
59    IncludeExternalMSProject(Box<project::IncludeExternalMSProject<'t>>),
60    /// Set the regular expression used for dependency checking.
61    IncludeRegularExpression(Box<project::IncludeRegularExpression<'t>>),
62    /// Specify rules to run at install time.
63    Install(Box<project::Install<'t>>),
64    /// Add directories in which the linker will look for libraries.
65    LinkDirectories(Box<project::LinkDirectories<'t>>),
66    /// Link libraries to all targets added later.
67    LinkLibraries(Box<project::LinkLibraries<'t>>),
68    /// Load in the values from another project's CMake cache.
69    LoadCache(Box<project::LoadCache<'t>>),
70    /// Set the name of the project.
71    Project(Box<project::Project<'t>>),
72    /// Remove -D define flags added by add_definitions().
73    RemoveDefinitions(Box<project::RemoveDefinitions<'t>>),
74    /// Sets properties associated with source files using a key/value paired list.
75    SetSourceFileProperties(Box<project::SetSourceFileProperties<'t>>),
76    /// Sets properties on targets.
77    SetTargetProperties(Box<project::SetTargetProperties<'t>>),
78    /// Set a property of the tests.
79    SetTestsProperties(Box<project::SetTestsProperties<'t>>),
80    /// Define a grouping for source files in IDE project generation.
81    SourceGroup(Box<project::SourceGroup<'t>>),
82    /// Add compile definitions to a target.
83    TargetCompileDefinitions(Box<project::TargetCompileDefinitions<'t>>),
84    /// Add expected compiler features to a target.
85    TargetCompileFeatures(Box<project::TargetCompileFeatures<'t>>),
86    /// Add compile options to a target.
87    TargetCompileOptions(Box<project::TargetCompileOptions<'t>>),
88    /// Add include directories to a target.
89    TargetIncludeDirectories(Box<project::TargetIncludeDirectories<'t>>),
90    /// Add link directories to a target.
91    TargetLinkDirectories(Box<project::TargetLinkDirectories<'t>>),
92    /// Specify libraries or flags to use when linking a given target and/or its dependents.
93    TargetLinkLibraries(Box<project::TargetLinkLibraries<'t>>),
94    /// Add options to the link step for an executable, shared library or module library target.
95    TargetLinkOptions(Box<project::TargetLinkOptions<'t>>),
96    /// Add a list of header files to precompile.
97    TargetPrecompileHeaders(Box<project::TargetPrecompileHeaders<'t>>),
98    /// Add sources to a target.
99    TargetSources(Box<project::TargetSources<'t>>),
100    /// Try building some code.
101    TryCompile(Box<project::TryCompile<'t>>),
102    /// Try compiling and then running some code.
103    TryRun(Box<project::TryRun<'t>>),
104    /// Perform the CTest Build Step as a Dashboard Client.
105    CTestBuild(Box<ctest::CTestBuild<'t>>),
106    /// Perform the CTest Configure Step as a Dashboard Client.
107    CTestConfigure(Box<ctest::CTestConfigure<'t>>),
108    /// Perform the CTest Coverage Step as a Dashboard Client.
109    CTestCoverage(Box<ctest::CTestCoverage<'t>>),
110    /// Removes a binary directory.
111    CTestEmptyBinaryDirectory(Box<ctest::CTestEmptyBinaryDirectory<'t>>),
112    /// Perform the CTest MemCheck Step as a Dashboard Client.
113    CTestMemCheck(Box<ctest::CTestMemCheck<'t>>),
114    /// Read all the CTestCustom.ctest or CTestCustom.cmake files from the given directory.
115    CTestReadCustomFiles(Box<ctest::CTestReadCustomFiles<'t>>),
116    /// Runs a script or scripts much like if it was run from ctest -S.
117    CTestRunScript(Box<ctest::CTestRunScript<'t>>),
118    /// Sleeps for some amount of time
119    CTestSleep(Box<ctest::CTestSleep<'t>>),
120    /// Starts the testing for a given model
121    CTestStart(Box<ctest::CTestStart<'t>>),
122    /// Perform the CTest Submit Step as a Dashboard Client.
123    CTestSubmit(Box<ctest::CTestSubmit<'t>>),
124    /// Perform the CTest Test Step as a Dashboard Client.
125    CTestTest(Box<ctest::CTestTest<'t>>),
126    /// Perform the CTest Update Step as a Dashboard Client.
127    CTestUpdate(Box<ctest::CTestUpdate<'t>>),
128    /// Upload files to a dashboard server as a Dashboard Client.
129    CTestUpload(Box<ctest::CTestUpload<'t>>),
130    /// Sets the specified variable to a string representing the platform and compiler settings.
131    BuildName(Box<deprecated::BuildName<'t>>),
132    /// Run an executable program during the processing of the CMakeList.txt file.
133    ExecProgram(Box<deprecated::ExecProgram<'t>>),
134    /// This command generates an old-style library dependencies file.
135    ExportLibraryDependencies(Box<deprecated::ExportLibraryDependencies<'t>>),
136    /// Specifies rules for installing files for a project.
137    InstallFiles(Box<deprecated::InstallFiles<'t>>),
138    /// Specifies rules for installing programs for a project.
139    InstallPrograms(Box<deprecated::InstallPrograms<'t>>),
140    /// Create rules to install the listed targets into the given directory.
141    InstallTargets(Box<deprecated::InstallTargets<'t>>),
142    /// Load a command into a running CMake.
143    LoadCommand(Box<deprecated::LoadCommand<'t>>),
144    /// Creates the specified directory.
145    MakeDirectory(Box<deprecated::MakeDirectory<'t>>),
146    /// Approximate C preprocessor dependency scanning.
147    OutputRequiredFiles(Box<deprecated::OutputRequiredFiles<'t>>),
148    /// Manually create Qt Wrappers.
149    QtWrapCpp(Box<deprecated::QtWrapCpp<'t>>),
150    /// Manually create Qt user interfaces Wrappers.
151    QtWrapUi(Box<deprecated::QtWrapUi<'t>>),
152    /// Removes value from the variable.
153    Remove(Box<deprecated::Remove<'t>>),
154    /// Does nothing.
155    SubdirDepends(Box<deprecated::SubdirDepends<'t>>),
156    /// Add a list of subdirectories to the build.
157    Subdirs(Box<deprecated::Subdirs<'t>>),
158    /// Copy mesa headers for use in combination with system GL.
159    UseMangledMesa(Box<deprecated::UseMangledMesa<'t>>),
160    /// Specify the source tree of a third-party utility.
161    UtilitySource(Box<deprecated::UtilitySource<'t>>),
162    /// Assert satisfaction of an option's required variables.
163    VariableRequires(Box<deprecated::VariableRequires<'t>>),
164    /// Write content into a file.
165    WriteFile(Box<deprecated::WriteFile<'t>>),
166    /// Evaluate a group of commands with a dedicated variable and/or policy scope.
167    Block(Box<scripting::Block<'t>>),
168    /// Break from an enclosing foreach or while loop.
169    Break(Box<scripting::Break>),
170    /// Query various host system information.
171    CMakeHostSystemInformation(Box<scripting::CMakeHostSystemInformation<'t>>),
172    /// Call meta-operations on CMake commands.
173    CMakeLanguage(Box<scripting::CMakeLanguage<'t>>),
174    /// Require a minimum version of cmake.
175    CMakeMinimumRequired(Box<scripting::CMakeMinimumRequired<'t>>),
176    /// Parse function or macro arguments.
177    CMakeParseArguments(Box<scripting::CMakeParseArguments<'t>>),
178    /// This command is for the manipulation of paths.
179    CMakePath(Box<scripting::CMakePath<'t>>),
180    /// Manage CMake Policy settings.
181    CMakePolicy(Box<scripting::CMakePolicy<'t>>),
182    /// Copy a file to another location and modify its contents.
183    ConfigureFile(Box<scripting::ConfigureFile<'t>>),
184    /// Continue to the top of enclosing foreach or while loop.
185    Continue(Box<scripting::Continue>),
186    /// Starts the else portion of an if block.
187    Else(Box<scripting::Else<'t>>),
188    /// Starts an elseif portion of an if block.
189    ElseIf(Box<scripting::ElseIf<'t>>),
190    /// Ends a list of commands in a block() and removes the scopes created by the block() command.
191    EndBlock(Box<scripting::EndBlock>),
192    /// Ends a list of commands in a foreach block.
193    EndForEach(Box<scripting::EndForEach<'t>>),
194    /// Ends a list of commands in a function block.
195    EndFunction(Box<scripting::EndFunction<'t>>),
196    /// Ends a list of commands in an if block.
197    EndIf(Box<scripting::EndIf<'t>>),
198    /// Ends a list of commands in a macro block.
199    EndMacro(Box<scripting::EndMacro<'t>>),
200    /// Ends a list of commands in a while block.
201    EndWhile(Box<scripting::EndWhile<'t>>),
202    /// Execute one or more child processes.
203    ExecuteProcess(Box<scripting::ExecuteProcess<'t>>),
204    /// File manipulation command.
205    File(Box<scripting::File<'t>>),
206    /// This command is used to find a full path to named file.
207    FindFile(Box<scripting::FindFile<'t>>),
208    /// This command is used to find a library.
209    FindLibrary(Box<scripting::FindLibrary<'t>>),
210    /// Find a package
211    FindPackage(Box<scripting::FindPackage<'t>>),
212    /// This command is used to find a directory containing the named file.
213    FindPath(Box<scripting::FindPath<'t>>),
214    /// This command is used to find a program.
215    FindProgram(Box<scripting::FindProgram<'t>>),
216    /// Evaluate a group of commands for each value in a list.
217    ForEach(Box<scripting::ForEach<'t>>),
218    /// Start recording a function for later invocation as a command.
219    Function(Box<scripting::Function<'t>>),
220    /// Get a global property of the CMake instance.
221    GetCMakeProperty(Box<scripting::GetCMakeProperty<'t>>),
222    /// Get a property of DIRECTORY scope.
223    GetDirectoryProperty(Box<scripting::GetDirectoryProperty<'t>>),
224    /// Get a specific component of a full filename.
225    GetFilenameComponent(Box<scripting::GetFilenameComponent<'t>>),
226    /// Get a property.
227    GetProperty(Box<scripting::GetProperty<'t>>),
228    /// Conditionally execute a group of commands.
229    If(Box<scripting::If<'t>>),
230    /// Load and run CMake code from a file or module.
231    Include(Box<scripting::Include<'t>>),
232    /// Provides an include guard for the file currently being processed by CMake.
233    IncludeGuard(Box<scripting::IncludeGuard>),
234    /// List operations.
235    List(Box<scripting::List<'t>>),
236    /// Start recording a macro for later invocation as a command
237    Macro(Box<scripting::Macro<'t>>),
238    /// Mark cmake cached variables as advanced.
239    MarkAsAdvanced(Box<scripting::MarkAsAdvanced<'t>>),
240    /// Evaluate a mathematical expression.
241    Math(Box<scripting::Math<'t>>),
242    /// Log a message.
243    Message(Box<scripting::Message<'t>>),
244    /// Provide a boolean option that the user can optionally select.
245    Option(Box<scripting::Option<'t>>),
246    /// Return from a file, directory or function.
247    Return(Box<scripting::Return<'t>>),
248    /// Parse command-line arguments into a semicolon-separated list.
249    SeparateArguments(Box<scripting::SeparateArguments<'t>>),
250    /// Set a normal, cache, or environment variable to a given value.
251    Set(Box<scripting::Set<'t>>),
252    /// Set properties of the current directory and subdirectories.
253    SetDirectoryProperties(Box<scripting::SetDirectoryProperties<'t>>),
254    /// Set a named property in a given scope.
255    SetProperty(Box<scripting::SetProperty<'t>>),
256    /// Set the given variable to the name of the computer.
257    SiteName(Box<scripting::SiteName<'t>>),
258    /// String operations.
259    String(Box<scripting::String<'t>>),
260    /// Unset a variable, cache variable, or environment variable.
261    Unset(Box<scripting::Unset<'t>>),
262    /// Watch the CMake variable for change.
263    VariableWatch(Box<scripting::VariableWatch<'t>>),
264    /// Evaluate a group of commands while a condition is true
265    While(Box<scripting::While<'t>>),
266}
267
268#[derive(Debug, thiserror::Error, PartialEq)]
269pub enum CommandParseError {
270    #[error("required token is missing: {0}")]
271    MissingToken(String),
272    #[error("unknown command: {0}")]
273    UnknownCommand(String),
274    #[error("unknown option: {0}")]
275    UnknownOption(String),
276    #[error("expected: {expected:?}, found: {found:?}")]
277    UnexpectedToken { expected: String, found: String },
278    #[error("token required")]
279    TokenRequired,
280    #[error("no tokens expected")]
281    NotEmpty,
282    #[error("flag option must have no arguments")]
283    NotFlag,
284    #[error("all arguments must be parsed")]
285    Incomplete,
286}