From cb90544a0436ee603109ac61a74f8c486fe3d9ee Mon Sep 17 00:00:00 2001 From: Omar Chebib Date: Thu, 6 Jan 2022 03:17:29 +0000 Subject: [PATCH] Build: fix idf_as_lib example not building --- .../cmake/idf_as_lib/CMakeLists.txt | 15 ++++++++----- .../cmake/idf_as_lib/build-esp32.sh | 5 +---- .../cmake/idf_as_lib/build-esp32c3.sh | 1 + .../cmake/idf_as_lib/build-esp32h2.sh | 1 + .../cmake/idf_as_lib/build-esp32s2.sh | 1 + .../cmake/idf_as_lib/build-esp32s3.sh | 1 + .../cmake/idf_as_lib/build-esp8684.sh | 1 + .../build_system/cmake/idf_as_lib/build.sh | 12 +++++++++- .../cmake/idf_as_lib/run-esp328684.sh | 1 + .../cmake/idf_as_lib/run-esp32c3.sh | 1 + .../cmake/idf_as_lib/run-esp32h2.sh | 1 + .../cmake/idf_as_lib/run-esp32s2.sh | 1 + .../cmake/idf_as_lib/run-esp32s3.sh | 1 + .../cmake/idf_as_lib/run-esp8684.sh | 1 + tools/ci/executable-list.txt | 11 ++++++++++ tools/cmake/toolchain-clang-esp32.cmake | 19 +++++++++++++--- tools/cmake/toolchain-clang-esp32s2.cmake | 22 ++++++++++++++++--- tools/cmake/toolchain-esp32.cmake | 8 ++++++- tools/cmake/toolchain-esp32c3.cmake | 18 ++++++++++----- tools/cmake/toolchain-esp32h2.cmake | 16 +++++++++----- tools/cmake/toolchain-esp32s2.cmake | 8 +++++-- tools/cmake/toolchain-esp32s3.cmake | 7 +++++- tools/cmake/toolchain-esp8684.cmake | 12 +++++++++- tools/cmake/utilities.cmake | 14 ++++++++++++ 24 files changed, 144 insertions(+), 34 deletions(-) mode change 100755 => 120000 examples/build_system/cmake/idf_as_lib/build-esp32.sh create mode 120000 examples/build_system/cmake/idf_as_lib/build-esp32c3.sh create mode 120000 examples/build_system/cmake/idf_as_lib/build-esp32h2.sh create mode 120000 examples/build_system/cmake/idf_as_lib/build-esp32s2.sh create mode 120000 examples/build_system/cmake/idf_as_lib/build-esp32s3.sh create mode 120000 examples/build_system/cmake/idf_as_lib/build-esp8684.sh create mode 120000 examples/build_system/cmake/idf_as_lib/run-esp328684.sh create mode 120000 examples/build_system/cmake/idf_as_lib/run-esp32c3.sh create mode 120000 examples/build_system/cmake/idf_as_lib/run-esp32h2.sh create mode 120000 examples/build_system/cmake/idf_as_lib/run-esp32s2.sh create mode 120000 examples/build_system/cmake/idf_as_lib/run-esp32s3.sh create mode 120000 examples/build_system/cmake/idf_as_lib/run-esp8684.sh diff --git a/examples/build_system/cmake/idf_as_lib/CMakeLists.txt b/examples/build_system/cmake/idf_as_lib/CMakeLists.txt index 0d5ea95b1c..13c8fccab1 100644 --- a/examples/build_system/cmake/idf_as_lib/CMakeLists.txt +++ b/examples/build_system/cmake/idf_as_lib/CMakeLists.txt @@ -2,21 +2,24 @@ cmake_minimum_required(VERSION 3.5) project(idf_as_lib C) -if("${TARGET}" STREQUAL "esp32") +set(targets "esp32" "esp32s2" "esp32s3" "esp32c3" "esp32h2" "esp8684") + +if("${TARGET}" IN_LIST targets) # Include for ESP-IDF build system functions include($ENV{IDF_PATH}/tools/cmake/idf.cmake) - # Create idf::esp32 and idf::freertos static libraries - idf_build_process(esp32 + # Create idf::{target} and idf::freertos static libraries + idf_build_process("${TARGET}" # try and trim the build; additional components # will be included as needed based on dependency tree # # although esptool_py does not generate static library, # processing the component is needed for flashing related # targets and file generation - COMPONENTS esp32 freertos esptool_py + COMPONENTS "${TARGET}" freertos esptool_py SDKCONFIG ${CMAKE_CURRENT_LIST_DIR}/sdkconfig BUILD_DIR ${CMAKE_BINARY_DIR}) else() + message(WARNING "Unknown target ${TARGET}, creating stubs for esp32 instead") # Create stubs for esp32 and freertos, stub::esp32 and stub::freertos add_subdirectory(stubs/esp32) add_subdirectory(stubs/freertos) @@ -29,8 +32,8 @@ set(elf_file ${CMAKE_PROJECT_NAME}.elf) add_executable(${elf_file} main.c) # Link the static libraries to the executable -if("${TARGET}" STREQUAL "esp32") - target_link_libraries(${elf_file} idf::esp32 idf::freertos idf::spi_flash) +if("${TARGET}" IN_LIST targets) + target_link_libraries(${elf_file} "idf::${TARGET}" idf::freertos idf::spi_flash) # Attach additional targets to the executable file for flashing, # linker script generation, partition_table generation, etc. idf_build_executable(${elf_file}) diff --git a/examples/build_system/cmake/idf_as_lib/build-esp32.sh b/examples/build_system/cmake/idf_as_lib/build-esp32.sh deleted file mode 100755 index c30f83226d..0000000000 --- a/examples/build_system/cmake/idf_as_lib/build-esp32.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash -rm -rf build && mkdir build && cd build -cmake .. -DCMAKE_TOOLCHAIN_FILE=$IDF_PATH/tools/cmake/toolchain-esp32.cmake -DTARGET=esp32 -GNinja -cmake --build . diff --git a/examples/build_system/cmake/idf_as_lib/build-esp32.sh b/examples/build_system/cmake/idf_as_lib/build-esp32.sh new file mode 120000 index 0000000000..c07a74de4f --- /dev/null +++ b/examples/build_system/cmake/idf_as_lib/build-esp32.sh @@ -0,0 +1 @@ +build.sh \ No newline at end of file diff --git a/examples/build_system/cmake/idf_as_lib/build-esp32c3.sh b/examples/build_system/cmake/idf_as_lib/build-esp32c3.sh new file mode 120000 index 0000000000..c07a74de4f --- /dev/null +++ b/examples/build_system/cmake/idf_as_lib/build-esp32c3.sh @@ -0,0 +1 @@ +build.sh \ No newline at end of file diff --git a/examples/build_system/cmake/idf_as_lib/build-esp32h2.sh b/examples/build_system/cmake/idf_as_lib/build-esp32h2.sh new file mode 120000 index 0000000000..c07a74de4f --- /dev/null +++ b/examples/build_system/cmake/idf_as_lib/build-esp32h2.sh @@ -0,0 +1 @@ +build.sh \ No newline at end of file diff --git a/examples/build_system/cmake/idf_as_lib/build-esp32s2.sh b/examples/build_system/cmake/idf_as_lib/build-esp32s2.sh new file mode 120000 index 0000000000..c07a74de4f --- /dev/null +++ b/examples/build_system/cmake/idf_as_lib/build-esp32s2.sh @@ -0,0 +1 @@ +build.sh \ No newline at end of file diff --git a/examples/build_system/cmake/idf_as_lib/build-esp32s3.sh b/examples/build_system/cmake/idf_as_lib/build-esp32s3.sh new file mode 120000 index 0000000000..c07a74de4f --- /dev/null +++ b/examples/build_system/cmake/idf_as_lib/build-esp32s3.sh @@ -0,0 +1 @@ +build.sh \ No newline at end of file diff --git a/examples/build_system/cmake/idf_as_lib/build-esp8684.sh b/examples/build_system/cmake/idf_as_lib/build-esp8684.sh new file mode 120000 index 0000000000..c07a74de4f --- /dev/null +++ b/examples/build_system/cmake/idf_as_lib/build-esp8684.sh @@ -0,0 +1 @@ +build.sh \ No newline at end of file diff --git a/examples/build_system/cmake/idf_as_lib/build.sh b/examples/build_system/cmake/idf_as_lib/build.sh index b46f026094..b1c533f810 100755 --- a/examples/build_system/cmake/idf_as_lib/build.sh +++ b/examples/build_system/cmake/idf_as_lib/build.sh @@ -1,4 +1,14 @@ #!/usr/bin/env bash + +# Retrive the target from the current filename, if no target specified, +# the variable will be empty +TARGET=$(echo $0 | cut -s -f2 -d- | cut -s -f1 -d.) +if [[ -n $TARGET ]] +then + # Target is not null, specify the build parameters + PARAM="-DCMAKE_TOOLCHAIN_FILE=$IDF_PATH/tools/cmake/toolchain-${TARGET}.cmake -DTARGET=${TARGET} -GNinja" +fi + rm -rf build && mkdir build && cd build -cmake .. +cmake .. $PARAM cmake --build . diff --git a/examples/build_system/cmake/idf_as_lib/run-esp328684.sh b/examples/build_system/cmake/idf_as_lib/run-esp328684.sh new file mode 120000 index 0000000000..cde8585ed4 --- /dev/null +++ b/examples/build_system/cmake/idf_as_lib/run-esp328684.sh @@ -0,0 +1 @@ +run-esp32.sh \ No newline at end of file diff --git a/examples/build_system/cmake/idf_as_lib/run-esp32c3.sh b/examples/build_system/cmake/idf_as_lib/run-esp32c3.sh new file mode 120000 index 0000000000..cde8585ed4 --- /dev/null +++ b/examples/build_system/cmake/idf_as_lib/run-esp32c3.sh @@ -0,0 +1 @@ +run-esp32.sh \ No newline at end of file diff --git a/examples/build_system/cmake/idf_as_lib/run-esp32h2.sh b/examples/build_system/cmake/idf_as_lib/run-esp32h2.sh new file mode 120000 index 0000000000..cde8585ed4 --- /dev/null +++ b/examples/build_system/cmake/idf_as_lib/run-esp32h2.sh @@ -0,0 +1 @@ +run-esp32.sh \ No newline at end of file diff --git a/examples/build_system/cmake/idf_as_lib/run-esp32s2.sh b/examples/build_system/cmake/idf_as_lib/run-esp32s2.sh new file mode 120000 index 0000000000..cde8585ed4 --- /dev/null +++ b/examples/build_system/cmake/idf_as_lib/run-esp32s2.sh @@ -0,0 +1 @@ +run-esp32.sh \ No newline at end of file diff --git a/examples/build_system/cmake/idf_as_lib/run-esp32s3.sh b/examples/build_system/cmake/idf_as_lib/run-esp32s3.sh new file mode 120000 index 0000000000..cde8585ed4 --- /dev/null +++ b/examples/build_system/cmake/idf_as_lib/run-esp32s3.sh @@ -0,0 +1 @@ +run-esp32.sh \ No newline at end of file diff --git a/examples/build_system/cmake/idf_as_lib/run-esp8684.sh b/examples/build_system/cmake/idf_as_lib/run-esp8684.sh new file mode 120000 index 0000000000..cde8585ed4 --- /dev/null +++ b/examples/build_system/cmake/idf_as_lib/run-esp8684.sh @@ -0,0 +1 @@ +run-esp32.sh \ No newline at end of file diff --git a/tools/ci/executable-list.txt b/tools/ci/executable-list.txt index f18a9743a6..b644447758 100644 --- a/tools/ci/executable-list.txt +++ b/tools/ci/executable-list.txt @@ -26,8 +26,19 @@ components/spiffs/test_spiffsgen/test_spiffsgen.py components/ulp/esp32ulp_mapgen.py docs/check_lang_folder_sync.sh examples/build_system/cmake/idf_as_lib/build-esp32.sh +examples/build_system/cmake/idf_as_lib/build-esp32c3.sh +examples/build_system/cmake/idf_as_lib/build-esp32h2.sh +examples/build_system/cmake/idf_as_lib/build-esp32s2.sh +examples/build_system/cmake/idf_as_lib/build-esp32s3.sh +examples/build_system/cmake/idf_as_lib/build-esp8684.sh examples/build_system/cmake/idf_as_lib/build.sh examples/build_system/cmake/idf_as_lib/run-esp32.sh +examples/build_system/cmake/idf_as_lib/run-esp328684.sh +examples/build_system/cmake/idf_as_lib/run-esp32c3.sh +examples/build_system/cmake/idf_as_lib/run-esp32h2.sh +examples/build_system/cmake/idf_as_lib/run-esp32s2.sh +examples/build_system/cmake/idf_as_lib/run-esp32s3.sh +examples/build_system/cmake/idf_as_lib/run-esp8684.sh examples/build_system/cmake/idf_as_lib/run.sh examples/storage/parttool/parttool_example.py examples/storage/parttool/parttool_example.sh diff --git a/tools/cmake/toolchain-clang-esp32.cmake b/tools/cmake/toolchain-clang-esp32.cmake index 42fdbe15dd..1ed0850436 100644 --- a/tools/cmake/toolchain-clang-esp32.cmake +++ b/tools/cmake/toolchain-clang-esp32.cmake @@ -13,6 +13,19 @@ set(CMAKE_OBJDUMP xtensa-esp32-elf-objdump) # -freestanding is a hack to force Clang to use its own stdatomic.h, # without falling back to the (incompatible) GCC stdatomic.h # https://github.com/espressif/llvm-project/blob/d9341b81/clang/lib/Headers/stdatomic.h#L13-L18 -list(APPEND c_compile_options "--target=xtensa" "-mcpu=esp32" "-ffreestanding") -list(APPEND cxx_compile_options "--target=xtensa" "-mcpu=esp32" "-ffreestanding") -list(APPEND asm_compile_options "--target=xtensa" "-mcpu=esp32") +remove_duplicated_flags("--target=xtensa -mcpu=esp32 -ffreestanding ${CMAKE_C_FLAGS}" + UNIQ_CMAKE_C_FLAGS) +set(CMAKE_C_FLAGS "${UNIQ_CMAKE_C_FLAGS}" + CACHE STRING "C Compiler Base Flags" + FORCE) + +remove_duplicated_flags("--target=xtensa -mcpu=esp32 -ffreestanding ${CMAKE_CXX_FLAGS}" + UNIQ_CMAKE_CXX_FLAGS) +set(CMAKE_CXX_FLAGS "${UNIQ_CMAKE_CXX_FLAGS}" + CACHE STRING "C++ Compiler Base Flags" + FORCE) + +remove_duplicated_flags("--target=xtensa -mcpu=esp32 ${CMAKE_ASM_FLAGS}" UNIQ_CMAKE_ASM_FLAGS) +set(CMAKE_ASM_FLAGS "${UNIQ_CMAKE_ASM_FLAGS}" + CACHE STRING "Assembler Base Flags" + FORCE) diff --git a/tools/cmake/toolchain-clang-esp32s2.cmake b/tools/cmake/toolchain-clang-esp32s2.cmake index 6449ef485e..d5a192d278 100644 --- a/tools/cmake/toolchain-clang-esp32s2.cmake +++ b/tools/cmake/toolchain-clang-esp32s2.cmake @@ -1,3 +1,5 @@ +include($ENV{IDF_PATH}/tools/cmake/utilities.cmake) + set(CMAKE_SYSTEM_NAME Generic) set(CMAKE_C_COMPILER clang) @@ -11,6 +13,20 @@ set(CMAKE_OBJDUMP xtensa-esp32-elf-objdump) # -freestanding is a hack to force Clang to use its own stdatomic.h, # without falling back to the (incompatible) GCC stdatomic.h # https://github.com/espressif/llvm-project/blob/d9341b81/clang/lib/Headers/stdatomic.h#L13-L18 -list(APPEND c_compile_options "--target=xtensa" "-mcpu=esp32s2" "-ffreestanding") -list(APPEND cxx_compile_options "--target=xtensa" "-mcpu=esp32s2" "-ffreestanding") -list(APPEND asm_compile_options "--target=xtensa" "-mcpu=esp32s2") +remove_duplicated_flags("--target=xtensa -mcpu=esp32s2 -ffreestanding ${CMAKE_C_FLAGS}" + UNIQ_CMAKE_C_FLAGS) +set(CMAKE_C_FLAGS "${UNIQ_CMAKE_C_FLAGS}" + CACHE STRING "C Compiler Base Flags" + FORCE) + +remove_duplicated_flags("--target=xtensa -mcpu=esp32s2 -ffreestanding ${CMAKE_CXX_FLAGS}" + UNIQ_CMAKE_CXX_FLAGS) +set(CMAKE_CXX_FLAGS "${UNIQ_CMAKE_CXX_FLAGS}" + CACHE STRING "C++ Compiler Base Flags" + FORCE) + +remove_duplicated_flags("--target=xtensa -mcpu=esp32s2 ${CMAKE_ASM_FLAGS}" + UNIQ_CMAKE_ASM_FLAGS) +set(CMAKE_ASM_FLAGS "${UNIQ_CMAKE_ASM_FLAGS}" + CACHE STRING "Assembler Base Flags" + FORCE) diff --git a/tools/cmake/toolchain-esp32.cmake b/tools/cmake/toolchain-esp32.cmake index 4819486608..d62cfa94cc 100644 --- a/tools/cmake/toolchain-esp32.cmake +++ b/tools/cmake/toolchain-esp32.cmake @@ -1,7 +1,13 @@ +include($ENV{IDF_PATH}/tools/cmake/utilities.cmake) + set(CMAKE_SYSTEM_NAME Generic) set(CMAKE_C_COMPILER xtensa-esp32-elf-gcc) set(CMAKE_CXX_COMPILER xtensa-esp32-elf-g++) set(CMAKE_ASM_COMPILER xtensa-esp32-elf-gcc) -list(APPEND compile_options "-mlongcalls" "-Wno-frame-address") + +remove_duplicated_flags("-mlongcalls -Wno-frame-address ${CMAKE_C_FLAGS}" UNIQ_CMAKE_C_FLAGS) +set(CMAKE_C_FLAGS "${UNIQ_CMAKE_C_FLAGS}" CACHE STRING "C Compiler Base Flags" FORCE) +remove_duplicated_flags("-mlongcalls -Wno-frame-address ${CMAKE_CXX_FLAGS}" UNIQ_CMAKE_CXX_FLAGS) +set(CMAKE_CXX_FLAGS "${UNIQ_CMAKE_CXX_FLAGS}" CACHE STRING "C++ Compiler Base Flags" FORCE) diff --git a/tools/cmake/toolchain-esp32c3.cmake b/tools/cmake/toolchain-esp32c3.cmake index e02cc1b796..c143b073c7 100644 --- a/tools/cmake/toolchain-esp32c3.cmake +++ b/tools/cmake/toolchain-esp32c3.cmake @@ -1,13 +1,19 @@ +include($ENV{IDF_PATH}/tools/cmake/utilities.cmake) + set(CMAKE_SYSTEM_NAME Generic) set(CMAKE_C_COMPILER riscv32-esp-elf-gcc) set(CMAKE_CXX_COMPILER riscv32-esp-elf-g++) set(CMAKE_ASM_COMPILER riscv32-esp-elf-gcc) -list(APPEND compile_options "-march=rv32imc") +remove_duplicated_flags("-march=rv32imc ${CMAKE_C_FLAGS}" + UNIQ_CMAKE_C_FLAGS) +set(CMAKE_C_FLAGS "${UNIQ_CMAKE_C_FLAGS}" CACHE STRING "C Compiler Base Flags" FORCE) +remove_duplicated_flags("-march=rv32imc ${CMAKE_CXX_FLAGS}" + UNIQ_CMAKE_CXX_FLAGS) +set(CMAKE_CXX_FLAGS "${UNIQ_CMAKE_CXX_FLAGS}" CACHE STRING "C++ Compiler Base Flags" FORCE) -# Option `--specs` must only be defined ONCE in the final linker command, else GCC will complain: -# "attempt to rename spec 'link_gcc_c_sequence' to already defined spec 'nosys_link_gcc_c_sequence'" -# so unset `link_options` first. -unset(link_options) -list(APPEND link_options "-nostartfiles" "-march=rv32imc" "--specs=nosys.specs") +remove_duplicated_flags("-nostartfiles -march=rv32imc --specs=nosys.specs \ + ${CMAKE_EXE_LINKER_FLAGS}" + UNIQ_CMAKE_SAFE_EXE_LINKER_FLAGS) +set(CMAKE_EXE_LINKER_FLAGS "${UNIQ_CMAKE_SAFE_EXE_LINKER_FLAGS}" CACHE STRING "Linker Base Flags" FORCE) diff --git a/tools/cmake/toolchain-esp32h2.cmake b/tools/cmake/toolchain-esp32h2.cmake index e02cc1b796..a97ac2d75e 100644 --- a/tools/cmake/toolchain-esp32h2.cmake +++ b/tools/cmake/toolchain-esp32h2.cmake @@ -1,13 +1,17 @@ +include($ENV{IDF_PATH}/tools/cmake/utilities.cmake) + set(CMAKE_SYSTEM_NAME Generic) set(CMAKE_C_COMPILER riscv32-esp-elf-gcc) set(CMAKE_CXX_COMPILER riscv32-esp-elf-g++) set(CMAKE_ASM_COMPILER riscv32-esp-elf-gcc) -list(APPEND compile_options "-march=rv32imc") +remove_duplicated_flags("-march=rv32imc ${CMAKE_C_FLAGS}" UNIQ_CMAKE_C_FLAGS) +set(CMAKE_C_FLAGS "${UNIQ_CMAKE_C_FLAGS}" CACHE STRING "C Compiler Base Flags" FORCE) +remove_duplicated_flags("-march=rv32imc ${CMAKE_CXX_FLAGS}" UNIQ_CMAKE_CXX_FLAGS) +set(CMAKE_CXX_FLAGS "${UNIQ_CMAKE_CXX_FLAGS}" CACHE STRING "C++ Compiler Base Flags" FORCE) -# Option `--specs` must only be defined ONCE in the final linker command, else GCC will complain: -# "attempt to rename spec 'link_gcc_c_sequence' to already defined spec 'nosys_link_gcc_c_sequence'" -# so unset `link_options` first. -unset(link_options) -list(APPEND link_options "-nostartfiles" "-march=rv32imc" "--specs=nosys.specs") +remove_duplicated_flags("-nostartfiles -march=rv32imc --specs=nosys.specs \ + ${CMAKE_EXE_LINKER_FLAGS}" + UNIQ_CMAKE_SAFE_EXE_LINKER_FLAGS) +set(CMAKE_EXE_LINKER_FLAGS "${UNIQ_CMAKE_SAFE_EXE_LINKER_FLAGS}" CACHE STRING "Linker Base Flags" FORCE) diff --git a/tools/cmake/toolchain-esp32s2.cmake b/tools/cmake/toolchain-esp32s2.cmake index 52e7d52857..bc27881436 100644 --- a/tools/cmake/toolchain-esp32s2.cmake +++ b/tools/cmake/toolchain-esp32s2.cmake @@ -1,8 +1,12 @@ +include($ENV{IDF_PATH}/tools/cmake/utilities.cmake) + set(CMAKE_SYSTEM_NAME Generic) set(CMAKE_C_COMPILER xtensa-esp32s2-elf-gcc) set(CMAKE_CXX_COMPILER xtensa-esp32s2-elf-g++) set(CMAKE_ASM_COMPILER xtensa-esp32s2-elf-gcc) - -list(APPEND compile_options "-mlongcalls") +remove_duplicated_flags("-mlongcalls ${CMAKE_C_FLAGS}" UNIQ_CMAKE_C_FLAGS) +set(CMAKE_C_FLAGS "${UNIQ_CMAKE_C_FLAGS}" CACHE STRING "C Compiler Base Flags" FORCE) +remove_duplicated_flags("-mlongcalls ${CMAKE_CXX_FLAGS}" UNIQ_CMAKE_CXX_FLAGS) +set(CMAKE_CXX_FLAGS "${UNIQ_CMAKE_CXX_FLAGS}" CACHE STRING "C++ Compiler Base Flags" FORCE) diff --git a/tools/cmake/toolchain-esp32s3.cmake b/tools/cmake/toolchain-esp32s3.cmake index ff7ea3d6c9..f92c1f837c 100644 --- a/tools/cmake/toolchain-esp32s3.cmake +++ b/tools/cmake/toolchain-esp32s3.cmake @@ -1,7 +1,12 @@ +include($ENV{IDF_PATH}/tools/cmake/utilities.cmake) + set(CMAKE_SYSTEM_NAME Generic) set(CMAKE_C_COMPILER xtensa-esp32s3-elf-gcc) set(CMAKE_CXX_COMPILER xtensa-esp32s3-elf-g++) set(CMAKE_ASM_COMPILER xtensa-esp32s3-elf-gcc) -list(APPEND compile_options "-mlongcalls") +remove_duplicated_flags("-mlongcalls ${CMAKE_C_FLAGS}" UNIQ_CMAKE_C_FLAGS) +set(CMAKE_C_FLAGS "${UNIQ_CMAKE_C_FLAGS}" CACHE STRING "C Compiler Base Flags" FORCE) +remove_duplicated_flags("-mlongcalls ${CMAKE_CXX_FLAGS}" UNIQ_CMAKE_CXX_FLAGS) +set(CMAKE_CXX_FLAGS "${UNIQ_CMAKE_CXX_FLAGS}" CACHE STRING "C++ Compiler Base Flags" FORCE) diff --git a/tools/cmake/toolchain-esp8684.cmake b/tools/cmake/toolchain-esp8684.cmake index 9025a3a82a..a97ac2d75e 100644 --- a/tools/cmake/toolchain-esp8684.cmake +++ b/tools/cmake/toolchain-esp8684.cmake @@ -1,7 +1,17 @@ +include($ENV{IDF_PATH}/tools/cmake/utilities.cmake) + set(CMAKE_SYSTEM_NAME Generic) set(CMAKE_C_COMPILER riscv32-esp-elf-gcc) set(CMAKE_CXX_COMPILER riscv32-esp-elf-g++) set(CMAKE_ASM_COMPILER riscv32-esp-elf-gcc) -list(APPEND compile_options "-march=rv32imc") +remove_duplicated_flags("-march=rv32imc ${CMAKE_C_FLAGS}" UNIQ_CMAKE_C_FLAGS) +set(CMAKE_C_FLAGS "${UNIQ_CMAKE_C_FLAGS}" CACHE STRING "C Compiler Base Flags" FORCE) +remove_duplicated_flags("-march=rv32imc ${CMAKE_CXX_FLAGS}" UNIQ_CMAKE_CXX_FLAGS) +set(CMAKE_CXX_FLAGS "${UNIQ_CMAKE_CXX_FLAGS}" CACHE STRING "C++ Compiler Base Flags" FORCE) + +remove_duplicated_flags("-nostartfiles -march=rv32imc --specs=nosys.specs \ + ${CMAKE_EXE_LINKER_FLAGS}" + UNIQ_CMAKE_SAFE_EXE_LINKER_FLAGS) +set(CMAKE_EXE_LINKER_FLAGS "${UNIQ_CMAKE_SAFE_EXE_LINKER_FLAGS}" CACHE STRING "Linker Base Flags" FORCE) diff --git a/tools/cmake/utilities.cmake b/tools/cmake/utilities.cmake index e4756c67b5..5c53110ee6 100644 --- a/tools/cmake/utilities.cmake +++ b/tools/cmake/utilities.cmake @@ -364,3 +364,17 @@ function(add_deprecated_target_alias old_target new_target) ) add_dependencies(${old_target} ${new_target}) endfunction() + + +# Remove duplicates from a string containing compilation flags +function(remove_duplicated_flags FLAGS UNIQFLAGS) + set(FLAGS_LIST "${FLAGS}") + # Convert the given flags, as a string, into a CMake list type + separate_arguments(FLAGS_LIST) + # Remove all the duplicated flags + list(REMOVE_DUPLICATES FLAGS_LIST) + # Convert the list back to a string + string(REPLACE ";" " " FLAGS_LIST "${FLAGS_LIST}") + # Return that string to the caller + set(${UNIQFLAGS} "${FLAGS_LIST}" PARENT_SCOPE) +endfunction()