Skip to content

Commit ad235b5

Browse files
authored
feat(cmake): add ixm_property command to the public runtime (#40)
This introduces `ixm_property`, a command that was originally implemented as `ixm_target_property` in #21. However, as that PR is broken apart and into separate pieces I've been re-evaluating how each component should be named or how it works. Not much has changed with this command's implementation however it's name required an update as only target properties can be used with this command anyhow. There are possibly more useful additions that can be added for the final generator expression that is generated, however I'm keeping it as simple as it can be for now given its use-cases. Signed-off-by: Izzy Muerte <63051+bruxisma@users.noreply.github.com>
1 parent 0f2a5d6 commit ad235b5

2 files changed

Lines changed: 76 additions & 0 deletions

File tree

docs/commands/common.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,51 @@ set is whatever is passed after the `variable` argument (i.e., [`ARGN`][argn]).
2121
### Required Parameters {#fallback/required}
2222

2323
`variable`
24+
: *Type*: `identifier`
2425
: Name of the variable to store values in.
26+
27+
## `ixm_property`
28+
29+
Creates a generator expression for reading from a target property, as well as
30+
ensuring that any resulting values from said generator expression are also
31+
evaluated. Supports both the `$<TARGET_PROPERTY:target,property>` format, as
32+
well as `$<TARGET_PROPERTY:property>`.
33+
34+
### Required Parameters {#property/required}
35+
36+
`property`
2537
: *Type*: `identifier`
38+
: Name of the property to create the generator expression for.
39+
40+
41+
### Keyword Parameters {#property/required}
42+
43+
`CONTEXT`
44+
: *Type*: `option`
45+
: Use `TARGET_GENEX_EVAL` instead of `GENEX_EVAL` for the generator expression.
46+
47+
`TARGET`
48+
: *Type*: `target`
49+
: Name of target or a generator expression that evaluates to a target name.
50+
51+
`OUTPUT_VARIABLE`
52+
: *Type*: `identifier`
53+
: *Default: `${property}`
54+
: Name of the variable to write the generator expression to.
55+
56+
`PREFIX`
57+
: *Type*: `identifier[]`
58+
: Any number of identifiers to prefix to the property. These are joined via the
59+
`_` character, and are most useful when the `OUTPUT_VARIABLE` argument isn't
60+
used and the user wishes to use the provided `property` instead.
61+
62+
### Example
63+
64+
```cmake
65+
ixm_property(IMPORTED_LOCATION TARGET ccache::ccache)
66+
set_property(TARGET ${PROJECT_NAME} PROPERTY
67+
CXX_COMPILER_LAUNCHER ${IMPORTED_LOCATION})
68+
```
2669

2770
## `ixm::unimplemented`
2871

runtime/common.cmake

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,36 @@ function (ixm_fallback variable)
7777
set(${variable} ${ARGN} PARENT_SCOPE)
7878
endif()
7979
endfunction()
80+
#[============================================================================[
81+
# @summary Creates a generator expression for reading from a target property.
82+
# @description This command permits creating generator expressions for targets
83+
# that are *not yet defined*, even if the `TARGET` parameter is passed in.
84+
#
85+
# @param {identifier} property - Name of the property to create generator
86+
# expression for.
87+
# @param {option} [CONTEXT] - Use `TARGET_GENEX_EVAL` instead of `GENEX_EVAL`.
88+
# Does nothing if `TARGET` has not been specified.
89+
# @param {target} [TARGET] - Name of a target to use for context and scope.
90+
# @param {identifier} [OUTPUT_VARIABLE=${property}] - Name of the variable to
91+
# output.
92+
# @param {list} [PREFIX] - Additional prefixes to prepend to the property.
93+
# These are joined via the `_` character. Useful if `OUTPUT_VARIABLE` is not
94+
# provided, as this allows for more complex property generator expressions with
95+
# simple output variables.
96+
#]============================================================================]
97+
function (ixm_property property)
98+
cmake_parse_arguments(PARSE_ARGV 1 ARG "CONTEXT" "TARGET;OUTPUT_VARIABLE" "PREFIX")
99+
ixm_fallback(ARG_OUTPUT_VARIABLE ${property})
100+
string(JOIN _ property ${ARG_PREFIX} ${property})
101+
102+
set(eval GENEX_EVAL:)
103+
set(target)
104+
if (ARG_TARGET)
105+
set(target "${ARG_TARGET},") # note the `,` at the end of the string
106+
if (ARG_CONTEXT)
107+
set(eval TARGET_GENEX_EVAL:${target})
108+
endif()
109+
endif()
110+
111+
set(${ARG_OUTPUT_VARIABLE} "$<${eval}$<TARGET_PROPERTY:${target}${property}>>" PARENT_SCOPE)
112+
endfunction()

0 commit comments

Comments
 (0)