cmake detect toolchain based on -DCMAKE_C_COMPILER

This commit is contained in:
hathach 2024-04-16 22:17:29 +07:00
parent 0fb73eac7e
commit 7545c40003
No known key found for this signature in database
GPG Key ID: 26FAB84F615C3C52
2 changed files with 28 additions and 5 deletions

View File

@ -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 "")

View File

@ -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)