diff --git a/cmake/nuttx_add_library.cmake b/cmake/nuttx_add_library.cmake index 8eede604ef44b..fc97281d9fff3 100644 --- a/cmake/nuttx_add_library.cmake +++ b/cmake/nuttx_add_library.cmake @@ -201,11 +201,13 @@ function(nuttx_add_extra_library) # define the target name of the extra library string(REGEX REPLACE "[^a-zA-Z0-9]" "_" extra_target "${extra_lib}") # set the absolute path of the library for the import target - nuttx_library_import(${extra_target} ${extra_lib}) - set_property(GLOBAL APPEND PROPERTY NUTTX_EXTRA_LIBRARIES ${extra_target}) - if(CONFIG_BUILD_PROTECTED) - set_property(GLOBAL APPEND PROPERTY NUTTX_USER_EXTRA_LIBRARIES - ${extra_target}) + if(NOT TARGET ${extra_target}) + nuttx_library_import(${extra_target} ${extra_lib}) + set_property(GLOBAL APPEND PROPERTY NUTTX_EXTRA_LIBRARIES ${extra_target}) + if(CONFIG_BUILD_PROTECTED) + set_property(GLOBAL APPEND PROPERTY NUTTX_USER_EXTRA_LIBRARIES + ${extra_target}) + endif() endif() endforeach() endfunction()