Skip to content

Commit a5ad4e8

Browse files
tejlmandcarlescufi
authored andcommitted
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 <[email protected]>
1 parent 574e166 commit a5ad4e8

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

cmake/modules/extensions.cmake

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -500,14 +500,12 @@ function(zephyr_library_compile_options item)
500500
string(MD5 uniqueness ${item})
501501
set(lib_name options_interface_lib_${uniqueness})
502502

503-
if (TARGET ${lib_name})
504-
# ${item} already added, ignoring duplicate just like CMake does
505-
return()
503+
if (NOT TARGET ${lib_name})
504+
# Create the unique target only if it doesn't exist.
505+
add_library( ${lib_name} INTERFACE)
506+
target_compile_options(${lib_name} INTERFACE ${item} ${ARGN})
506507
endif()
507508

508-
add_library( ${lib_name} INTERFACE)
509-
target_compile_options(${lib_name} INTERFACE ${item} ${ARGN})
510-
511509
target_link_libraries(${ZEPHYR_CURRENT_LIBRARY} PRIVATE ${lib_name})
512510
endfunction()
513511

0 commit comments

Comments
 (0)