cmake_parser/doc/command/project/
add_link_options.rs

1use cmake_parser_derive::CMake;
2
3use crate::{
4    doc::command_scope::{CommandScope, ToCommandScope},
5    Token,
6};
7
8/// Add options to the link step for executable, shared library or module library targets in the current directory and below that are added after this command is invoked.
9///
10/// Reference: <https://cmake.org/cmake/help/v3.26/command/add_link_options.html>
11#[derive(CMake, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
12#[cmake(pkg = "crate")]
13pub struct AddLinkOptions<'t> {
14    #[cmake(positional)]
15    pub link_options: Vec<Token<'t>>,
16}
17
18impl<'t> ToCommandScope for AddLinkOptions<'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::quoted_tokens;
28    use crate::*;
29
30    #[test]
31    fn add_link_options() {
32        let src = include_bytes!("../../../../../fixture/commands/project/add_link_options");
33        let cmakelists = parse_cmakelists(src).unwrap();
34        let doc = Doc::from(cmakelists);
35        assert_eq!(
36            doc.commands().unwrap(),
37            &[
38                Command::AddLinkOptions(Box::new(AddLinkOptions {
39                    link_options: quoted_tokens([b"SHELL: --bind"]).to_vec(),
40                })),
41                Command::AddLinkOptions(Box::new(AddLinkOptions {
42                    link_options: quoted_tokens([b"SHELL: -s MODULARIZE=1"]).to_vec(),
43                }))
44            ]
45        )
46    }
47}