cmake_parser/doc/command/project/
add_compile_definitions.rs

1use cmake_parser_derive::CMake;
2
3use crate::{
4    doc::command_scope::{CommandScope, ToCommandScope},
5    Token,
6};
7
8/// Add preprocessor definitions to the compilation of source files.
9///
10/// Reference: <https://cmake.org/cmake/help/v3.26/command/add_compile_definitions.html>
11#[derive(CMake, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
12#[cmake(pkg = "crate")]
13pub struct AddCompileDefinitions<'t> {
14    #[cmake(positional)]
15    pub compile_definitions: Vec<Token<'t>>,
16}
17
18impl<'t> ToCommandScope for AddCompileDefinitions<'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_definitions() {
32        let src = include_bytes!("../../../../../fixture/commands/project/add_compile_definitions");
33        let cmakelists = parse_cmakelists(src).unwrap();
34        let doc = Doc::from(cmakelists);
35        assert_eq!(
36            doc.commands().unwrap(),
37            &[Command::AddCompileDefinitions(Box::new(
38                AddCompileDefinitions {
39                    compile_definitions: tokens([b"DEBUG_UNPLUGGED"]).to_vec(),
40                }
41            ))]
42        )
43    }
44}