Skip to content

Commit c0f4060

Browse files
tejlmandjukkar
authored andcommitted
[nrf fromtree] 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]> (cherry picked from commit 718b726) (cherry picked from commit f819df8)
1 parent 20528f7 commit c0f4060

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
@@ -109,16 +109,37 @@ endfunction()
109109

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

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

0 commit comments

Comments
 (0)