Skip to content

Commit c94fee8

Browse files
tejlmandcarlescufi
authored andcommitted
cmake: support range for find_package(Zephyr-sdk)
Fixes: #80200 CMake `find_package(<package> <version>)` support the use of ranges, like `1.0.0...4.0.0`. Update the FindZephyr-sdk.cmake module to support this. This allows looking up the Zephyr SDK with an upper boundry, for example `find_package(Zephyr-sdk 0.16...<0.17)`. Signed-off-by: Torsten Rasmussen <[email protected]>
1 parent f5e54e6 commit c94fee8

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

cmake/modules/FindZephyr-sdk.cmake

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ if(("zephyr" STREQUAL ${ZEPHYR_TOOLCHAIN_VARIANT}) OR
5454
# To support Zephyr SDK tools (DTC, and other tools) with 3rd party toolchains
5555
# then we keep track of current toolchain variant.
5656
set(ZEPHYR_CURRENT_TOOLCHAIN_VARIANT ${ZEPHYR_TOOLCHAIN_VARIANT})
57-
find_package(Zephyr-sdk ${Zephyr-sdk_FIND_VERSION}
57+
find_package(Zephyr-sdk ${Zephyr-sdk_FIND_VERSION_COMPLETE}
5858
REQUIRED QUIET CONFIG HINTS ${ZEPHYR_SDK_INSTALL_DIR}
5959
)
6060
if(DEFINED ZEPHYR_CURRENT_TOOLCHAIN_VARIANT)
@@ -82,18 +82,28 @@ if(("zephyr" STREQUAL ${ZEPHYR_TOOLCHAIN_VARIANT}) OR
8282

8383
list(REMOVE_DUPLICATES Zephyr-sdk_CONSIDERED_VERSIONS)
8484
list(SORT Zephyr-sdk_CONSIDERED_VERSIONS COMPARE NATURAL ORDER DESCENDING)
85+
if("${Zephyr-sdk_FIND_VERSION_RANGE_MAX}" STREQUAL "INCLUDE")
86+
set(upper_bound _EQUAL)
87+
endif()
88+
89+
if(NOT DEFINED Zephyr-sdk_FIND_VERSION_RANGE)
90+
# Range not given, max out to ensure max version is not in effect.
91+
set(Zephyr-sdk_FIND_VERSION_MAX 99999999)
92+
endif()
8593

8694
# Loop over each found Zepher SDK version until one is found that is compatible.
8795
foreach(zephyr_sdk_candidate ${Zephyr-sdk_CONSIDERED_VERSIONS})
88-
if("${zephyr_sdk_candidate}" VERSION_GREATER_EQUAL "${Zephyr-sdk_FIND_VERSION}")
96+
if("${zephyr_sdk_candidate}" VERSION_GREATER_EQUAL "${Zephyr-sdk_FIND_VERSION}"
97+
AND "${zephyr_sdk_candidate}" VERSION_LESS${upper_bound} "${Zephyr-sdk_FIND_VERSION_MAX}"
98+
)
8999
# Find the path for the current version being checked and get the directory
90100
# of the Zephyr SDK so it can be checked.
91101
list(FIND zephyr_sdk_found_versions ${zephyr_sdk_candidate} zephyr_sdk_current_index)
92102
list(GET zephyr_sdk_found_configs ${zephyr_sdk_current_index} zephyr_sdk_current_check_path)
93103
get_filename_component(zephyr_sdk_current_check_path ${zephyr_sdk_current_check_path} DIRECTORY)
94104

95105
# Then see if this version is compatible.
96-
find_package(Zephyr-sdk ${Zephyr-sdk_FIND_VERSION} QUIET CONFIG PATHS ${zephyr_sdk_current_check_path} NO_DEFAULT_PATH)
106+
find_package(Zephyr-sdk ${Zephyr-sdk_FIND_VERSION_COMPLETE} QUIET CONFIG PATHS ${zephyr_sdk_current_check_path} NO_DEFAULT_PATH)
97107

98108
if (${Zephyr-sdk_FOUND})
99109
# A compatible version of the Zephyr SDK has been found which is the highest
@@ -106,7 +116,7 @@ if(("zephyr" STREQUAL ${ZEPHYR_TOOLCHAIN_VARIANT}) OR
106116
if (NOT ${Zephyr-sdk_FOUND})
107117
# This means no compatible Zephyr SDK versions were found, set the version
108118
# back to the minimum version so that it is displayed in the error text.
109-
find_package(Zephyr-sdk ${Zephyr-sdk_FIND_VERSION} REQUIRED CONFIG PATHS ${zephyr_sdk_search_paths})
119+
find_package(Zephyr-sdk ${Zephyr-sdk_FIND_VERSION_COMPLETE} REQUIRED CONFIG PATHS ${zephyr_sdk_search_paths})
110120
endif()
111121
endif()
112122

0 commit comments

Comments
 (0)