Skip to content

Commit 4635343

Browse files
marc-hbnashif
authored andcommitted
zephyr_library_compile_options(): silently de-duplicate
PR #14776 / commit 915a353 changed function zephyr_library_compile_options() to use MD5 instead of RANDOM for build reproduction reasons. As later predicted by Sebastian Bøe in the PR (thx), the names generated for these pseudo-libraries won't be unique anymore if the exact same flag gets added more than once. To reproduce the issue, simply add the following two lines in some CMakeLists.txt file like samples/hello_world/CMakeLists.txt: zephyr_library_compile_options("-Dfubar=barfu") zephyr_library_compile_options("-Dfubar=barfu") cmake will then fail like this: CMake Error at zephyr/cmake/extensions.cmake:403 (add_library): add_library cannot create target "options_interface_lib_e689fdb7eb15d801c2f95dd61301fc5e" because another target with the same name already exists. The existing target is an interface library created in source directory "zephyr/samples/hello_world". See documentation for policy CMP0002 for more details. Call Stack (most recent call first): CMakeLists.txt:9 (zephyr_library_compile_options) As requested by Sebastian, silently discard duplicate options just like CMake does. Fixes #15093 Signed-off-by: Marc Herbert <[email protected]>
1 parent bd10c72 commit 4635343

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

cmake/extensions.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,11 @@ function(zephyr_library_compile_options item)
400400
string(MD5 uniqueness ${item})
401401
set(lib_name options_interface_lib_${uniqueness})
402402

403+
if (TARGET ${lib_name})
404+
# ${item} already added, ignoring duplicate just like CMake does
405+
return()
406+
endif()
407+
403408
add_library( ${lib_name} INTERFACE)
404409
target_compile_options(${lib_name} INTERFACE ${item} ${ARGN})
405410

0 commit comments

Comments
 (0)