1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use cmake_parser_derive::CMake;

use crate::{
    doc::command_scope::{CommandScope, ToCommandScope},
    Token,
};

/// Adds options to the compilation of source files.
///
/// Reference: <https://cmake.org/cmake/help/v3.26/command/add_compile_options.html>
#[derive(CMake, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cmake(pkg = "crate")]
pub struct AddCompileOptions<'t> {
    #[cmake(positional)]
    pub compile_options: Vec<Token<'t>>,
}

impl<'t> ToCommandScope for AddCompileOptions<'t> {
    fn to_command_scope(&self) -> CommandScope {
        CommandScope::Project
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::doc::cmake_parse::tests::tokens;
    use crate::*;

    #[test]
    fn add_compile_options() {
        let src = include_bytes!("../../../../../fixture/commands/project/add_compile_options");
        let cmakelists = parse_cmakelists(src).unwrap();
        let doc = Doc::from(cmakelists);
        assert_eq!(
            doc.commands().unwrap(),
            &[Command::AddCompileOptions(Box::new(AddCompileOptions {
                compile_options: tokens([b"-foo", b"-bar",]).to_vec()
            }))]
        )
    }
}