Skip to content

Commit 4816034

Browse files
committed
cmake: Add macOS and Windows host tool support
This commit adds the Zephyr build system support for the host tools included in macOS and Windows Zephyr SDK distributions. Signed-off-by: Stephanos Ioannidis <[email protected]>
1 parent 4c3b80d commit 4816034

File tree

1 file changed

+38
-14
lines changed

1 file changed

+38
-14
lines changed

cmake/zephyr/host-tools.cmake

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,41 @@
11
# SPDX-License-Identifier: Apache-2.0
22

33
cmake_host_system_information(RESULT TOOLCHAIN_ARCH QUERY OS_PLATFORM)
4-
set(HOST_TOOLS_HOME ${ZEPHYR_SDK_INSTALL_DIR}/hosttools/sysroots/${TOOLCHAIN_ARCH}-pokysdk-linux)
5-
6-
# Path used for searching by the find_*() functions, with appropriate
7-
# suffixes added. Ensures that the SDK's host tools will be found when
8-
# we call, e.g. find_program(QEMU qemu-system-x86)
9-
list(APPEND CMAKE_PREFIX_PATH ${HOST_TOOLS_HOME}/usr)
10-
11-
# TODO: Use find_* somehow for these as well?
12-
set_ifndef(QEMU_BIOS ${HOST_TOOLS_HOME}/usr/share/qemu)
13-
if (WIN32)
14-
set_ifndef(OPENOCD_DEFAULT_PATH $ENV{ProgramFiles}/OpenOCD/share/openocd/scripts)
15-
else ()
16-
set_ifndef(OPENOCD_DEFAULT_PATH ${HOST_TOOLS_HOME}/usr/share/openocd/scripts)
17-
endif ()
4+
5+
if(${CMAKE_HOST_SYSTEM_NAME} STREQUAL Linux)
6+
# For Linux SDK, host tool components are built using Yocto and placed into
7+
# the Poky sysroot. The host tool directory layout follows the standard UNIX
8+
# filesystem hierarchy.
9+
set(HOST_TOOLS_HOME ${ZEPHYR_SDK_INSTALL_DIR}/hosttools/sysroots/${TOOLCHAIN_ARCH}-pokysdk-linux)
10+
11+
# Path used for searching by the find_*() functions, with appropriate
12+
# suffixes added. Ensures that the SDK's host tools will be found when
13+
# we call, e.g. find_program(QEMU qemu-system-x86)
14+
list(APPEND CMAKE_PREFIX_PATH ${HOST_TOOLS_HOME}/usr)
15+
16+
set_ifndef(QEMU_BIOS ${HOST_TOOLS_HOME}/usr/share/qemu)
17+
set_ifndef(OPENOCD_DEFAULT_PATH ${HOST_TOOLS_HOME}/usr/share/openocd/scripts)
18+
elseif(${CMAKE_HOST_SYSTEM_NAME} STREQUAL Darwin)
19+
# For macOS SDK, each host tool component is placed in its own directory under
20+
# the 'opt' directory, with all executable binaries symlinked to 'usr/bin'
21+
# directory.
22+
set(HOST_TOOLS_HOME ${ZEPHYR_SDK_INSTALL_DIR}/hosttools)
23+
24+
# Make executable symlinks under 'usr/bin' directory discoverable by the
25+
# find_*() functions.
26+
list(APPEND CMAKE_PREFIX_PATH ${HOST_TOOLS_HOME}/usr)
27+
28+
set_ifndef(QEMU_BIOS ${HOST_TOOLS_HOME}/opt/qemu/share/qemu)
29+
set_ifndef(OPENOCD_DEFAULT_PATH ${HOST_TOOLS_HOME}/opt/openocd/scripts)
30+
elseif(${CMAKE_HOST_SYSTEM_NAME} STREQUAL Windows)
31+
# For Windows SDK, each host tool component is placed in its own directory
32+
# under the host tools home directory.
33+
set(HOST_TOOLS_HOME ${ZEPHYR_SDK_INSTALL_DIR}/hosttools)
34+
35+
# Add host tool component binary directories to the prefix paths for
36+
# discovery by the find_program() function.
37+
list(APPEND CMAKE_PREFIX_PATH ${HOST_TOOLS_HOME}/qemu)
38+
39+
set_ifndef(QEMU_BIOS ${HOST_TOOLS_HOME}/qemu/share)
40+
set_ifndef(OPENOCD_DEFAULT_PATH ${HOST_TOOLS_HOME}/openocd/scripts)
41+
endif()

0 commit comments

Comments
 (0)