@@ -11,8 +11,6 @@ if (NOT DEFINED MCUBOOT_TARGET)
11
11
message (FATAL_ERROR "MCUBOOT_TARGET not defined. Please pass -DMCUBOOT_TARGET flag." )
12
12
endif ()
13
13
14
- project (mcuboot_${MCUBOOT_TARGET} )
15
-
16
14
add_definitions (-DMCUBOOT_TARGET=${MCUBOOT_TARGET} )
17
15
add_definitions (-D__ESPRESSIF__=1 )
18
16
@@ -27,6 +25,41 @@ elseif("${MCUBOOT_TARGET}" STREQUAL "esp32c3" OR
27
25
set (MCUBOOT_ARCH "riscv" )
28
26
endif ()
29
27
28
+ if (NOT DEFINED CMAKE_TOOLCHAIN_FILE )
29
+ if (DEFINED TOOLCHAIN_BIN_DIR )
30
+ message ("CMAKE_TOOLCHAIN_FILE not defined, searching for toolchain compiler in TOOLCHAIN_BIN_DIR: ${TOOLCHAIN_BIN_DIR} " )
31
+ set (CMAKE_SYSTEM_NAME Generic )
32
+
33
+ file (GLOB C_COMPILER_BIN "${TOOLCHAIN_BIN_DIR} /*${MCUBOOT_ARCH} *elf-gcc" )
34
+ if (NOT C_COMPILER_BIN )
35
+ message (FATAL_ERROR "No C compiler found. Please ensure that TOOLCHAIN_BIN_DIR directory contains a set of C compiling tools compatible with the target" )
36
+ endif ()
37
+ set (CMAKE_C_COMPILER ${C_COMPILER_BIN} )
38
+ set (CMAKE_ASM_COMPILER ${C_COMPILER_BIN} )
39
+ message ("C compiler found: ${CMAKE_C_COMPILER} " )
40
+
41
+ file (GLOB CXX_COMPILER_BIN "${TOOLCHAIN_BIN_DIR} /*${MCUBOOT_ARCH} *elf-g++" )
42
+ if (NOT CXX_COMPILER_BIN )
43
+ message (FATAL_ERROR "No C++ compiler found. Please ensure that TOOLCHAIN_BIN_DIR directory contains a set of C++ compiling tools compatible with the target" )
44
+ endif ()
45
+ set (CMAKE_CXX_COMPILER ${CXX_COMPILER_BIN} )
46
+ message ("CXX compiler found: ${CMAKE_CXX_COMPILER} " )
47
+ else ()
48
+ # Set toolchain file that expect the same toolchain as IDF sets on PATH
49
+ set (CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_LIST_DIR} /tools/toolchain-${MCUBOOT_TARGET}.cmake )
50
+ message ("No user-defined toolchain, setting default toolchain file: ${CMAKE_TOOLCHAIN_FILE} " )
51
+ endif ()
52
+
53
+ # This flag is needed when redefining a different compiler toolchain at this point
54
+ # on CMakeLists, the reason is that CMake does a compiler testing prior to building
55
+ # that may fail due to cross-compilation
56
+ set (CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY" )
57
+ else ()
58
+ message ("CMAKE_TOOLCHAIN_FILE: ${CMAKE_TOOLCHAIN_FILE} " )
59
+ endif ()
60
+
61
+ project (mcuboot_${MCUBOOT_TARGET} )
62
+
30
63
# Set the minimum revision for each supported chip
31
64
if ("${MCUBOOT_TARGET} " STREQUAL "esp32" )
32
65
set (ESP_MIN_REVISION 3 )
@@ -50,10 +83,12 @@ if (NOT DEFINED ESP_HAL_PATH)
50
83
if (DEFINED ENV{ESP_HAL_PATH} )
51
84
set (ESP_HAL_PATH $ENV{ESP_HAL_PATH} )
52
85
else ()
53
- message (WARNING "ESP_HAL_PATH not found. Please set -DESP_HAL_PATH parameter or define ESP_HAL_PATH environment variable ." )
86
+ message (WARNING "ESP_HAL_PATH not defined, checking if IDF_PATH exists ." )
54
87
if (DEFINED ENV{IDF_PATH} )
55
88
set (ESP_HAL_PATH $ENV{IDF_PATH} )
56
89
message ("IDF installation found in the system, using IDF_PATH as ESP_HAL_PATH." )
90
+ else ()
91
+ message (FATAL_ERROR "Please set -DESP_HAL_PATH parameter or define ESP_HAL_PATH environment variable." )
57
92
endif ()
58
93
endif ()
59
94
endif ()
0 commit comments