cmake_parser/doc/command/project/
target_compile_features.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")]
13pub struct TargetCompileFeatures<'t> {
14 #[cmake(positional)]
15 pub target: Token<'t>,
16 pub features: Vec<Feature<'t>>,
17}
18
19impl<'t> ToCommandScope for TargetCompileFeatures<'t> {
20 fn to_command_scope(&self) -> CommandScope {
21 CommandScope::Project
22 }
23}
24
25#[derive(CMake, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
26#[cmake(pkg = "crate", transparent)]
27pub enum Feature<'t> {
28 Interface(Vec<Token<'t>>),
29 Public(Vec<Token<'t>>),
30 Private(Vec<Token<'t>>),
31}
32
33#[cfg(test)]
34mod tests {
35 use super::*;
36 use crate::doc::cmake_parse::tests::{token, tokens_vec};
37 use crate::*;
38 use pretty_assertions::assert_eq;
39
40 #[test]
41 fn target_compile_features() {
42 let src = include_bytes!("../../../../../fixture/commands/project/target_compile_features");
43 let cmakelists = parse_cmakelists(src).unwrap();
44 let doc = Doc::from(cmakelists);
45 assert_eq!(
46 doc.commands(),
47 Ok(vec![
48 Command::TargetCompileFeatures(Box::new(TargetCompileFeatures {
49 target: token(b"LibXml2"),
50 features: vec![Feature::Private(tokens_vec([
51 b"SYSCONFDIR=\"${CMAKE_INSTALL_FULL_SYSCONFDIR}\""
52 ]))]
53 })),
54 Command::TargetCompileFeatures(Box::new(TargetCompileFeatures {
55 target: token(b"LibXml2"),
56 features: vec![
57 Feature::Interface(tokens_vec([b"LIBXML_STATIC"])),
58 Feature::Private(tokens_vec([b"qqq", b"bbb"]))
59 ]
60 })),
61 ])
62 )
63 }
64}