cmake_parser/doc/command/deprecated/
subdirs.rs

1use cmake_parser_derive::CMake;
2
3use crate::{
4    doc::command_scope::{CommandScope, ToCommandScope},
5    Token,
6};
7
8/// Add a list of subdirectories to the build.
9///
10/// Reference: <https://cmake.org/cmake/help/v3.26/command/subdirs.html>
11#[derive(CMake, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
12#[cmake(pkg = "crate", default = "dirs")]
13pub struct Subdirs<'t> {
14    #[cmake(rename = "")]
15    pub dirs: Vec<Token<'t>>,
16    pub exclude_from_all: Option<Vec<Token<'t>>>,
17    pub preorder: bool,
18}
19
20impl<'t> ToCommandScope for Subdirs<'t> {
21    fn to_command_scope(&self) -> CommandScope {
22        CommandScope::Deprecated
23    }
24}
25
26#[cfg(test)]
27mod tests {
28    use super::*;
29    use crate::doc::cmake_parse::tests::tokens_vec;
30    use crate::*;
31    use pretty_assertions::assert_eq;
32
33    #[test]
34    fn subdirs() {
35        let src = include_bytes!("../../../../../fixture/commands/deprecated/subdirs");
36        let cmakelists = parse_cmakelists(src).unwrap();
37        let doc = Doc::from(cmakelists);
38        assert_eq!(
39            doc.commands(),
40            Ok(vec![Command::Subdirs(Box::new(Subdirs {
41                dirs: tokens_vec([b"dir1", b"dir2"]),
42                exclude_from_all: Some(tokens_vec([b"exclude_dir1", b"exclude_dir2"])),
43                preorder: true,
44            })),])
45        )
46    }
47}