Torsten Rasmussen | 2f1637c | 2022-08-31 21:59:26 +0200 | [diff] [blame] | 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 | |
| 36 | if("${Deprecated_FIND_COMPONENTS}" STREQUAL "") |
| 37 | message(WARNING "find_package(Deprecated) missing required COMPONENTS keyword") |
| 38 | endif() |
| 39 | |
Torsten Rasmussen | 980c22c | 2022-08-31 22:24:04 +0200 | [diff] [blame] | 40 | if("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}))) |
Torsten Rasmussen | 56c827a | 2022-07-14 15:44:53 +0200 | [diff] [blame] | 49 | set(ZEPHYR_TOOLCHAIN_VARIANT cross-compile CACHE STRING "Zephyr toolchain variant" FORCE) |
Torsten Rasmussen | a5cd394 | 2022-09-07 09:54:39 +0200 | [diff] [blame] | 50 | message(DEPRECATION "Setting CROSS_COMPILE without setting ZEPHYR_TOOLCHAIN_VARIANT is deprecated." |
| 51 | "Please set ZEPHYR_TOOLCHAIN_VARIANT to 'cross-compile'" |
| 52 | ) |
Torsten Rasmussen | 980c22c | 2022-08-31 22:24:04 +0200 | [diff] [blame] | 53 | endif() |
| 54 | endif() |
Torsten Rasmussen | 2f1637c | 2022-08-31 21:59:26 +0200 | [diff] [blame] | 55 | |
Stephanos Ioannidis | a9d85ae | 2022-10-17 22:56:40 +0900 | [diff] [blame] | 56 | if("XTOOLS" IN_LIST Deprecated_FIND_COMPONENTS) |
| 57 | list(REMOVE_ITEM Deprecated_FIND_COMPONENTS XTOOLS) |
| 58 | # This code was deprecated after Zephyr v3.3.0 |
| 59 | # When removing support for `xtools`, remember to also remove: |
| 60 | # cmake/toolchain/xtools (folder with files) |
| 61 | # doc/develop/toolchains/crosstool_ng.rst and update the index.rst file. |
| 62 | message(DEPRECATION "XTOOLS toolchain variant is deprecated. " |
| 63 | "Please set ZEPHYR_TOOLCHAIN_VARIANT to 'zephyr'") |
| 64 | endif() |
| 65 | |
Torsten Rasmussen | 60196ca | 2022-11-30 12:46:38 +0100 | [diff] [blame] | 66 | if("SPARSE" IN_LIST Deprecated_FIND_COMPONENTS) |
| 67 | list(REMOVE_ITEM Deprecated_FIND_COMPONENTS SPARSE) |
| 68 | # This code was deprecated after Zephyr v3.2.0 |
| 69 | if(SPARSE) |
| 70 | message(DEPRECATION |
Marc Herbert | acb7f71 | 2023-04-18 17:22:07 +0000 | [diff] [blame] | 71 | "Setting SPARSE='${SPARSE}' is deprecated. " |
Torsten Rasmussen | 60196ca | 2022-11-30 12:46:38 +0100 | [diff] [blame] | 72 | "Please set ZEPHYR_SCA_VARIANT to 'sparse'" |
| 73 | ) |
Marc Herbert | acb7f71 | 2023-04-18 17:22:07 +0000 | [diff] [blame] | 74 | if("${SPARSE}" STREQUAL "y") |
| 75 | set_ifndef(ZEPHYR_SCA_VARIANT sparse) |
| 76 | endif() |
Torsten Rasmussen | 60196ca | 2022-11-30 12:46:38 +0100 | [diff] [blame] | 77 | endif() |
| 78 | endif() |
| 79 | |
Yuval Peress | ffb861d | 2022-10-13 10:20:41 -0600 | [diff] [blame] | 80 | if("SOURCES" IN_LIST Deprecated_FIND_COMPONENTS) |
Torsten Rasmussen | 0b845cd | 2022-12-01 11:40:24 +0100 | [diff] [blame] | 81 | list(REMOVE_ITEM Deprecated_FIND_COMPONENTS SOURCES) |
Yuval Peress | fae9923 | 2022-11-06 22:43:14 -0700 | [diff] [blame] | 82 | if(SOURCES) |
| 83 | message(DEPRECATION |
| 84 | "Setting SOURCES prior to calling find_package() for unit tests is deprecated." |
| 85 | " To add sources after find_package() use:\n" |
| 86 | " target_sources(testbinary PRIVATE <source-file.c>)") |
| 87 | endif() |
Yuval Peress | ffb861d | 2022-10-13 10:20:41 -0600 | [diff] [blame] | 88 | endif() |
| 89 | |
Torsten Rasmussen | 40d85eb | 2023-06-28 11:40:51 +0200 | [diff] [blame] | 90 | if("PYTHON_PREFER" IN_LIST Deprecated_FIND_COMPONENTS) |
| 91 | # This code was deprecated after Zephyr v3.4.0 |
| 92 | list(REMOVE_ITEM Deprecated_FIND_COMPONENTS PYTHON_PREFER) |
| 93 | if(DEFINED PYTHON_PREFER) |
| 94 | message(DEPRECATION "'PYTHON_PREFER' variable is deprecated. Please use " |
| 95 | "Python3_EXECUTABLE instead.") |
| 96 | if(NOT DEFINED Python3_EXECUTABLE) |
| 97 | set(Python3_EXECUTABLE ${PYTHON_PREFER}) |
| 98 | endif() |
| 99 | endif() |
| 100 | endif() |
| 101 | |
Torsten Rasmussen | 69d2c0f | 2024-09-12 13:06:54 +0200 | [diff] [blame] | 102 | if("toolchain_ld_base" IN_LIST Deprecated_FIND_COMPONENTS) |
| 103 | # This code was deprecated after Zephyr v4.0.0 |
| 104 | list(REMOVE_ITEM Deprecated_FIND_COMPONENTS toolchain_ld_base) |
| 105 | |
| 106 | if(COMMAND toolchain_ld_base) |
| 107 | message(DEPRECATION |
| 108 | "The macro/function 'toolchain_ld_base' is deprecated. " |
| 109 | "Please use '${LINKER}/linker_flags.cmake' and define the appropriate " |
| 110 | "linker flags as properties instead. " |
| 111 | "See '${ZEPHYR_BASE}/cmake/linker/linker_flags_template.cmake' for " |
| 112 | "known linker properties." |
| 113 | ) |
| 114 | toolchain_ld_base() |
| 115 | endif() |
| 116 | endif() |
| 117 | |
| 118 | if("toolchain_ld_baremetal" IN_LIST Deprecated_FIND_COMPONENTS) |
| 119 | # This code was deprecated after Zephyr v4.0.0 |
| 120 | list(REMOVE_ITEM Deprecated_FIND_COMPONENTS toolchain_ld_baremetal) |
| 121 | |
| 122 | if(COMMAND toolchain_ld_baremetal) |
| 123 | message(DEPRECATION |
| 124 | "The macro/function 'toolchain_ld_baremetal' is deprecated. " |
| 125 | "Please use '${LINKER}/linker_flags.cmake' and define the appropriate " |
| 126 | "linker flags as properties instead. " |
| 127 | "See '${ZEPHYR_BASE}/cmake/linker/linker_flags_template.cmake' for " |
| 128 | "known linker properties." |
| 129 | ) |
| 130 | toolchain_ld_baremetal() |
| 131 | endif() |
| 132 | endif() |
| 133 | |
| 134 | if("toolchain_ld_cpp" IN_LIST Deprecated_FIND_COMPONENTS) |
| 135 | # This code was deprecated after Zephyr v4.0.0 |
| 136 | list(REMOVE_ITEM Deprecated_FIND_COMPONENTS toolchain_ld_cpp) |
| 137 | |
| 138 | if(COMMAND toolchain_ld_cpp) |
| 139 | message(DEPRECATION |
| 140 | "The macro/function 'toolchain_ld_cpp' is deprecated. " |
| 141 | "Please use '${LINKER}/linker_flags.cmake' and define the appropriate " |
| 142 | "linker flags as properties instead. " |
| 143 | "See '${ZEPHYR_BASE}/cmake/linker/linker_flags_template.cmake' for " |
| 144 | "known linker properties." |
| 145 | ) |
| 146 | toolchain_ld_cpp() |
| 147 | endif() |
| 148 | endif() |
| 149 | |
Torsten Rasmussen | 0b845cd | 2022-12-01 11:40:24 +0100 | [diff] [blame] | 150 | if(NOT "${Deprecated_FIND_COMPONENTS}" STREQUAL "") |
| 151 | message(STATUS "The following deprecated component(s) could not be found: " |
| 152 | "${Deprecated_FIND_COMPONENTS}") |
| 153 | endif() |
| 154 | |
Torsten Rasmussen | 26b649e | 2023-10-27 21:49:16 +0200 | [diff] [blame] | 155 | if("SEARCHED_LINKER_SCRIPT" IN_LIST Deprecated_FIND_COMPONENTS) |
| 156 | # This code was deprecated after Zephyr v3.5.0 |
| 157 | list(REMOVE_ITEM Deprecated_FIND_COMPONENTS SEARCHED_LINKER_SCRIPT) |
| 158 | |
| 159 | # Try a board specific linker file |
| 160 | set(LINKER_SCRIPT ${BOARD_DIR}/linker.ld) |
| 161 | if(NOT EXISTS ${LINKER_SCRIPT}) |
| 162 | # If not available, try an SoC specific linker file |
Torsten Rasmussen | 8dc3f85 | 2022-09-14 22:23:15 +0200 | [diff] [blame] | 163 | set(LINKER_SCRIPT ${SOC_FULL_DIR}/linker.ld) |
Torsten Rasmussen | 26b649e | 2023-10-27 21:49:16 +0200 | [diff] [blame] | 164 | endif() |
| 165 | message(DEPRECATION |
| 166 | "Pre-defined `linker.ld` script is deprecated. Please set " |
| 167 | "BOARD_LINKER_SCRIPT or SOC_LINKER_SCRIPT to point to ${LINKER_SCRIPT} " |
| 168 | "or one of the Zephyr provided common linker scripts for the ${ARCH} " |
| 169 | "architecture." |
| 170 | ) |
| 171 | endif() |
| 172 | |
Torsten Rasmussen | 2f1637c | 2022-08-31 21:59:26 +0200 | [diff] [blame] | 173 | set(Deprecated_FOUND True) |
| 174 | set(DEPRECATED_FOUND True) |