cmake: source dedicated linker library properties for native builds
Native builds uses system libraries per default. Instead of handling this in each linker_libraries.cmake files, then the check for native build is moved one level up and for native build a dedicated linker_libraries_native.cmake is sourced. This simplifies the linker_libraries.cmake files as they no longer need to check for native builds. Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
This commit is contained in:
parent
d2896df821
commit
cc488787ea
4 changed files with 36 additions and 15 deletions
|
@ -2,21 +2,17 @@
|
|||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
# Do not specify default link libraries when targeting host (native build).
|
||||
if(NOT CONFIG_NATIVE_BUILD)
|
||||
set_linker_property(NO_CREATE PROPERTY c_library "-lc")
|
||||
set_linker_property(NO_CREATE PROPERTY rt_library "-lgcc")
|
||||
set_linker_property(NO_CREATE PROPERTY c++_library "-lstdc++")
|
||||
set_linker_property(NO_CREATE PROPERTY math_library "-lm")
|
||||
# Keeping default include dir empty. The linker will then select libraries
|
||||
# from its default search path. The toolchain may adjust the value to a
|
||||
# specific location, for example gcc infrastructure will set the value based
|
||||
# on output from --print-libgcc-file-name.
|
||||
set_linker_property(NO_CREATE PROPERTY lib_include_dir "")
|
||||
endif()
|
||||
set_linker_property(NO_CREATE PROPERTY c_library "-lc")
|
||||
set_linker_property(NO_CREATE PROPERTY rt_library "-lgcc")
|
||||
set_linker_property(NO_CREATE PROPERTY c++_library "-lstdc++")
|
||||
set_linker_property(NO_CREATE PROPERTY math_library "-lm")
|
||||
# Keeping default include dir empty. The linker will then select libraries
|
||||
# from its default search path. The toolchain may adjust the value to a
|
||||
# specific location, for example gcc infrastructure will set the value based
|
||||
# on output from --print-libgcc-file-name.
|
||||
set_linker_property(NO_CREATE PROPERTY lib_include_dir "")
|
||||
|
||||
if(CONFIG_CPP
|
||||
AND NOT CONFIG_NATIVE_LIBRARY
|
||||
# When new link principle is fully introduced, then the below condition can
|
||||
# be removed, and instead the external module c++ should use:
|
||||
# set_property(TARGET linker PROPERTY c++_library "<external_c++_lib>")
|
||||
|
|
21
cmake/linker/linker_libraries_native.cmake
Normal file
21
cmake/linker/linker_libraries_native.cmake
Normal file
|
@ -0,0 +1,21 @@
|
|||
# Copyright (c) 2024 Nordic Semiconductor
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
# When doing native builds, then we default to host libraries.
|
||||
# No reason for loading linker libraries properties in this case, however we do
|
||||
# define link order because that allows the build system to hook in alternative
|
||||
# C library implementations, such as minimal libc or picolibc.
|
||||
|
||||
# Empty on purpose as we default to host libraries selected by the linker.
|
||||
set_linker_property(PROPERTY c_library "")
|
||||
set_linker_property(PROPERTY rt_library "")
|
||||
set_linker_property(PROPERTY c++_library "")
|
||||
|
||||
# Although library properties are empty per default, then we still define link
|
||||
# order as this allows to update libraries in use elsewhere.
|
||||
if(CONFIG_CPP)
|
||||
set_property(TARGET linker PROPERTY link_order_library "c++")
|
||||
endif()
|
||||
|
||||
set_property(TARGET linker APPEND PROPERTY link_order_library "c;rt")
|
|
@ -8,7 +8,6 @@ set_linker_property(NO_CREATE TARGET linker PROPERTY rt_library "")
|
|||
set_linker_property(TARGET linker PROPERTY c++_library "-lc++;-lc++abi")
|
||||
|
||||
if(CONFIG_CPP
|
||||
AND NOT CONFIG_NATIVE_LIBRARY
|
||||
# When new link principle is fully introduced, then the below condition can
|
||||
# be removed, and instead the external module c++ should use:
|
||||
# set_property(TARGET linker PROPERTY c++_library "<external_c++_lib>")
|
||||
|
|
|
@ -41,4 +41,9 @@ include(${CMAKE_CURRENT_LIST_DIR}/linker/linker_libraries_template.cmake)
|
|||
# (gcc, host-gcc etc.)
|
||||
include(${TOOLCHAIN_ROOT}/cmake/compiler/${COMPILER}/compiler_flags.cmake OPTIONAL)
|
||||
include(${TOOLCHAIN_ROOT}/cmake/linker/${LINKER}/linker_flags.cmake OPTIONAL)
|
||||
include(${TOOLCHAIN_ROOT}/cmake/linker/${LINKER}/linker_libraries.cmake OPTIONAL)
|
||||
|
||||
if(CONFIG_NATIVE_LIBRARY)
|
||||
include(${TOOLCHAIN_ROOT}/cmake/linker/linker_libraries_native.cmake)
|
||||
else()
|
||||
include(${TOOLCHAIN_ROOT}/cmake/linker/${LINKER}/linker_libraries.cmake OPTIONAL)
|
||||
endif()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue