cmake_parser/doc/command/project/
get_source_file_property.rs1use cmake_parser_derive::CMake;
2
3use crate::{
4 doc::command_scope::{CommandScope, ToCommandScope},
5 Token,
6};
7
8#[derive(CMake, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
12#[cmake(pkg = "crate", positional)]
13pub struct GetSourceFileProperty<'t> {
14 pub variable: Token<'t>,
15 pub file: Token<'t>,
16 pub source: PropertySource<'t>,
17 pub property: Token<'t>,
18}
19
20#[derive(CMake, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
21#[cmake(pkg = "crate", transparent)]
22pub enum PropertySource<'t> {
23 Directory(Token<'t>),
24 TargetDirectory(Token<'t>),
25}
26
27impl<'t> ToCommandScope for GetSourceFileProperty<'t> {
28 fn to_command_scope(&self) -> CommandScope {
29 CommandScope::Project
30 }
31}
32
33#[cfg(test)]
34mod tests {
35 use super::*;
36 use crate::doc::cmake_parse::tests::{quoted_token, token};
37 use crate::*;
38 use pretty_assertions::assert_eq;
39
40 #[test]
41 fn get_source_file_property() {
42 let src =
43 include_bytes!("../../../../../fixture/commands/project/get_source_file_property");
44 let cmakelists = parse_cmakelists(src).unwrap();
45 let doc = Doc::from(cmakelists);
46 assert_eq!(
47 doc.commands().unwrap(),
48 &[Command::GetSourceFileProperty(Box::new(
49 GetSourceFileProperty {
50 variable: token(b"_generated"),
51 file: quoted_token(b"${_generated_candidate}"),
52 source: PropertySource::TargetDirectory(quoted_token(b"${target}")),
53 property: token(b"GENERATED"),
54 }
55 )),]
56 )
57 }
58}