blob: 27f2165033c80d6a086561fb2df917d7f36e20b3 [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("XCC_USE_CLANG" IN_LIST Deprecated_FIND_COMPONENTS)
41 list(REMOVE_ITEM Deprecated_FIND_COMPONENTS XCC_USE_CLANG)
42 # This code was deprecated after Zephyr v3.0.0
43 # Keep XCC_USE_CLANG behaviour for a while.
44 if(NOT DEFINED ZEPHYR_TOOLCHAIN_VARIANT)
45 set(ZEPHYR_TOOLCHAIN_VARIANT $ENV{ZEPHYR_TOOLCHAIN_VARIANT})
46 endif()
47
48 if ("${ZEPHYR_TOOLCHAIN_VARIANT}" STREQUAL "xcc"
49 AND "$ENV{XCC_USE_CLANG}" STREQUAL "1")
Torsten Rasmussen56c827a2022-07-14 15:44:53 +020050 set(ZEPHYR_TOOLCHAIN_VARIANT xcc-clang CACHE STRING "Zephyr toolchain variant" FORCE)
Torsten Rasmussen980c22c2022-08-31 22:24:04 +020051 message(DEPRECATION "XCC_USE_CLANG is deprecated. Please set ZEPHYR_TOOLCHAIN_VARIANT to 'xcc-clang'")
52 endif()
53endif()
54
55if("CROSS_COMPILE" IN_LIST Deprecated_FIND_COMPONENTS)
56 list(REMOVE_ITEM Deprecated_FIND_COMPONENTS CROSS_COMPILE)
57 # This code was deprecated after Zephyr v3.1.0
58 if(NOT DEFINED ZEPHYR_TOOLCHAIN_VARIANT)
59 set(ZEPHYR_TOOLCHAIN_VARIANT $ENV{ZEPHYR_TOOLCHAIN_VARIANT})
60 endif()
61
62 if(NOT ZEPHYR_TOOLCHAIN_VARIANT AND
63 (CROSS_COMPILE OR (DEFINED ENV{CROSS_COMPILE})))
Torsten Rasmussen56c827a2022-07-14 15:44:53 +020064 set(ZEPHYR_TOOLCHAIN_VARIANT cross-compile CACHE STRING "Zephyr toolchain variant" FORCE)
Torsten Rasmussena5cd3942022-09-07 09:54:39 +020065 message(DEPRECATION "Setting CROSS_COMPILE without setting ZEPHYR_TOOLCHAIN_VARIANT is deprecated."
66 "Please set ZEPHYR_TOOLCHAIN_VARIANT to 'cross-compile'"
67 )
Torsten Rasmussen980c22c2022-08-31 22:24:04 +020068 endif()
69endif()
Torsten Rasmussen2f1637c2022-08-31 21:59:26 +020070
71if(NOT "${Deprecated_FIND_COMPONENTS}" STREQUAL "")
72 message(STATUS "The following deprecated component(s) could not be found: "
73 "${Deprecated_FIND_COMPONENTS}")
74endif()
75
Yuval Peressffb861d2022-10-13 10:20:41 -060076if("SOURCES" IN_LIST Deprecated_FIND_COMPONENTS)
77 message(DEPRECATION
78 "Setting SOURCES prior to calling find_package() for unit tests is deprecated."
79 "To add sources after find_package() use:\n"
80 " target_sources(testbinary PRIVATE <source-file.c>)")
81endif()
82
Torsten Rasmussen2f1637c2022-08-31 21:59:26 +020083set(Deprecated_FOUND True)
84set(DEPRECATED_FOUND True)