Skip to content

Commit 718b726

Browse files
tejlmandfabiobaltieri
authored andcommitted
cmake: PROPERTY flag support on compile options and link libraries
Extend zephyr_link_libraries to allow an optional value together with the `zephyr_link_libraries(PROPERTY <property> [<value>])`. This allow setting linker property combined with a value when linking Zephyr. The value will only be applied if the property is defined. Extend zephyr_compile_options to support the same PROPERTY flag that has been introduced for zephyr_link_libraries(). This remove the need for developers to write complex generator expressions for compiler flags and thus minimizes mistakes. The following syntax is now supported in addition to the existing syntax: `zephyr_compile_options(PROPERTY <property> [<value>])` Signed-off-by: Torsten Rasmussen <[email protected]>
1 parent 2e3873a commit 718b726

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

cmake/modules/extensions.cmake

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,16 +108,37 @@ endfunction()
108108

109109
# https://cmake.org/cmake/help/latest/command/target_compile_options.html
110110
function(zephyr_compile_options)
111-
target_compile_options(zephyr_interface INTERFACE ${ARGV})
111+
if(ARGV0 STREQUAL "PROPERTY")
112+
set(property $<TARGET_PROPERTY:compiler,${ARGV1}>)
113+
set(property_defined $<BOOL:${property}>)
114+
if(ARGC GREATER 3)
115+
message(FATAL_ERROR "zephyr_compile_options(PROPERTY <prop> [<var>]) "
116+
"called with too many arguments."
117+
)
118+
elseif(ARGC EQUAL 3)
119+
target_compile_options(zephyr_interface INTERFACE $<${property_defined}:${property}${ARGV2}>)
120+
else()
121+
target_compile_options(zephyr_interface INTERFACE ${property})
122+
endif()
123+
else()
124+
target_compile_options(zephyr_interface INTERFACE ${ARGV})
125+
endif()
112126
endfunction()
113127

114128
# https://cmake.org/cmake/help/latest/command/target_link_libraries.html
115129
function(zephyr_link_libraries)
116130
if(ARGV0 STREQUAL "PROPERTY")
117-
if(ARGC GREATER 2)
118-
message(FATAL_ERROR "zephyr_link_libraries(PROPERTY <prop>) only allows a single property.")
131+
set(property $<TARGET_PROPERTY:linker,${ARGV1}>)
132+
set(property_defined $<BOOL:${property}>)
133+
if(ARGC GREATER 3)
134+
message(FATAL_ERROR "zephyr_link_options(PROPERTY <prop> [<val>]) "
135+
"called with too many arguments."
136+
)
137+
elseif(ARGC EQUAL 3)
138+
target_link_libraries(zephyr_interface INTERFACE $<${property_defined}:${property}${ARGV2}>)
139+
else()
140+
target_link_libraries(zephyr_interface INTERFACE ${property})
119141
endif()
120-
target_link_libraries(zephyr_interface INTERFACE $<TARGET_PROPERTY:linker,${ARGV1}>)
121142
else()
122143
target_link_libraries(zephyr_interface INTERFACE ${ARGV})
123144
endif()

0 commit comments

Comments
 (0)