Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions cmake/preload/toolchains/pico_riscv_gcc.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
set(CMAKE_SYSTEM_PROCESSOR hazard3)

set(PICO_DEFAULT_GCC_TRIPLE riscv32-unknown-elf riscv32-corev-elf riscv-none-elf)

set(PICO_COMMON_LANG_FLAGS " -march=rv32imac_zicsr_zifencei_zba_zbb_zbs_zbkb -mabi=ilp32")
set(PICO_DEFAULT_GCC_TRIPLE riscv32-pico-elf riscv32-unknown-elf riscv32-corev-elf riscv-none-elf)

# ordered list of preferred flags to support
set(PICO_COMMON_LANG_FLAGS_LIST
" -march=rv32ima_zicsr_zifencei_zba_zbb_zbs_zbkb_zca_zcb_zcmp -mabi=ilp32"
" -march=rv32imac_zicsr_zifencei_zba_zbb_zbs_zbkb -mabi=ilp32")
include(${CMAKE_CURRENT_LIST_DIR}/util/pico_riscv_gcc_common.cmake)
2 changes: 1 addition & 1 deletion cmake/preload/toolchains/pico_riscv_gcc_zcb_zcmp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

set(CMAKE_SYSTEM_PROCESSOR hazard3)

set(PICO_DEFAULT_GCC_TRIPLE riscv32-unknown-elf riscv32-corev-elf riscv-none-elf)
set(PICO_DEFAULT_GCC_TRIPLE riscv32-pico-elf riscv32-unknown-elf riscv32-corev-elf riscv-none-elf)

set(PICO_COMMON_LANG_FLAGS " -march=rv32ima_zicsr_zifencei_zba_zbb_zbs_zbkb_zca_zcb_zcmp -mabi=ilp32")

Expand Down
37 changes: 37 additions & 0 deletions cmake/preload/toolchains/util/find_compiler.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,40 @@ function(pico_find_compiler_with_triples compiler_path triples compiler_suffix)
pico_find_compiler(${compiler_path} "${triples}")
set(${compiler_path} ${${compiler_path}} PARENT_SCOPE)
endfunction()

# If no single compiler flags variable is set, then choose first working compiler flags from a list.
# This is done by doing a test compile via execute_proces, as we can't use check_c_compiler_flag
Comment thread
kilograham marked this conversation as resolved.
Outdated
# prior to project_setup.
# Assuming the single flag variable is not already set, each of the flag_var_list flags are tried in order.
# If the flags don't cause an error the single flag variable is set to the good flag value. If no valid flags
# are found, a fatal error is raised.
function(pico_choose_compiler_flags compiler_path common_lang_flags_var common_lang_flags_var_list)
# simplify logic by not complaining if both set, since CMake calls compiler setup repeatedly
if (NOT ${common_lang_flags_var})
if (${common_lang_flags_var_list})
if(CMAKE_HOST_WIN32)
set(NULL_DEVICE "NUL")
else()
set(NULL_DEVICE "/dev/null")
endif()
foreach(flags IN LISTS ${common_lang_flags_var_list})
separate_arguments(COMPILER_CMD NATIVE_COMMAND "${compiler_path} ${flags} -x c -c ${NULL_DEVICE} -o ${NULL_DEVICE}")
Comment thread
kilograham marked this conversation as resolved.
Outdated
execute_process(
COMMAND ${COMPILER_CMD}
RESULT_VARIABLE COMPILE_FAILED
ERROR_QUIET
)

if (NOT COMPILE_FAILED)
set(${common_lang_flags_var} ${flags} PARENT_SCOPE)
return()
endif()
endforeach()
message(FATAL_ERROR "No compiler that supported required compiler flags")
Comment thread
kilograham marked this conversation as resolved.
Outdated
else()
if (${common_lang_flags_var_list})
message(FATAL_ERROR "Either ${common_lang_flags_var} or ${common_lang_flags_var_list} must be set")
endif()
endif()
endif()
endfunction()
3 changes: 2 additions & 1 deletion cmake/preload/toolchains/util/pico_gcc_common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ include(${CMAKE_CURRENT_LIST_DIR}/find_compiler.cmake)
# include our Platform/PICO.cmake
set(CMAKE_SYSTEM_NAME PICO)

# PICO_CMAKE_CONFIG: PICO_GCC_TRIPLE, List of GCC_TRIPLES -- usually only one -- to try when searching for a compiler. This may be specified as an environment variable, type=string, default=PICO_DEFAULT_GCC_TRIPLE which is set based on PICO_COMPILER, group=pico_base, docref=cmake-toolchain-config
# PICO_CMAKE_CONFIG: PICO_GCC_TRIPLE, List of GCC_TRIPLES -- usually only one -- to try when searching for a compiler. This may be specified as an environment variable, type=string, default=PICO_DEFAULT_GCC_TRIPLE which is set based on PICO_COMPILER, group=pico_base, docref=cmake-toolchain-config
if (NOT PICO_GCC_TRIPLE)
if (DEFINED ENV{_SAVED_PICO_GCC_TRIPLE})
# saved within the same cmake invocation
Expand All @@ -23,6 +23,7 @@ set(ENV{_SAVED_PICO_GCC_TRIPLE} "${PICO_GCC_TRIPLE}")

# Find GCC
pico_find_compiler_with_triples(PICO_COMPILER_CC "${PICO_GCC_TRIPLE}" gcc)
pico_choose_compiler_flags(${PICO_COMPILER_CC} PICO_COMMON_LANG_FLAGS PICO_COMMON_LANG_FLAGS_LIST)
pico_find_compiler_with_triples(PICO_COMPILER_CXX "${PICO_GCC_TRIPLE}" g++)
set(PICO_COMPILER_ASM "${PICO_COMPILER_CC}" CACHE INTERNAL "")
pico_find_compiler_with_triples(PICO_OBJCOPY "${PICO_GCC_TRIPLE}" objcopy)
Expand Down
4 changes: 4 additions & 0 deletions cmake/preload/toolchains/util/set_flags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ option(PICO_DEOPTIMIZED_DEBUG "Build debug builds with -O0" 0)
# PICO_CMAKE_CONFIG: PICO_DEBUG_INFO_IN_RELEASE, Include debug information in release builds, type=bool, default=1, group=build, docref=cmake-toolchain-config
option(PICO_DEBUG_INFO_IN_RELEASE "Include debug info in release builds" 1)

if (NOT PICO_COMMON_LANG_FLAGS)
message(FATAL_ERROR "PICO_COMMON_LANG_FLAGS not set")
endif()

get_property(IS_IN_TRY_COMPILE GLOBAL PROPERTY IN_TRY_COMPILE)
foreach(LANG IN ITEMS C CXX ASM)
set(CMAKE_${LANG}_FLAGS_INIT "${PICO_COMMON_LANG_FLAGS}")
Expand Down
Loading