2020-02-18 21:06:44 +08:00
|
|
|
# The purpose of this file is to provide search mechanism for locating Zephyr in-work-tree package
|
|
|
|
# even when they are not installed into CMake package system
|
|
|
|
# Linux/MacOS: ~/.cmake/packages
|
|
|
|
# Windows: Registry database
|
|
|
|
|
2020-03-04 19:34:44 +08:00
|
|
|
# Relative directory of workspace project dir as seen from Zephyr package file
|
|
|
|
set(WORKSPACE_RELATIVE_DIR "../../../../..")
|
2020-02-18 21:06:44 +08:00
|
|
|
|
|
|
|
# Relative directory of Zephyr dir as seen from Zephyr package file
|
|
|
|
set(ZEPHYR_RELATIVE_DIR "../../../..")
|
|
|
|
|
|
|
|
# This macro returns a list of parent folders to use for later searches.
|
2020-03-09 22:26:21 +08:00
|
|
|
macro(get_search_paths START_PATH SEARCH_PATHS PREFERENCE_LIST)
|
2020-02-18 21:06:44 +08:00
|
|
|
get_filename_component(SEARCH_PATH ${START_PATH} DIRECTORY)
|
2020-05-04 22:39:02 +08:00
|
|
|
while(NOT (SEARCH_PATH STREQUAL SEARCH_PATH_PREV))
|
2020-03-09 22:26:21 +08:00
|
|
|
foreach(preference ${PREFERENCE_LIST})
|
|
|
|
list(APPEND SEARCH_PATHS ${SEARCH_PATH}/${preference})
|
|
|
|
endforeach()
|
2020-02-18 21:06:44 +08:00
|
|
|
list(APPEND SEARCH_PATHS ${SEARCH_PATH}/zephyr)
|
|
|
|
list(APPEND SEARCH_PATHS ${SEARCH_PATH})
|
2020-05-04 22:39:02 +08:00
|
|
|
set(SEARCH_PATH_PREV ${SEARCH_PATH})
|
2020-02-18 21:06:44 +08:00
|
|
|
get_filename_component(SEARCH_PATH ${SEARCH_PATH} DIRECTORY)
|
|
|
|
endwhile()
|
|
|
|
endmacro()
|
|
|
|
|
|
|
|
# This macro can check for additional Zephyr package that has a better match
|
|
|
|
# Options:
|
2020-03-09 22:26:21 +08:00
|
|
|
# - ZEPHYR_BASE : Use the specified ZEPHYR_BASE directly.
|
|
|
|
# - WORKSPACE_DIR : Search for projects in specified workspace.
|
|
|
|
# - SEARCH_PARENTS : Search parent folder of current source file (application)
|
|
|
|
# to locate in-project-tree Zephyr candidates.
|
|
|
|
# - CHECK_ONLY : Only set PACKAGE_VERSION_COMPATIBLE to false if a better candidate
|
|
|
|
# is found, default is to also include the found candidate.
|
|
|
|
# - VERSION_CHECK : This is the version check stage by CMake find package
|
|
|
|
# - CANDIDATES_PREFERENCE_LIST : List of candidate to be preferred, if installed
|
2020-02-18 21:06:44 +08:00
|
|
|
macro(check_zephyr_package)
|
2020-03-09 22:26:21 +08:00
|
|
|
set(options CHECK_ONLY SEARCH_PARENTS VERSION_CHECK)
|
2020-03-04 19:34:44 +08:00
|
|
|
set(single_args WORKSPACE_DIR ZEPHYR_BASE)
|
2020-03-09 22:26:21 +08:00
|
|
|
set(list_args CANDIDATES_PREFERENCE_LIST)
|
|
|
|
cmake_parse_arguments(CHECK_ZEPHYR_PACKAGE "${options}" "${single_args}" "${list_args}" ${ARGN})
|
2020-02-18 21:06:44 +08:00
|
|
|
|
2020-03-04 19:34:44 +08:00
|
|
|
if(CHECK_ZEPHYR_PACKAGE_ZEPHYR_BASE)
|
|
|
|
set(SEARCH_SETTINGS PATHS ${CHECK_ZEPHYR_PACKAGE_ZEPHYR_BASE} NO_DEFAULT_PATH)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(CHECK_ZEPHYR_PACKAGE_WORKSPACE_DIR)
|
|
|
|
set(SEARCH_SETTINGS PATHS ${CHECK_ZEPHYR_PACKAGE_WORKSPACE_DIR}/zephyr ${CHECK_ZEPHYR_PACKAGE_WORKSPACE_DIR} NO_DEFAULT_PATH)
|
2020-02-18 21:06:44 +08:00
|
|
|
endif()
|
|
|
|
|
|
|
|
if(CHECK_ZEPHYR_PACKAGE_SEARCH_PARENTS)
|
2020-03-09 22:26:21 +08:00
|
|
|
get_search_paths(${CMAKE_CURRENT_SOURCE_DIR} SEARCH_PATHS "${CHECK_ZEPHYR_PACKAGE_CANDIDATES_PREFERENCE_LIST}")
|
2020-02-18 21:06:44 +08:00
|
|
|
set(SEARCH_SETTINGS PATHS ${SEARCH_PATHS} NO_DEFAULT_PATH)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Searching for version zero means there will be no match, but we obtain
|
|
|
|
# a list of all potential Zephyr candidates in the tree to consider.
|
|
|
|
find_package(Zephyr 0.0.0 EXACT QUIET ${SEARCH_SETTINGS})
|
|
|
|
|
2020-03-09 22:26:21 +08:00
|
|
|
# The find package will also find ourself when searching using installed candidates.
|
|
|
|
# So avoid re-including unless NO_DEFAULT_PATH is set.
|
|
|
|
# NO_DEFAULT_PATH means explicit search and we could be part of a preference list.
|
|
|
|
if(NOT (NO_DEFAULT_PATH IN_LIST SEARCH_SETTINGS))
|
|
|
|
list(REMOVE_ITEM Zephyr_CONSIDERED_CONFIGS ${CMAKE_CURRENT_LIST_DIR}/ZephyrConfig.cmake)
|
|
|
|
endif()
|
2020-02-18 21:06:44 +08:00
|
|
|
list(REMOVE_DUPLICATES Zephyr_CONSIDERED_CONFIGS)
|
|
|
|
|
|
|
|
foreach(ZEPHYR_CANDIDATE ${Zephyr_CONSIDERED_CONFIGS})
|
2020-03-04 19:34:44 +08:00
|
|
|
if(CHECK_ZEPHYR_PACKAGE_WORKSPACE_DIR)
|
|
|
|
# Check is done in Zephyr workspace already, thus check only for pure Zephyr candidates.
|
2020-02-18 21:06:44 +08:00
|
|
|
get_filename_component(CANDIDATE_DIR ${ZEPHYR_CANDIDATE}/${ZEPHYR_RELATIVE_DIR} ABSOLUTE)
|
|
|
|
else()
|
2020-03-04 19:34:44 +08:00
|
|
|
get_filename_component(CANDIDATE_DIR ${ZEPHYR_CANDIDATE}/${WORKSPACE_RELATIVE_DIR} ABSOLUTE)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(CHECK_ZEPHYR_PACKAGE_ZEPHYR_BASE)
|
|
|
|
if(CHECK_ZEPHYR_PACKAGE_VERSION_CHECK)
|
|
|
|
string(REGEX REPLACE "\.cmake$" "Version.cmake" ZEPHYR_VERSION_CANDIDATE ${ZEPHYR_CANDIDATE})
|
|
|
|
include(${ZEPHYR_VERSION_CANDIDATE} NO_POLICY_SCOPE)
|
|
|
|
return()
|
|
|
|
else()
|
|
|
|
include(${ZEPHYR_CANDIDATE} NO_POLICY_SCOPE)
|
|
|
|
return()
|
|
|
|
endif()
|
2020-02-18 21:06:44 +08:00
|
|
|
endif()
|
|
|
|
|
|
|
|
string(FIND "${CMAKE_CURRENT_SOURCE_DIR}" "${CANDIDATE_DIR}/" COMMON_INDEX)
|
|
|
|
if (COMMON_INDEX EQUAL 0)
|
|
|
|
if(CHECK_ZEPHYR_PACKAGE_CHECK_ONLY)
|
|
|
|
# A better candidate exists, thus return
|
|
|
|
set(PACKAGE_VERSION_COMPATIBLE FALSE)
|
|
|
|
return()
|
2020-03-09 22:26:21 +08:00
|
|
|
elseif(ZEPHYR_CANDIDATE STREQUAL ${CMAKE_CURRENT_LIST_DIR}/ZephyrConfig.cmake)
|
|
|
|
# Current Zephyr is preferred one, let's just break the loop and continue processing.
|
|
|
|
break()
|
2020-02-18 21:06:44 +08:00
|
|
|
else()
|
|
|
|
if(CHECK_ZEPHYR_PACKAGE_VERSION_CHECK)
|
|
|
|
string(REGEX REPLACE "\.cmake$" "Version.cmake" ZEPHYR_VERSION_CANDIDATE ${ZEPHYR_CANDIDATE})
|
|
|
|
include(${ZEPHYR_VERSION_CANDIDATE} NO_POLICY_SCOPE)
|
|
|
|
return()
|
|
|
|
else()
|
|
|
|
include(${ZEPHYR_CANDIDATE} NO_POLICY_SCOPE)
|
|
|
|
return()
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
endmacro()
|