cmake_parser/doc/command/project/
set_source_files_properties.rs

1use cmake_parser_derive::CMake;
2
3use crate::{
4    command::common::Property,
5    doc::command_scope::{CommandScope, ToCommandScope},
6    Token,
7};
8
9/// Sets properties associated with source files using a key/value paired list.
10///
11/// Reference: <https://cmake.org/cmake/help/v3.26/command/set_source_files_properties.html>
12#[derive(CMake, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
13#[cmake(pkg = "crate", default = "files")]
14pub struct SetSourceFileProperties<'t> {
15    #[cmake(rename = "")]
16    pub files: Vec<Token<'t>>,
17    #[cmake(rename = "DIRECTORY")]
18    pub directories: Option<Vec<Token<'t>>>,
19    #[cmake(rename = "TARGET_DIRECTORY")]
20    pub targets: Option<Vec<Token<'t>>>,
21    pub properties: Vec<Property<'t>>,
22}
23
24impl<'t> ToCommandScope for SetSourceFileProperties<'t> {
25    fn to_command_scope(&self) -> CommandScope {
26        CommandScope::Project
27    }
28}
29
30#[cfg(test)]
31mod tests {
32    use super::*;
33    use crate::doc::cmake_parse::tests::{quoted_token, token, tokens_vec};
34    use crate::*;
35    use pretty_assertions::assert_eq;
36
37    #[test]
38    fn set_source_files_properties() {
39        let src =
40            include_bytes!("../../../../../fixture/commands/project/set_source_files_properties");
41        let cmakelists = parse_cmakelists(src).unwrap();
42        let doc = Doc::from(cmakelists);
43        assert_eq!(
44            doc.commands(),
45            Ok(vec![
46                Command::SetSourceFileProperties(Box::new(SetSourceFileProperties {
47                    files: tokens_vec([b"a.cpp"]),
48                    directories: None,
49                    targets: None,
50                    properties: vec![Property {
51                        prop: token(b"COMPILE_DEFINITIONS"),
52                        value: quoted_token(b"DIR1=/home/x x/b.i;DIR2=/home/xxx/c.i"),
53                    }]
54                })),
55                Command::SetSourceFileProperties(Box::new(SetSourceFileProperties {
56                    files: tokens_vec([b"example.i", b"example.q"]),
57                    directories: Some(tokens_vec([b"qqq1", b"qqq2"])),
58                    targets: Some(tokens_vec([b"ddd1", b"ddd2"])),
59                    properties: vec![
60                        Property {
61                            prop: token(b"CPLUSPLUS"),
62                            value: token(b"ON"),
63                        },
64                        Property {
65                            prop: token(b"SWIG_FLAGS"),
66                            value: quoted_token(b"-includeall"),
67                        }
68                    ]
69                })),
70            ])
71        )
72    }
73}