zephyr/cmake/app/boilerplate.cmake
Torsten Rasmussen f96ee77c7c cmake: function to update Zephyr_DIR when loading old Zephyr packages
Fixes: #43094

This commit introduces a function which updates Zephyr_DIR to point to
the directory of the Zephyr package being loaded.

For Zephyr 3.0 and earlier, the Zephyr_DIR might in some cases be
`Zephyr_DIR-NOTFOUND` or pointing to the Zephyr package including the
boilerplate code instead of the Zephyr package of the included
boilerplate code.

This code ensures that when a package is loaded then Zephyr_DIR will
point correctly.
This ensures that when Zephyr releases <=3.0 is loaded, then Zephyr_DIR
will point correctly, see more in #43094.

Old style Zephyr package will in some cases load boilerplate.cmake
directly so to ensure proper behavior, restrict boilerplate uses of
`find_package(Zephyr)` to not use default search path, but allow only
the current Zephyr.

Of the same reason, only print warning if Zephyr_DIR is not defined as
this indicates old style inclusion.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2022-03-07 16:35:54 +01:00

26 lines
919 B
CMake

# SPDX-License-Identifier: Apache-2.0
######################################
# The use of this file is deprecated #
######################################
# To build a Zephyr application it must start with one of those lines:
#
# find_package(Zephyr)
# find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
#
# The `REQUIRED HINTS $ENV{ZEPHYR_BASE}` variant is required for any application
# inside the Zephyr repository.
#
# Loading of this file directly is deprecated and only kept for backward compatibility.
if(NOT DEFINED Zephyr_DIR)
# When `find_package(Zephyr)` is used then `Zephyr_DIR` is defined, else
# old style inclusion is used. Warning is only printed in first invocation.
message(WARNING "Loading of Zephyr boilerplate.cmake directly is deprecated, "
"please use 'find_package(Zephyr)'"
)
endif()
find_package(Zephyr REQUIRED PATHS ${CMAKE_CURRENT_LIST_DIR}/../.. NO_DEFAULT_PATH)