1# PICO_CMAKE_CONFIG: PICO_TOOLCHAIN_PATH, Path to search for compiler, default=none (i.e. search system paths), group=build
2set(PICO_TOOLCHAIN_PATH "${PICO_TOOLCHAIN_PATH}" CACHE INTERNAL "")
3
4# Set a default build type if none was specified
5set(default_build_type "Release")
6
7if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
8    message(STATUS "Defaulting build type to '${default_build_type}' since not specified.")
9    set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE STRING "Choose the type of build, options are: 'Debug', 'Release', 'MinSizeRel', 'RelWithDebInfo'." FORCE)
10    # Set the possible values of build type for cmake-gui
11    set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
12            "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
13endif()
14
15if (CMAKE_BUILD_TYPE STREQUAL "Default")
16    error("Default build type is NOT supported")
17endif()
18
19# PICO_CMAKE_CONFIG: PICO_COMPILER, Optionally specifies a different compiler (other than pico_arm_gcc.cmake) - this is not yet fully supported, default=none, group=build
20# If PICO_COMPILER is specified, set toolchain file to ${PICO_COMPILER}.cmake.
21if (DEFINED PICO_COMPILER)
22    if (DEFINED CMAKE_TOOLCHAIN_FILE)
23        get_filename_component(toolchain "${CMAKE_TOOLCHAIN_FILE}" NAME_WE)
24        if (NOT "${PICO_COMPILER}" STREQUAL "${toolchain}")
25            message(WARNING "CMAKE_TOOLCHAIN_FILE is already defined to ${toolchain}.cmake, you\
26                need to delete cache and reconfigure if you want to switch compiler.")
27        endif ()
28    else ()
29        set(toolchain_dir "${CMAKE_CURRENT_LIST_DIR}/preload/toolchains")
30        set(toolchain_file "${toolchain_dir}/${PICO_COMPILER}.cmake")
31        if (EXISTS "${toolchain_file}")
32            set(CMAKE_TOOLCHAIN_FILE "${toolchain_file}" CACHE INTERNAL "")
33        else ()
34            # todo improve message
35            message(FATAL_ERROR "Toolchain file \"${PICO_COMPILER}.cmake\" does not exist, please\
36                select one from \"cmake/toolchains\" folder.")
37        endif ()
38    endif ()
39    message("PICO compiler is ${PICO_COMPILER}")
40endif ()
41
42unset(PICO_COMPILER CACHE)
43
44