1# SPDX-License-Identifier: Apache-2.0 2# 3# Copyright (c) 2022, Nordic Semiconductor ASA 4 5# FindDeprecated module provides a single location for deprecated CMake build code. 6# Whenever CMake code is deprecated it should be moved to this module and 7# corresponding COMPONENTS should be created with name identifying the deprecated code. 8# 9# This makes it easier to maintain deprecated code and cleanup such code when it 10# has been deprecated for two releases. 11# 12# Example: 13# CMakeList.txt contains deprecated code, like: 14# if(DEPRECATED_VAR) 15# deprecated() 16# endif() 17# 18# such code can easily be around for a long time, so therefore such code should 19# be moved to this module and can then be loaded as: 20# FindDeprecated.cmake 21# if(<deprecated_name> IN_LIST Deprecated_FIND_COMPONENTS) 22# # This code has been deprecated after Zephyr x.y 23# if(DEPRECATED_VAR) 24# deprecated() 25# endif() 26# endif() 27# 28# and then in the original CMakeLists.txt, this code is inserted instead: 29# find_package(Deprecated COMPONENTS <deprecated_name>) 30# 31# The module defines the following variables: 32# 33# 'Deprecated_FOUND', 'DEPRECATED_FOUND' 34# True if the Deprecated component was found and loaded. 35 36if("${Deprecated_FIND_COMPONENTS}" STREQUAL "") 37 message(WARNING "find_package(Deprecated) missing required COMPONENTS keyword") 38endif() 39 40if("CROSS_COMPILE" IN_LIST Deprecated_FIND_COMPONENTS) 41 list(REMOVE_ITEM Deprecated_FIND_COMPONENTS CROSS_COMPILE) 42 # This code was deprecated after Zephyr v3.1.0 43 if(NOT DEFINED ZEPHYR_TOOLCHAIN_VARIANT) 44 set(ZEPHYR_TOOLCHAIN_VARIANT $ENV{ZEPHYR_TOOLCHAIN_VARIANT}) 45 endif() 46 47 if(NOT ZEPHYR_TOOLCHAIN_VARIANT AND 48 (CROSS_COMPILE OR (DEFINED ENV{CROSS_COMPILE}))) 49 set(ZEPHYR_TOOLCHAIN_VARIANT cross-compile CACHE STRING "Zephyr toolchain variant" FORCE) 50 message(DEPRECATION "Setting CROSS_COMPILE without setting ZEPHYR_TOOLCHAIN_VARIANT is deprecated." 51 "Please set ZEPHYR_TOOLCHAIN_VARIANT to 'cross-compile'" 52 ) 53 endif() 54endif() 55 56if("SPARSE" IN_LIST Deprecated_FIND_COMPONENTS) 57 list(REMOVE_ITEM Deprecated_FIND_COMPONENTS SPARSE) 58 # This code was deprecated after Zephyr v3.2.0 59 if(SPARSE) 60 message(DEPRECATION 61 "Setting SPARSE='${SPARSE}' is deprecated. " 62 "Please set ZEPHYR_SCA_VARIANT to 'sparse'" 63 ) 64 if("${SPARSE}" STREQUAL "y") 65 set_ifndef(ZEPHYR_SCA_VARIANT sparse) 66 endif() 67 endif() 68endif() 69 70if("SOURCES" IN_LIST Deprecated_FIND_COMPONENTS) 71 list(REMOVE_ITEM Deprecated_FIND_COMPONENTS SOURCES) 72 if(SOURCES) 73 message(DEPRECATION 74 "Setting SOURCES prior to calling find_package() for unit tests is deprecated." 75 " To add sources after find_package() use:\n" 76 " target_sources(testbinary PRIVATE <source-file.c>)") 77 endif() 78endif() 79 80if("PYTHON_PREFER" IN_LIST Deprecated_FIND_COMPONENTS) 81 # This code was deprecated after Zephyr v3.4.0 82 list(REMOVE_ITEM Deprecated_FIND_COMPONENTS PYTHON_PREFER) 83 if(DEFINED PYTHON_PREFER) 84 message(DEPRECATION "'PYTHON_PREFER' variable is deprecated. Please use " 85 "Python3_EXECUTABLE instead.") 86 if(NOT DEFINED Python3_EXECUTABLE) 87 set(Python3_EXECUTABLE ${PYTHON_PREFER}) 88 endif() 89 endif() 90endif() 91 92if("toolchain_ld_base" IN_LIST Deprecated_FIND_COMPONENTS) 93 # This code was deprecated after Zephyr v4.0.0 94 list(REMOVE_ITEM Deprecated_FIND_COMPONENTS toolchain_ld_base) 95 96 if(COMMAND toolchain_ld_base) 97 message(DEPRECATION 98 "The macro/function 'toolchain_ld_base' is deprecated. " 99 "Please use '${LINKER}/linker_flags.cmake' and define the appropriate " 100 "linker flags as properties instead. " 101 "See '${ZEPHYR_BASE}/cmake/linker/linker_flags_template.cmake' for " 102 "known linker properties." 103 ) 104 toolchain_ld_base() 105 endif() 106endif() 107 108if("toolchain_ld_baremetal" IN_LIST Deprecated_FIND_COMPONENTS) 109 # This code was deprecated after Zephyr v4.0.0 110 list(REMOVE_ITEM Deprecated_FIND_COMPONENTS toolchain_ld_baremetal) 111 112 if(COMMAND toolchain_ld_baremetal) 113 message(DEPRECATION 114 "The macro/function 'toolchain_ld_baremetal' is deprecated. " 115 "Please use '${LINKER}/linker_flags.cmake' and define the appropriate " 116 "linker flags as properties instead. " 117 "See '${ZEPHYR_BASE}/cmake/linker/linker_flags_template.cmake' for " 118 "known linker properties." 119 ) 120 toolchain_ld_baremetal() 121 endif() 122endif() 123 124if("toolchain_ld_cpp" IN_LIST Deprecated_FIND_COMPONENTS) 125 # This code was deprecated after Zephyr v4.0.0 126 list(REMOVE_ITEM Deprecated_FIND_COMPONENTS toolchain_ld_cpp) 127 128 if(COMMAND toolchain_ld_cpp) 129 message(DEPRECATION 130 "The macro/function 'toolchain_ld_cpp' is deprecated. " 131 "Please use '${LINKER}/linker_flags.cmake' and define the appropriate " 132 "linker flags as properties instead. " 133 "See '${ZEPHYR_BASE}/cmake/linker/linker_flags_template.cmake' for " 134 "known linker properties." 135 ) 136 toolchain_ld_cpp() 137 endif() 138endif() 139 140if(NOT "${Deprecated_FIND_COMPONENTS}" STREQUAL "") 141 message(STATUS "The following deprecated component(s) could not be found: " 142 "${Deprecated_FIND_COMPONENTS}") 143endif() 144 145if("SEARCHED_LINKER_SCRIPT" IN_LIST Deprecated_FIND_COMPONENTS) 146 # This code was deprecated after Zephyr v3.5.0 147 list(REMOVE_ITEM Deprecated_FIND_COMPONENTS SEARCHED_LINKER_SCRIPT) 148 149 # Try a board specific linker file 150 set(LINKER_SCRIPT ${BOARD_DIR}/linker.ld) 151 if(NOT EXISTS ${LINKER_SCRIPT}) 152 # If not available, try an SoC specific linker file 153 set(LINKER_SCRIPT ${SOC_FULL_DIR}/linker.ld) 154 endif() 155 message(DEPRECATION 156 "Pre-defined `linker.ld` script is deprecated. Please set " 157 "BOARD_LINKER_SCRIPT or SOC_LINKER_SCRIPT to point to ${LINKER_SCRIPT} " 158 "or one of the Zephyr provided common linker scripts for the ${ARCH} " 159 "architecture." 160 ) 161endif() 162 163set(Deprecated_FOUND True) 164set(DEPRECATED_FOUND True) 165