Re-enable compiler checks (#1097)

Add a -nostdlib specifically for the check to ensure that it builds
successfully.

The -nostdlib isn't needed normally, because linking against the pico
SDK will add in definitions for the previously-missing function
diff --git a/cmake/preload/toolchains/pico_arm_clang.cmake b/cmake/preload/toolchains/pico_arm_clang.cmake
index 1d2c4eb..d06d77e 100644
--- a/cmake/preload/toolchains/pico_arm_clang.cmake
+++ b/cmake/preload/toolchains/pico_arm_clang.cmake
@@ -27,10 +27,6 @@
 set(CMAKE_OBJCOPY ${PICO_OBJCOPY} CACHE FILEPATH "")
 set(CMAKE_OBJDUMP ${PICO_OBJDUMP} CACHE FILEPATH "")
 
-# Disable compiler checks.
-set(CMAKE_C_COMPILER_FORCED TRUE)
-set(CMAKE_CXX_COMPILER_FORCED TRUE)
-
 # Add target system root to cmake find path.
 get_filename_component(PICO_COMPILER_DIR "${PICO_COMPILER_CC}" DIRECTORY)
 get_filename_component(CMAKE_FIND_ROOT_PATH "${PICO_COMPILER_DIR}" DIRECTORY)
@@ -43,11 +39,7 @@
 
 include_directories(/usr/include/newlib)
 
-# todo move to platform/Generix-xxx
-set(ARM_CLANG_COMMON_FLAGS " --target=arm-none-eabi -mcpu=cortex-m0plus -mthumb")
-set(CMAKE_C_FLAGS_INIT "${ARM_CLANG_COMMON_FLAGS}")
-set(CMAKE_CXX_FLAGS_INIT "${ARM_CLANG_COMMON_FLAGS}")
-set(CMAKE_ASM_FLAGS_INIT "${ARM_CLANG_COMMON_FLAGS}")
-set(CMAKE_C_FLAGS_DEBUG_INIT "${ARM_CLANG_COMMON_FLAGS} -Og")
-set(CMAKE_CXX_FLAGS_DEBUG_INIT "${ARM_CLANG_COMMON_FLAGS} -Og")
+option(PICO_DEOPTIMIZED_DEBUG "Build debug builds with -O0" 0)
 
+set(ARM_TOOLCHAIN_COMMON_FLAGS " --target=arm-none-eabi -mcpu=cortex-m0plus -mthumb")
+include(${CMAKE_CURRENT_LIST_DIR}/set_flags.cmake)
diff --git a/cmake/preload/toolchains/pico_arm_clang_arm.cmake b/cmake/preload/toolchains/pico_arm_clang_arm.cmake
index 50fabbc..b943f1b 100644
--- a/cmake/preload/toolchains/pico_arm_clang_arm.cmake
+++ b/cmake/preload/toolchains/pico_arm_clang_arm.cmake
@@ -27,10 +27,6 @@
 set(CMAKE_OBJCOPY ${PICO_OBJCOPY} CACHE FILEPATH "")
 set(CMAKE_OBJDUMP ${PICO_OBJDUMP} CACHE FILEPATH "")
 
-# Disable compiler checks.
-set(CMAKE_C_COMPILER_FORCED TRUE)
-set(CMAKE_CXX_COMPILER_FORCED TRUE)
-
 # Add target system root to cmake find path.
 get_filename_component(PICO_COMPILER_DIR "${PICO_COMPILER_CC}" DIRECTORY)
 get_filename_component(CMAKE_FIND_ROOT_PATH "${PICO_COMPILER_DIR}" DIRECTORY)
@@ -41,12 +37,7 @@
 set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
 set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
 
-# todo move to platform/Generix-xxx
-set(ARM_CLANG_COMMON_FLAGS " --cpu=Cortex-M0plus")
-string(APPEND CMAKE_C_FLAGS_INIT "${ARM_CLANG_COMMON_FLAGS}")
-string(APPEND CMAKE_CXX_FLAGS_INIT "${ARM_CLANG_COMMON_FLAGS}")
-string(APPEND CMAKE_ASM_FLAGS_INIT "${ARM_CLANG_COMMON_FLAGS}")
-string(APPEND CMAKE_C_FLAGS_DEBUG_INIT "${ARM_CLANG_COMMON_FLAGS} -Og")
-string(APPEND CMAKE_CXX_FLAGS_DEBUG_INIT "${ARM_CLANG_COMMON_FLAGS} -Og")
+option(PICO_DEOPTIMIZED_DEBUG "Build debug builds with -O0" 0)
 
-
+set(ARM_TOOLCHAIN_COMMON_FLAGS " --cpu=Cortex-M0plus")
+include(${CMAKE_CURRENT_LIST_DIR}/set_flags.cmake)
diff --git a/cmake/preload/toolchains/pico_arm_gcc.cmake b/cmake/preload/toolchains/pico_arm_gcc.cmake
index d8c56fc..ad5d33f 100644
--- a/cmake/preload/toolchains/pico_arm_gcc.cmake
+++ b/cmake/preload/toolchains/pico_arm_gcc.cmake
@@ -35,10 +35,6 @@
 set(CMAKE_OBJCOPY ${PICO_OBJCOPY} CACHE FILEPATH "")
 set(CMAKE_OBJDUMP ${PICO_OBJDUMP} CACHE FILEPATH "")
 
-# Disable compiler checks.
-set(CMAKE_C_COMPILER_FORCED TRUE)
-set(CMAKE_CXX_COMPILER_FORCED TRUE)
-
 # Add target system root to cmake find path.
 get_filename_component(PICO_COMPILER_DIR "${PICO_COMPILER_CC}" DIRECTORY)
 get_filename_component(CMAKE_FIND_ROOT_PATH "${PICO_COMPILER_DIR}" DIRECTORY)
@@ -51,17 +47,6 @@
 
 option(PICO_DEOPTIMIZED_DEBUG "Build debug builds with -O0" 0)
 
-# todo move to platform/Generix-xxx
-
 # on ARM -mcpu should not be mixed with -march
-set(ARM_GCC_COMMON_FLAGS " -mcpu=cortex-m0plus -mthumb")
-foreach(LANG IN ITEMS C CXX ASM)
-    set(CMAKE_${LANG}_FLAGS_INIT "${ARM_GCC_COMMON_FLAGS}")
-    if (PICO_DEOPTIMIZED_DEBUG)
-        set(CMAKE_${LANG}_FLAGS_DEBUG_INIT "-O0")
-    else()
-        set(CMAKE_${LANG}_FLAGS_DEBUG_INIT "-Og")
-    endif()
-    set(CMAKE_${LANG}_LINK_FLAGS "-Wl,--build-id=none")
-endforeach()
-
+set(ARM_TOOLCHAIN_COMMON_FLAGS " -mcpu=cortex-m0plus -mthumb")
+include(${CMAKE_CURRENT_LIST_DIR}/set_flags.cmake)
diff --git a/cmake/preload/toolchains/set_flags.cmake b/cmake/preload/toolchains/set_flags.cmake
new file mode 100644
index 0000000..bd6e240
--- /dev/null
+++ b/cmake/preload/toolchains/set_flags.cmake
@@ -0,0 +1,19 @@
+
+get_property(IS_IN_TRY_COMPILE GLOBAL PROPERTY IN_TRY_COMPILE)
+foreach(LANG IN ITEMS C CXX ASM)
+    set(CMAKE_${LANG}_FLAGS_INIT "${ARM_TOOLCHAIN_COMMON_FLAGS}")
+    if (PICO_DEOPTIMIZED_DEBUG)
+        set(CMAKE_${LANG}_FLAGS_DEBUG_INIT "-O0")
+    else()
+        set(CMAKE_${LANG}_FLAGS_DEBUG_INIT "-Og")
+    endif()
+    set(CMAKE_${LANG}_LINK_FLAGS "-Wl,--build-id=none")
+
+    # try_compile is where the feature testing is done, and at that point,
+    # pico_standard_link is not ready to be linked in to provide essential
+    # functions like _exit. So pass -nostdlib so it doesn't link in an exit()
+    # function at all.
+    if(IS_IN_TRY_COMPILE)
+        set(CMAKE_${LANG}_LINK_FLAGS "${CMAKE_${LANG}_LINK_FLAGS} -nostdlib")
+    endif()
+endforeach()