1option(PICO_DEOPTIMIZED_DEBUG "Build debug builds with -O0" 0)
2option(PICO_DEBUG_INFO_IN_RELEASE "Include debug info in release builds" 1)
3
4get_property(IS_IN_TRY_COMPILE GLOBAL PROPERTY IN_TRY_COMPILE)
5foreach(LANG IN ITEMS C CXX ASM)
6    set(CMAKE_${LANG}_FLAGS_INIT "${PICO_COMMON_LANG_FLAGS}")
7    unset(CMAKE_${LANG}_FLAGS_DEBUG CACHE)
8    if (PICO_DEOPTIMIZED_DEBUG)
9        set(CMAKE_${LANG}_FLAGS_DEBUG_INIT "-O0")
10    else()
11        set(CMAKE_${LANG}_FLAGS_DEBUG_INIT "-Og")
12    endif()
13    if (PICO_DEBUG_INFO_IN_RELEASE)
14        set(CMAKE_${LANG}_FLAGS_RELEASE_INIT "-g")
15        set(CMAKE_${LANG}_FLAGS_MINSIZEREL_INIT "-g")
16    endif()
17    set(CMAKE_${LANG}_LINK_FLAGS "-Wl,--build-id=none")
18
19    # try_compile is where the feature testing is done, and at that point,
20    # pico_standard_link is not ready to be linked in to provide essential
21    # functions like _exit. So pass -nostdlib so it doesn't link in an exit()
22    # function at all.
23    if(IS_IN_TRY_COMPILE)
24        set(CMAKE_${LANG}_LINK_FLAGS "${CMAKE_${LANG}_LINK_FLAGS} -nostdlib")
25    endif()
26endforeach()
27