summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhathach <[email protected]>2024-04-16 22:17:29 +0700
committerhathach <[email protected]>2024-04-19 23:16:54 +0700
commit7545c40003d5f143cd7cb21037e4dd63b882d7f7 (patch)
tree64e848fdd999e79654e5bdda59e22c00bcb97e30
parent0fb73eac7e058925cebf788f58d9f9f8e823d79b (diff)
cmake detect toolchain based on -DCMAKE_C_COMPILER
-rw-r--r--examples/build_system/cmake/toolchain/arm_iar.cmake14
-rw-r--r--hw/bsp/family_support.cmake19
2 files changed, 28 insertions, 5 deletions
diff --git a/examples/build_system/cmake/toolchain/arm_iar.cmake b/examples/build_system/cmake/toolchain/arm_iar.cmake
index 1482624e5..c22685112 100644
--- a/examples/build_system/cmake/toolchain/arm_iar.cmake
+++ b/examples/build_system/cmake/toolchain/arm_iar.cmake
@@ -1,8 +1,16 @@
set(CMAKE_SYSTEM_NAME Generic)
-set(CMAKE_C_COMPILER "iccarm")
-set(CMAKE_CXX_COMPILER "iccarm")
-set(CMAKE_ASM_COMPILER "iasmarm")
+if (NOT DEFINED CMAKE_C_COMPILER)
+ set(CMAKE_C_COMPILER "iccarm")
+endif()
+
+if (NOT DEFINED CMAKE_CXX_COMPILER)
+ set(CMAKE_CXX_COMPILER "iccarm")
+endif()
+
+if (NOT DEFINED CMAKE_ASM_COMPILER)
+ set(CMAKE_ASM_COMPILER "iasmarm")
+endif()
set(CMAKE_SIZE "size" CACHE FILEPATH "")
set(CMAKE_OBJCOPY "ielftool" CACHE FILEPATH "")
diff --git a/hw/bsp/family_support.cmake b/hw/bsp/family_support.cmake
index d4f355e0c..7f4dda172 100644
--- a/hw/bsp/family_support.cmake
+++ b/hw/bsp/family_support.cmake
@@ -6,12 +6,24 @@ include(CMakePrintHelpers)
set(TOP "${CMAKE_CURRENT_LIST_DIR}/../..")
get_filename_component(TOP ${TOP} ABSOLUTE)
-# Default to gcc
+#-------------------------------------------------------------
+# Toolchain
+# Can be changed via -DTOOLCHAIN=gcc|iar or -DCMAKE_C_COMPILER=
+#-------------------------------------------------------------
+if (DEFINED CMAKE_C_COMPILER)
+ string(FIND ${CMAKE_C_COMPILER} "iccarm" IS_IAR)
+ if (NOT IS_IAR EQUAL -1)
+ set(TOOLCHAIN iar)
+ endif ()
+endif ()
+
if (NOT DEFINED TOOLCHAIN)
set(TOOLCHAIN gcc)
endif ()
-# FAMILY not defined, try to detect it from BOARD
+#-------------------------------------------------------------
+# FAMILY and BOARD
+#-------------------------------------------------------------
if (NOT DEFINED FAMILY)
if (NOT DEFINED BOARD)
message(FATAL_ERROR "You must set a FAMILY variable for the build (e.g. rp2040, espressif).
@@ -74,6 +86,9 @@ set(WARNING_FLAGS_GNU
set(WARNING_FLAGS_IAR "")
+#-------------------------------------------------------------
+# Functions
+#-------------------------------------------------------------
# Filter example based on only.txt and skip.txt
function(family_filter RESULT DIR)