diff --git a/Bootloader/CMakeLists.txt b/Bootloader/CMakeLists.txt index be713c0..bc5b7f8 100644 --- a/Bootloader/CMakeLists.txt +++ b/Bootloader/CMakeLists.txt @@ -103,7 +103,7 @@ include_directories ( # #| Project -project ( kiibohd_bootloader ) +project ( kiibohd_bootloader C ) #| Target Name (output name) set ( TARGET kiibohd_bootloader ) @@ -113,6 +113,20 @@ cmake_minimum_required ( VERSION 2.8 ) +### +# Minimum Compiler Version Checks +# + +# Due to optimization requirements, we have to impose a minimum GCC version on the bootloader +set ( BOOTLOADER_MIN_GCC_VERSION "4.9" ) +if ( "${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" ) + if ( CMAKE_C_COMPILER_VERSION VERSION_LESS "${BOOTLOADER_MIN_GCC_VERSION}" ) + message( FATAL_ERROR "arm-none-eabi-gcc ${BOOTLOADER_MIN_GCC_VERSION} or higher is required for bootloader" ) + endif () +endif () + + + ### # CMake Build Env # diff --git a/CMakeLists.txt b/CMakeLists.txt index ec9fb62..1399ec3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,8 +38,8 @@ set( CHIP #| clang does work though #| Currently only arm is supported with clang set( COMPILER - "gcc" # arm-none-eabi-gcc / avr-gcc - Default -# "clang" # arm-none-eabi + "gcc" # arm-none-eabi-gcc / avr-gcc / host-gcc - Default +# "clang" # arm-none-eabi / host CACHE STRING "Compiler Type" ) @@ -48,7 +48,7 @@ set( COMPILER ### # Compiler Intialization # -set ( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/Lib/CMake ) +set( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/Lib/CMake ) include( initialize ) @@ -139,7 +139,7 @@ set( MAIN_SRCS # #| Project -project( kiibohd_controller ) +project( kiibohd_controller C ) #| Target Name (output name) set( TARGET kiibohd ) diff --git a/Lib/CMake/arm.cmake b/Lib/CMake/arm.cmake index 465ae02..fd5eecd 100644 --- a/Lib/CMake/arm.cmake +++ b/Lib/CMake/arm.cmake @@ -10,22 +10,53 @@ ### +### +# Compiler Check +# -#| Set the Compilers (must be set first) -include( CMakeForceCompiler ) -message( STATUS "Compiler Selected:" ) -if ( "${COMPILER}" MATCHES "gcc" ) - cmake_force_c_compiler ( arm-none-eabi-gcc ARMCCompiler ) - cmake_force_cxx_compiler( arm-none-eabi-g++ ARMCxxCompiler ) - set( _CMAKE_TOOLCHAIN_PREFIX arm-none-eabi- ) - message( "gcc" ) -elseif ( "${COMPILER}" MATCHES "clang" ) - cmake_force_c_compiler ( clang ARMCCompiler ) - cmake_force_cxx_compiler( clang++ ARMCxxCompiler ) - set( _CMAKE_TOOLCHAIN_PREFIX llvm- ) - message( "clang" ) +#| +#| In CMake 3.6 a new feature to configure try_compile to work with cross-compilers +#| https://cmake.org/cmake/help/v3.6/variable/CMAKE_TRY_COMPILE_TARGET_TYPE.html#variable:CMAKE_TRY_COMPILE_TARGET_TYPE +#| If we detect CMake 3.6 or higher, use the new method +#| +if ( NOT CMAKE_VERSION VERSION_LESS "3.6" ) + # Prepare for cross-compilation + set( CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY" ) + set( CMAKE_SYSTEM_NAME "Generic" ) + + message( STATUS "Compiler Selected:" ) + if ( "${COMPILER}" MATCHES "gcc" ) + set( CMAKE_C_COMPILER arm-none-eabi-gcc ) + set( _CMAKE_TOOLCHAIN_PREFIX arm-none-eabi- ) + message( "gcc" ) + elseif ( "${COMPILER}" MATCHES "clang" ) + set( CMAKE_C_COMPILER clang ) + set( CMAKE_C_COMPILER_ID ARMCCompiler ) + set( _CMAKE_TOOLCHAIN_PREFIX llvm- ) + message( "clang" ) + else () + message( AUTHOR_WARNING "COMPILER: ${COMPILER} - Unknown compiler selection" ) + endif () + +#| +#| Before CMake 3.6 the cmake_force_c_compiler command was necessary to select cross-compilers +#| and other problemmatic compilers. +#| else () - message( AUTHOR_WARNING "COMPILER: ${COMPILER} - Unknown compiler selection" ) + # Set the Compilers (must be set first) + include( CMakeForceCompiler ) + message( STATUS "Compiler Selected:" ) + if ( "${COMPILER}" MATCHES "gcc" ) + cmake_force_c_compiler( arm-none-eabi-gcc ARMCCompiler ) + set( _CMAKE_TOOLCHAIN_PREFIX arm-none-eabi- ) + message( "gcc" ) + elseif ( "${COMPILER}" MATCHES "clang" ) + cmake_force_c_compiler( clang ARMCCompiler ) + set( _CMAKE_TOOLCHAIN_PREFIX llvm- ) + message( "clang" ) + else () + message( AUTHOR_WARNING "COMPILER: ${COMPILER} - Unknown compiler selection" ) + endif () endif ()