diff --git a/CMakeLists.txt b/CMakeLists.txt index 15671fc8ad3..3e3fd205a8a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -484,30 +484,6 @@ if(CONFIG_USERSPACE) set(KOBJECT_LINKER_DEP kobject_linker) endif() -get_property(TOPT GLOBAL PROPERTY TOPT) -get_property(COMPILER_TOPT TARGET compiler PROPERTY linker_script) -set_ifndef( TOPT "${COMPILER_TOPT}") -set_ifndef( TOPT -Wl,-T) # Use this if the compiler driver doesn't set a value - -if(CONFIG_HAVE_CUSTOM_LINKER_SCRIPT) - set(LINKER_SCRIPT ${APPLICATION_SOURCE_DIR}/${CONFIG_CUSTOM_LINKER_SCRIPT}) - if(NOT EXISTS ${LINKER_SCRIPT}) - set(LINKER_SCRIPT ${CONFIG_CUSTOM_LINKER_SCRIPT}) - assert_exists(CONFIG_CUSTOM_LINKER_SCRIPT) - endif() -else() - # Try a board specific linker file - set(LINKER_SCRIPT ${BOARD_DIR}/linker.ld) - if(NOT EXISTS ${LINKER_SCRIPT}) - # If not available, try an SoC specific linker file - set(LINKER_SCRIPT ${SOC_DIR}/${ARCH}/${SOC_PATH}/linker.ld) - endif() -endif() - -if(NOT EXISTS ${LINKER_SCRIPT}) - message(FATAL_ERROR "Could not find linker script: '${LINKER_SCRIPT}'. Corrupted configuration?") -endif() - if(DEFINED BUILD_VERSION) set(build_version_argument "-DBUILD_VERSION=${BUILD_VERSION}") elseif(NOT ZEPHYR_GIT_INDEX) @@ -976,6 +952,29 @@ set(CMAKE_C_COMPILE_FEATURES ${compile_features_${CSTD}} PARENT_SCOPE) # @Intent: Configure linker scripts, i.e. generate linker scripts with variables substituted toolchain_ld_configure_files() +get_property(TOPT GLOBAL PROPERTY TOPT) +get_property(COMPILER_TOPT TARGET compiler PROPERTY linker_script) +set_ifndef( TOPT "${COMPILER_TOPT}") +set_ifndef( TOPT -Wl,-T) # Use this if the compiler driver doesn't set a value + +if(CONFIG_HAVE_CUSTOM_LINKER_SCRIPT) + set(LINKER_SCRIPT ${APPLICATION_SOURCE_DIR}/${CONFIG_CUSTOM_LINKER_SCRIPT}) + if(NOT EXISTS ${LINKER_SCRIPT}) + set(LINKER_SCRIPT ${CONFIG_CUSTOM_LINKER_SCRIPT}) + assert_exists(CONFIG_CUSTOM_LINKER_SCRIPT) + endif() +elseif(DEFINED BOARD_LINKER_SCRIPT) + set(LINKER_SCRIPT ${BOARD_LINKER_SCRIPT}) +elseif(DEFINED SOC_LINKER_SCRIPT) + set(LINKER_SCRIPT ${SOC_LINKER_SCRIPT}) +else() + find_package(Deprecated COMPONENTS SEARCHED_LINKER_SCRIPT) +endif() + +if(NOT EXISTS ${LINKER_SCRIPT}) + message(FATAL_ERROR "Could not find linker script: '${LINKER_SCRIPT}'. Corrupted configuration?") +endif() + if(CONFIG_USERSPACE) set(APP_SMEM_ALIGNED_LD "${PROJECT_BINARY_DIR}/include/generated/app_smem_aligned.ld") set(APP_SMEM_UNALIGNED_LD "${PROJECT_BINARY_DIR}/include/generated/app_smem_unaligned.ld") diff --git a/cmake/linker/ld/target.cmake b/cmake/linker/ld/target.cmake index 507188540b7..baf76d2fed5 100644 --- a/cmake/linker/ld/target.cmake +++ b/cmake/linker/ld/target.cmake @@ -57,6 +57,7 @@ macro(configure_linker_script linker_script_gen linker_pass_define) zephyr_get_include_directories_for_lang(C current_includes) get_property(current_defines GLOBAL PROPERTY PROPERTY_LINKER_SCRIPT_DEFINES) + cmake_path(GET SOC_LINKER_SCRIPT PARENT_PATH soc_linker_script_includes) add_custom_command( OUTPUT ${linker_script_gen} @@ -74,6 +75,7 @@ macro(configure_linker_script linker_script_gen linker_pass_define) -D_ASMLANGUAGE -imacros ${AUTOCONF_H} ${current_includes} + -I${soc_linker_script_includes} ${current_defines} ${template_script_defines} -E ${LINKER_SCRIPT} diff --git a/cmake/modules/FindDeprecated.cmake b/cmake/modules/FindDeprecated.cmake index ae9b292af09..66cac2a5583 100644 --- a/cmake/modules/FindDeprecated.cmake +++ b/cmake/modules/FindDeprecated.cmake @@ -131,5 +131,23 @@ if(NOT "${Deprecated_FIND_COMPONENTS}" STREQUAL "") "${Deprecated_FIND_COMPONENTS}") endif() +if("SEARCHED_LINKER_SCRIPT" IN_LIST Deprecated_FIND_COMPONENTS) + # This code was deprecated after Zephyr v3.5.0 + list(REMOVE_ITEM Deprecated_FIND_COMPONENTS SEARCHED_LINKER_SCRIPT) + + # Try a board specific linker file + set(LINKER_SCRIPT ${BOARD_DIR}/linker.ld) + if(NOT EXISTS ${LINKER_SCRIPT}) + # If not available, try an SoC specific linker file + set(LINKER_SCRIPT ${SOC_DIR}/${ARCH}/${SOC_PATH}/linker.ld) + endif() + message(DEPRECATION + "Pre-defined `linker.ld` script is deprecated. Please set " + "BOARD_LINKER_SCRIPT or SOC_LINKER_SCRIPT to point to ${LINKER_SCRIPT} " + "or one of the Zephyr provided common linker scripts for the ${ARCH} " + "architecture." + ) +endif() + set(Deprecated_FOUND True) set(DEPRECATED_FOUND True)