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("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 Rasmussen | 56c827a | 2022-07-14 15:44:53 +0200 | [diff] [blame] | 50 | set(ZEPHYR_TOOLCHAIN_VARIANT xcc-clang CACHE STRING "Zephyr toolchain variant" FORCE) |
Torsten Rasmussen | 980c22c | 2022-08-31 22:24:04 +0200 | [diff] [blame] | 51 | message(DEPRECATION "XCC_USE_CLANG is deprecated. Please set ZEPHYR_TOOLCHAIN_VARIANT to 'xcc-clang'") |
| 52 | endif() |
| 53 | endif() |
| 54 | |
| 55 | if("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 Rasmussen | 56c827a | 2022-07-14 15:44:53 +0200 | [diff] [blame] | 64 | set(ZEPHYR_TOOLCHAIN_VARIANT cross-compile CACHE STRING "Zephyr toolchain variant" FORCE) |
Torsten Rasmussen | a5cd394 | 2022-09-07 09:54:39 +0200 | [diff] [blame] | 65 | message(DEPRECATION "Setting CROSS_COMPILE without setting ZEPHYR_TOOLCHAIN_VARIANT is deprecated." |
| 66 | "Please set ZEPHYR_TOOLCHAIN_VARIANT to 'cross-compile'" |
| 67 | ) |
Torsten Rasmussen | 980c22c | 2022-08-31 22:24:04 +0200 | [diff] [blame] | 68 | endif() |
| 69 | endif() |
Torsten Rasmussen | 2f1637c | 2022-08-31 21:59:26 +0200 | [diff] [blame] | 70 | |
| 71 | if(NOT "${Deprecated_FIND_COMPONENTS}" STREQUAL "") |
| 72 | message(STATUS "The following deprecated component(s) could not be found: " |
| 73 | "${Deprecated_FIND_COMPONENTS}") |
| 74 | endif() |
| 75 | |
Yuval Peress | ffb861d | 2022-10-13 10:20:41 -0600 | [diff] [blame^] | 76 | if("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>)") |
| 81 | endif() |
| 82 | |
Torsten Rasmussen | 2f1637c | 2022-08-31 21:59:26 +0200 | [diff] [blame] | 83 | set(Deprecated_FOUND True) |
| 84 | set(DEPRECATED_FOUND True) |