Skip to content

Commit 1bb4e71

Browse files
committed
toolchain: add support Intel oneApi toolchain based on llvm
This adds preliminary support for the oneApi toolchain for X86. The toolchain is available from here: https://software.intel.com/content/www/us/en/develop/tools/oneapi/base-toolkit/download.html Signed-off-by: Anas Nashif <[email protected]>
1 parent 1d949ee commit 1bb4e71

File tree

7 files changed

+133
-2
lines changed

7 files changed

+133
-2
lines changed

cmake/bintools/oneApi/target.cmake

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
if(DEFINED TOOLCHAIN_HOME)
4+
set(find_program_clang_args PATHS ${TOOLCHAIN_HOME} ${ONEAPI_PYTHON_PATH} NO_DEFAULT_PATH)
5+
set(find_program_binutils_args PATHS ${TOOLCHAIN_HOME} )
6+
endif()
7+
8+
find_program(CMAKE_AR llvm-ar ${find_program_clang_args} )
9+
find_program(CMAKE_NM llvm-nm ${find_program_clang_args} )
10+
find_program(CMAKE_OBJDUMP llvm-objdump ${find_program_clang_args} )
11+
find_program(CMAKE_RANLIB llvm-ranlib ${find_program_clang_args} )
12+
find_program(CMAKE_OBJCOPY llvm-objcopy ${find_program_binutils_args})
13+
find_program(CMAKE_READELF readelf ${find_program_binutils_args})
14+
find_program(CMAKE_STRIP llvm-strip ${find_program_binutils_args})
15+
16+
find_program(CMAKE_GDB gdb-oneapi)
17+
18+
# Use the gnu binutil abstraction
19+
include(${ZEPHYR_BASE}/cmake/bintools/llvm/target_bintools.cmake)
20+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
include(${ZEPHYR_BASE}/cmake/compiler/clang/compiler_flags.cmake)

cmake/compiler/icx/generic.cmake

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
if(DEFINED TOOLCHAIN_HOME)
4+
set(find_program_icx_args PATHS ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
5+
endif()
6+
7+
find_program(CMAKE_C_COMPILER icx ${find_program_icx_args})

cmake/compiler/icx/target.cmake

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
# Configuration for host installed oneApi
4+
#
5+
6+
set(NOSTDINC "")
7+
8+
# Note that NOSYSDEF_CFLAG may be an empty string, and
9+
# set_ifndef() does not work with empty string.
10+
if(NOT DEFINED NOSYSDEF_CFLAG)
11+
set(NOSYSDEF_CFLAG -undef)
12+
endif()
13+
14+
if(DEFINED TOOLCHAIN_HOME)
15+
set(find_program_icx_args PATHS ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
16+
endif()
17+
18+
find_program(CMAKE_C_COMPILER icx ${find_program_icx_args})
19+
find_program(CMAKE_CXX_COMPILER clang++ ${find_program_icx_args})
20+
21+
include(${ZEPHYR_BASE}/cmake/gcc-m-cpu.cmake)
22+
23+
foreach(file_name include/stddef.h)
24+
execute_process(
25+
COMMAND ${CMAKE_C_COMPILER} --print-file-name=${file_name}
26+
OUTPUT_VARIABLE _OUTPUT
27+
RESULT_VARIABLE result
28+
)
29+
if(result)
30+
message(FATAL_ERROR "Failed to find required headers.")
31+
endif()
32+
get_filename_component(_OUTPUT "${_OUTPUT}" DIRECTORY)
33+
string(REGEX REPLACE "\n" "" _OUTPUT "${_OUTPUT}")
34+
35+
list(APPEND NOSTDINC ${_OUTPUT})
36+
endforeach()
37+
38+
foreach(isystem_include_dir ${NOSTDINC})
39+
list(APPEND isystem_include_flags -isystem ${isystem_include_dir})
40+
endforeach()
41+
42+
if(CONFIG_64BIT)
43+
string(APPEND TOOLCHAIN_C_FLAGS "-m64")
44+
else()
45+
string(APPEND TOOLCHAIN_C_FLAGS "-m32")
46+
endif()
47+
48+
49+
# This libgcc code is partially duplicated in compiler/*/target.cmake
50+
execute_process(
51+
COMMAND ${CMAKE_C_COMPILER} ${TOOLCHAIN_C_FLAGS} --print-libgcc-file-name
52+
OUTPUT_VARIABLE LIBGCC_FILE_NAME
53+
OUTPUT_STRIP_TRAILING_WHITESPACE
54+
)
55+
56+
get_filename_component(LIBGCC_DIR ${LIBGCC_FILE_NAME} DIRECTORY)
57+
58+
list(APPEND LIB_INCLUDE_DIR "-L\"${LIBGCC_DIR}\"")
59+
if(LIBGCC_DIR)
60+
list(APPEND TOOLCHAIN_LIBS gcc)
61+
endif()
62+
63+
set(CMAKE_REQUIRED_FLAGS -nostartfiles -nostdlib ${isystem_include_flags})
64+
string(REPLACE ";" " " CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
65+
66+
# Load toolchain_cc-family macros
67+
macro(toolchain_cc_nostdinc)
68+
zephyr_compile_options( -nostdinc)
69+
endmacro()

cmake/linker/lld/target.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ macro(configure_linker_script linker_script_gen linker_pass_define)
2020
else()
2121
# TODO: How would the linker script dependencies work for non-linker
2222
# script generators.
23-
message(STATUS "Warning; this generator is not well supported. The
24-
Linker script may not be regenerated when it should.")
23+
message(WARNING "This generator is not well supported. The
24+
Linker script may not be regenerated when it should.")
2525
set(linker_script_dep "")
2626
endif()
2727

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
if($ENV{ONEAPI_ROOT})
4+
set_ifndef(ONEAPI_TOOLCHAIN_PATH "$ENV{ONEAPI_ROOT}")
5+
else()
6+
set_ifndef(ONEAPI_TOOLCHAIN_PATH "$ENV{ONEAPI_TOOLCHAIN_PATH}")
7+
endif()
8+
9+
if(ONEAPI_TOOLCHAIN_PATH)
10+
set(TOOLCHAIN_HOME ${ONEAPI_TOOLCHAIN_PATH}/compiler/latest/linux/bin/)
11+
set(ONEAPI_PYTHON_PATH ${ONEAPI_TOOLCHAIN_PATH}/intelpython/latest/bin)
12+
endif()
13+
14+
set(ONEAPI_TOOLCHAIN_PATH ${ONEAPI_TOOLCHAIN_PATH} CACHE PATH "oneApi install directory")
15+
16+
set(COMPILER icx)
17+
set(LINKER lld)
18+
set(BINTOOLS oneApi)
19+
20+
if(CONFIG_64BIT)
21+
set(triple x86_64-pc-none-elf)
22+
else()
23+
set(triple i686-pc-none-elf)
24+
endif()
25+
26+
set(CMAKE_C_COMPILER_TARGET ${triple})
27+
set(CMAKE_ASM_COMPILER_TARGET ${triple})
28+
set(CMAKE_CXX_COMPILER_TARGET ${triple})
29+
30+
message(STATUS "Found toolchain: host (clang/ld)")
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
# Intentionally left blank.

0 commit comments

Comments
 (0)