diff --git a/CMakeLists.txt b/CMakeLists.txt index 5d2d39470d..63455d5583 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -640,14 +640,15 @@ if(CONFIG_BUILD_FLAT) get_property(nuttx_apps_libs GLOBAL PROPERTY NUTTX_APPS_LIBRARIES) endif() -set(nuttx_libs ${nuttx_kernel_libs} ${nuttx_system_libs} ${nuttx_apps_libs}) +set(nuttx_libs ${nuttx_kernel_libs} ${nuttx_system_libs} ${nuttx_apps_libs} + ${nuttx_extra_libs}) if(NOT CONFIG_ARCH_SIM) # TODO: nostart/nodefault not applicable to nuttx toolchain target_link_libraries( nuttx PRIVATE ${NUTTX_EXTRA_FLAGS} -T${ldscript} -Wl,--start-group - ${nuttx_libs} ${nuttx_extra_libs} -Wl,--end-group) + ${nuttx_libs} -Wl,--end-group) # generate binary outputs in different formats (.bin, .hex, etc) nuttx_generate_outputs(nuttx) @@ -680,8 +681,8 @@ elseif(WIN32) add_custom_command( OUTPUT ${CMAKE_BINARY_DIR}/nuttx_all.lib COMMAND ${CMAKE_AR} /OUT:${CMAKE_BINARY_DIR}/nuttx_all.lib - ${nuttx_libs_paths} ${nuttx_extra_libs} - DEPENDS ${nuttx_libs} ${nuttx_extra_libs} + ${nuttx_libs_paths} + DEPENDS ${nuttx_libs} VERBATIM) add_custom_target(nuttx_all-lib DEPENDS ${CMAKE_BINARY_DIR}/nuttx_all.lib) add_dependencies(nuttx nuttx_all-lib) @@ -713,9 +714,9 @@ else() COMMAND ${CMAKE_LINKER} ARGS -r $<$:-m32> $ $<$>:-Wl,--start-group> - ${nuttx_libs_paths} ${nuttx_extra_libs} - $<$>:-Wl,--end-group> -o nuttx.rel - DEPENDS ${nuttx_libs} ${nuttx_extra_libs} sim_head + ${nuttx_libs_paths} $<$>:-Wl,--end-group> -o + nuttx.rel + DEPENDS ${nuttx_libs} sim_head COMMAND_EXPAND_LISTS) else() add_custom_command( @@ -723,10 +724,10 @@ else() COMMAND ${CMAKE_C_COMPILER} ARGS -r $<$:-m32> $ $<$>:-Wl,--start-group> - ${nuttx_libs_paths} ${nuttx_extra_libs} - $<$>:-Wl,--end-group> -o nuttx.rel + ${nuttx_libs_paths} $<$>:-Wl,--end-group> -o + nuttx.rel COMMAND ${CMAKE_OBJCOPY} --redefine-syms=nuttx-names.dat nuttx.rel - DEPENDS ${nuttx_libs} ${nuttx_extra_libs} sim_head sim_redefine_symbols + DEPENDS ${nuttx_libs} sim_head sim_redefine_symbols COMMAND_EXPAND_LISTS) endif() add_custom_target(nuttx-rel DEPENDS nuttx.rel diff --git a/arch/arm/src/cmake/platform.cmake b/arch/arm/src/cmake/platform.cmake index 76a5898dd2..5d6287cfc1 100644 --- a/arch/arm/src/cmake/platform.cmake +++ b/arch/arm/src/cmake/platform.cmake @@ -87,12 +87,7 @@ if(NOT EXISTS ${extra_library} AND CONFIG_ARCH_TOOLCHAIN_CLANG) OUTPUT_VARIABLE extra_library) endif() -if(CMAKE_HOST_SYSTEM_NAME MATCHES "MSYS|CYGWIN|Windows") - cmake_path(GET extra_library FILENAME extra_filename_library) - list(APPEND EXTRA_LIB -l:${extra_filename_library}) -else() - list(APPEND EXTRA_LIB ${extra_library}) -endif() +list(APPEND EXTRA_LIB ${extra_library}) if(NOT CONFIG_LIBM) execute_process( @@ -101,12 +96,7 @@ if(NOT CONFIG_LIBM) OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE extra_library) - if(CMAKE_HOST_SYSTEM_NAME MATCHES "MSYS|CYGWIN|Windows") - cmake_path(GET extra_library FILENAME extra_filename_library) - list(APPEND EXTRA_LIB -l:${extra_filename_library}) - else() - list(APPEND EXTRA_LIB ${extra_library}) - endif() + list(APPEND EXTRA_LIB ${extra_library}) endif() if(CONFIG_LIBSUPCXX) @@ -115,12 +105,7 @@ if(CONFIG_LIBSUPCXX) --print-file-name=libsupc++.a OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE extra_library) - if(CMAKE_HOST_SYSTEM_NAME MATCHES "MSYS|CYGWIN|Windows") - cmake_path(GET extra_library FILENAME extra_filename_library) - list(APPEND EXTRA_LIB -l:${extra_filename_library}) - else() - list(APPEND EXTRA_LIB ${extra_library}) - endif() + list(APPEND EXTRA_LIB ${extra_library}) endif() if(CONFIG_ARCH_COVERAGE) @@ -129,12 +114,7 @@ if(CONFIG_ARCH_COVERAGE) --print-file-name=libgcov.a OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE extra_library) - if(CMAKE_HOST_SYSTEM_NAME MATCHES "MSYS|CYGWIN|Windows") - cmake_path(GET extra_library FILENAME extra_filename_library) - list(APPEND EXTRA_LIB -l:${extra_filename_library}) - else() - list(APPEND EXTRA_LIB ${extra_library}) - endif() + list(APPEND EXTRA_LIB ${extra_library}) endif() nuttx_add_extra_library(${EXTRA_LIB}) diff --git a/cmake/nuttx_add_library.cmake b/cmake/nuttx_add_library.cmake index 71b57c97aa..166b3a5cf1 100644 --- a/cmake/nuttx_add_library.cmake +++ b/cmake/nuttx_add_library.cmake @@ -191,11 +191,18 @@ endfunction() # # nuttx_add_extra_library # -# Add extra library to extra attribute +# Add extra library to extra attribute, extra library will be treated as an +# import target and have a complete full path this will be used to avoid adding +# the -l prefix to the link target between different cmake versions and +# platformss # function(nuttx_add_extra_library) - foreach(target ${ARGN}) - set_property(GLOBAL APPEND PROPERTY NUTTX_EXTRA_LIBRARIES ${target}) + foreach(extra_lib ${ARGN}) + # 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}) endforeach() endfunction()