blob: df0b6a3df51bf00d07c69a352d1d82b07e95c5ef [file] [log] [blame]
Torsten Rasmussen2f1637c2022-08-31 21:59:26 +02001# 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
Torsten Rasmussen980c22c2022-08-31 22:24:04 +020040if("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 Rasmussen56c827a2022-07-14 15:44:53 +020049 set(ZEPHYR_TOOLCHAIN_VARIANT cross-compile CACHE STRING "Zephyr toolchain variant" FORCE)
Torsten Rasmussena5cd3942022-09-07 09:54:39 +020050 message(DEPRECATION "Setting CROSS_COMPILE without setting ZEPHYR_TOOLCHAIN_VARIANT is deprecated."
51 "Please set ZEPHYR_TOOLCHAIN_VARIANT to 'cross-compile'"
52 )
Torsten Rasmussen980c22c2022-08-31 22:24:04 +020053 endif()
54endif()
Torsten Rasmussen2f1637c2022-08-31 21:59:26 +020055
Stephanos Ioannidisa9d85ae2022-10-17 22:56:40 +090056if("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'")
64endif()
65
Torsten Rasmussen60196ca2022-11-30 12:46:38 +010066if("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 Herbertacb7f712023-04-18 17:22:07 +000071 "Setting SPARSE='${SPARSE}' is deprecated. "
Torsten Rasmussen60196ca2022-11-30 12:46:38 +010072 "Please set ZEPHYR_SCA_VARIANT to 'sparse'"
73 )
Marc Herbertacb7f712023-04-18 17:22:07 +000074 if("${SPARSE}" STREQUAL "y")
75 set_ifndef(ZEPHYR_SCA_VARIANT sparse)
76 endif()
Torsten Rasmussen60196ca2022-11-30 12:46:38 +010077 endif()
78endif()
79
Yuval Peressffb861d2022-10-13 10:20:41 -060080if("SOURCES" IN_LIST Deprecated_FIND_COMPONENTS)
Torsten Rasmussen0b845cd2022-12-01 11:40:24 +010081 list(REMOVE_ITEM Deprecated_FIND_COMPONENTS SOURCES)
Yuval Peressfae99232022-11-06 22:43:14 -070082 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 Peressffb861d2022-10-13 10:20:41 -060088endif()
89
Torsten Rasmussen40d85eb2023-06-28 11:40:51 +020090if("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()
100endif()
101
Torsten Rasmussen69d2c0f2024-09-12 13:06:54 +0200102if("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()
116endif()
117
118if("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()
132endif()
133
134if("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()
148endif()
149
Torsten Rasmussen0b845cd2022-12-01 11:40:24 +0100150if(NOT "${Deprecated_FIND_COMPONENTS}" STREQUAL "")
151 message(STATUS "The following deprecated component(s) could not be found: "
152 "${Deprecated_FIND_COMPONENTS}")
153endif()
154
Torsten Rasmussen26b649e2023-10-27 21:49:16 +0200155if("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 Rasmussen8dc3f852022-09-14 22:23:15 +0200163 set(LINKER_SCRIPT ${SOC_FULL_DIR}/linker.ld)
Torsten Rasmussen26b649e2023-10-27 21:49:16 +0200164 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 )
171endif()
172
Torsten Rasmussen2f1637c2022-08-31 21:59:26 +0200173set(Deprecated_FOUND True)
174set(DEPRECATED_FOUND True)