cmake: reuse interface lib for compile options if it already exists

Fixes: #43835

In zephyr_library_compile_options() the existence of the compile
options interface library is checked and function returns if it already
exists. This results in #43835 meaning two libraries cannot add the
same option.

This commit fixes this by re-using the already created unique interface
library and link this to the Zephyr library.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
This commit is contained in:
Torsten Rasmussen 2022-03-17 11:08:40 +01:00 committed by Carles Cufí
commit a5ad4e8a56

View file

@ -500,14 +500,12 @@ function(zephyr_library_compile_options item)
string(MD5 uniqueness ${item}) string(MD5 uniqueness ${item})
set(lib_name options_interface_lib_${uniqueness}) set(lib_name options_interface_lib_${uniqueness})
if (TARGET ${lib_name}) if (NOT TARGET ${lib_name})
# ${item} already added, ignoring duplicate just like CMake does # Create the unique target only if it doesn't exist.
return() add_library( ${lib_name} INTERFACE)
target_compile_options(${lib_name} INTERFACE ${item} ${ARGN})
endif() endif()
add_library( ${lib_name} INTERFACE)
target_compile_options(${lib_name} INTERFACE ${item} ${ARGN})
target_link_libraries(${ZEPHYR_CURRENT_LIBRARY} PRIVATE ${lib_name}) target_link_libraries(${ZEPHYR_CURRENT_LIBRARY} PRIVATE ${lib_name})
endfunction() endfunction()