diff --git a/CMakeLists.txt b/CMakeLists.txt index d354d008179..390d12fbd90 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -351,7 +351,7 @@ if(NOT CONFIG_NATIVE_BUILD) toolchain_ld_baremetal() endif() -if(CONFIG_CPP AND NOT CONFIG_MINIMAL_LIBCPP) +if(CONFIG_CPP AND NOT CONFIG_MINIMAL_LIBCPP AND NOT CONFIG_NATIVE_LIBRARY) # @Intent: Set linker specific flags for C++ toolchain_ld_cpp() endif() @@ -394,7 +394,12 @@ zephyr_compile_options($<$:$:$>) zephyr_compile_options($<$:$>) -zephyr_link_libraries($) + +# In case of CONFIG_NATIVE_LIBRARY we also don't want position independent code, +# but we cannot tell that to the linker yet as we are first only doing a +# relocatable link into a static library +zephyr_link_libraries_ifndef(CONFIG_NATIVE_LIBRARY + $) # Allow the user to inject options when calling cmake, e.g. # 'cmake -DEXTRA_CFLAGS="-Werror -Wno-deprecated-declarations" ..' @@ -1209,6 +1214,8 @@ if(CONFIG_USERSPACE OR CONFIG_DEVICE_DEPS) LIBRARIES_POST_SCRIPT "" DEPENDENCIES ${CODE_RELOCATION_DEP} ) + target_link_libraries_ifdef(CONFIG_NATIVE_LIBRARY ${ZEPHYR_LINK_STAGE_EXECUTABLE} + $) target_byproducts(TARGET ${ZEPHYR_LINK_STAGE_EXECUTABLE} BYPRODUCTS ${PROJECT_BINARY_DIR}/${ZEPHYR_LINK_STAGE_EXECUTABLE}.map ) @@ -1426,6 +1433,8 @@ toolchain_ld_link_elf( LINKER_SCRIPT ${PROJECT_BINARY_DIR}/${ZEPHYR_CURRENT_LINKER_CMD} DEPENDENCIES ${CODE_RELOCATION_DEP} ) +target_link_libraries_ifdef(CONFIG_NATIVE_LIBRARY ${ZEPHYR_LINK_STAGE_EXECUTABLE} + $) target_byproducts(TARGET ${ZEPHYR_LINK_STAGE_EXECUTABLE} BYPRODUCTS ${PROJECT_BINARY_DIR}/${ZEPHYR_LINK_STAGE_EXECUTABLE}.map )