forked from aws/amazon-freertos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PreLoad.cmake
58 lines (52 loc) · 2.17 KB
/
PreLoad.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# Set your compiler path here if it's not in the PATH environment variable.
set(AFR_TOOLCHAIN_PATH "" CACHE INTERNAL "")
# If VENDOR or BOARD is specified, try to find a match.
if(DEFINED VENDOR OR DEFINED BOARD)
include("${CMAKE_CURRENT_LIST_DIR}/tools/cmake/afr_utils.cmake")
set(matched_boards)
afr_get_boards(all_boards)
foreach(board IN LISTS all_boards)
string(REGEX MATCH "${VENDOR}.*\\.${BOARD}.*" match "${board}")
if(match)
list(APPEND matched_boards "${match}")
endif()
endforeach()
list(LENGTH matched_boards size)
if(size EQUAL 0)
message(FATAL_ERROR "No matching board found, please check your VENDOR and BOARD value.")
endif()
if(NOT size EQUAL 1)
list(JOIN matched_boards ", " matched_boards)
message(FATAL_ERROR "Multiple matching boards found: ${matched_boards}")
else()
set(AFR_BOARD "${matched_boards}" CACHE INTERNAL "")
endif()
endif()
# If COMPILER is specified, set toolchain file to ${COMPILER}.cmake.
if(DEFINED COMPILER)
if(DEFINED CMAKE_TOOLCHAIN_FILE)
get_filename_component(toolchain "${CMAKE_TOOLCHAIN_FILE}" NAME_WE)
if(NOT "${COMPILER}" STREQUAL "${toolchain}")
message(WARNING "CMAKE_TOOLCHAIN_FILE is already defined to ${toolchain}.cmake, you\
need to delete cache and reconfigure if you want to switch compiler.")
endif()
else()
set(toolchain_dir "${CMAKE_CURRENT_LIST_DIR}/tools/cmake/toolchains")
set(toolchain_file "${toolchain_dir}/${COMPILER}.cmake")
if(EXISTS "${toolchain_file}")
set(CMAKE_TOOLCHAIN_FILE "${toolchain_file}" CACHE INTERNAL "")
else()
message(FATAL_ERROR "Toolchain file \"${COMPILER}.cmake\" does not exist, please\
select one from \"cmake/toolchains\" folder.")
endif()
endif()
endif()
# Disable compiler checks when only outputing metadata.
if(AFR_METADATA_MODE)
set(CMAKE_C_COMPILER_FORCED TRUE CACHE INTERNAL "")
set(CMAKE_CXX_COMPILER_FORCED TRUE CACHE INTERNAL "")
endif()
# Remove these helper variables from CMake cache.
unset(VENDOR CACHE)
unset(BOARD CACHE)
unset(COMPILER CACHE)