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 <Torsten.Rasmussen@nordicsemi.no>
This commit is contained in:
parent
2e3873adde
commit
718b726b37
1 changed files with 25 additions and 4 deletions
|
@ -108,16 +108,37 @@ endfunction()
|
|||
|
||||
# https://cmake.org/cmake/help/latest/command/target_compile_options.html
|
||||
function(zephyr_compile_options)
|
||||
if(ARGV0 STREQUAL "PROPERTY")
|
||||
set(property $<TARGET_PROPERTY:compiler,${ARGV1}>)
|
||||
set(property_defined $<BOOL:${property}>)
|
||||
if(ARGC GREATER 3)
|
||||
message(FATAL_ERROR "zephyr_compile_options(PROPERTY <prop> [<var>]) "
|
||||
"called with too many arguments."
|
||||
)
|
||||
elseif(ARGC EQUAL 3)
|
||||
target_compile_options(zephyr_interface INTERFACE $<${property_defined}:${property}${ARGV2}>)
|
||||
else()
|
||||
target_compile_options(zephyr_interface INTERFACE ${property})
|
||||
endif()
|
||||
else()
|
||||
target_compile_options(zephyr_interface INTERFACE ${ARGV})
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
# https://cmake.org/cmake/help/latest/command/target_link_libraries.html
|
||||
function(zephyr_link_libraries)
|
||||
if(ARGV0 STREQUAL "PROPERTY")
|
||||
if(ARGC GREATER 2)
|
||||
message(FATAL_ERROR "zephyr_link_libraries(PROPERTY <prop>) only allows a single property.")
|
||||
set(property $<TARGET_PROPERTY:linker,${ARGV1}>)
|
||||
set(property_defined $<BOOL:${property}>)
|
||||
if(ARGC GREATER 3)
|
||||
message(FATAL_ERROR "zephyr_link_options(PROPERTY <prop> [<val>]) "
|
||||
"called with too many arguments."
|
||||
)
|
||||
elseif(ARGC EQUAL 3)
|
||||
target_link_libraries(zephyr_interface INTERFACE $<${property_defined}:${property}${ARGV2}>)
|
||||
else()
|
||||
target_link_libraries(zephyr_interface INTERFACE ${property})
|
||||
endif()
|
||||
target_link_libraries(zephyr_interface INTERFACE $<TARGET_PROPERTY:linker,${ARGV1}>)
|
||||
else()
|
||||
target_link_libraries(zephyr_interface INTERFACE ${ARGV})
|
||||
endif()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue