Skip to content

cmake: support loading of host-tool through COMPONENTS #555

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions cmake/FindZephyr-sdk_HostTools.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# SPDX-License-Identifier: Apache-2.0
#
# Copyright (c) 2022, Nordic Semiconductor ASA

# FindZephyr-sdk_HostTools module for locating HostTools components in Zephyr SDK.
#
# The module defines the following variables:
#
# 'HOST_TOOLS_HOME'
# Path to host tools home if installed.
# Set to 'HOST_TOOLS_HOME-NOTFOUND' if not installed.
#
# 'Zephyr-sdk_HostTools_FOUND', 'ZEPHYR-SDK_HOSTTOOLS_FOUND'
# True if the host tools are found.

cmake_host_system_information(RESULT TOOLCHAIN_ARCH QUERY OS_PLATFORM)
set(HOST_TOOLS_HOME ${ZEPHYR_SDK_INSTALL_DIR}/sysroots/${TOOLCHAIN_ARCH}-pokysdk-linux)
if(NOT EXISTS ${HOST_TOOLS_HOME})
set(HOST_TOOLS_HOME_MISSING ${HOST_TOOLS_HOME})
set(HOST_TOOLS_HOME HOST_TOOLS_HOME-NOTFOUND)
endif()

find_package_handle_standard_args(Zephyr-sdk_HostTools
REQUIRED_VARS HOST_TOOLS_HOME ${HOST_TOOLS_HOME_MISSING}
VERSION_VAR Zephyr-sdk_VERSION
)

if(Zephyr-sdk_HostTools_FOUND)
# Path used for searching by the find_*() functions, with appropriate
# suffixes added. Ensures that the SDK's host tools will be found when
# we call, e.g. find_program(QEMU qemu-system-x86)
list(APPEND CMAKE_PREFIX_PATH ${HOST_TOOLS_HOME}/usr)

# TODO: Use find_* somehow for these as well?
set_ifndef(QEMU_BIOS ${HOST_TOOLS_HOME}/usr/share/qemu)
set_ifndef(OPENOCD_DEFAULT_PATH ${HOST_TOOLS_HOME}/usr/share/openocd/scripts)
endif()
8 changes: 8 additions & 0 deletions cmake/Zephyr-sdkConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ get_filename_component(ZEPHYR_SDK_INSTALL_DIR ${CMAKE_CURRENT_LIST_DIR}/.. ABSOL
set(ZEPHYR_SDK_INSTALL_DIR ${ZEPHYR_SDK_INSTALL_DIR})
set(ZEPHYR_TOOLCHAIN_VARIANT zephyr)

# Load additional components. Only components inside Zephyr SDK are allowed.
set(CURRENT_CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH})
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR})
foreach(component ${Zephyr-sdk_FIND_COMPONENTS})
find_package(Zephyr-sdk_${component})
endforeach()
set(CMAKE_MODULE_PATH ${CURRENT_CMAKE_MODULE_PATH})

# Those are CMake package parameters.
set(Zephyr-sdk_FOUND True)
set(Zephyr-sdk_DIR ${ZEPHYR_SDK_INSTALL_DIR})
2 changes: 2 additions & 0 deletions cmake/zephyr/host-tools.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# SPDX-License-Identifier: Apache-2.0

# This file is kept for backward compatibility with Zephyr <v3.2.0

cmake_host_system_information(RESULT TOOLCHAIN_ARCH QUERY OS_PLATFORM)
set(HOST_TOOLS_HOME ${ZEPHYR_SDK_INSTALL_DIR}/sysroots/${TOOLCHAIN_ARCH}-pokysdk-linux)

Expand Down