cmake_parser/doc/command/project/
add_compile_options.rs

1use cmake_parser_derive::CMake;
2
3use crate::{
4    doc::command_scope::{CommandScope, ToCommandScope},
5    Token,
6};
7
8/// Adds options to the compilation of source files.
9///
10/// Reference: <https://cmake.org/cmake/help/v3.26/command/add_compile_options.html>
11#[derive(CMake, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
12#[cmake(pkg = "crate")]
13pub struct AddCompileOptions<'t> {
14    #[cmake(positional)]
15    pub compile_options: Vec<Token<'t>>,
16}
17
18impl<'t> ToCommandScope for AddCompileOptions<'t> {
19    fn to_command_scope(&self) -> CommandScope {
20        CommandScope::Project
21    }
22}
23
24#[cfg(test)]
25mod tests {
26    use super::*;
27    use crate::doc::cmake_parse::tests::tokens;
28    use crate::*;
29
30    #[test]
31    fn add_compile_options() {
32        let src = include_bytes!("../../../../../fixture/commands/project/add_compile_options");
33        let cmakelists = parse_cmakelists(src).unwrap();
34        let doc = Doc::from(cmakelists);
35        assert_eq!(
36            doc.commands().unwrap(),
37            &[Command::AddCompileOptions(Box::new(AddCompileOptions {
38                compile_options: tokens([b"-foo", b"-bar",]).to_vec()
39            }))]
40        )
41    }
42}