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