Browse Source

Fixing CMake 3.6 deprecation message

- CMake 3.6 finally adds proper cross-compiler detection
- When detected, use full compiler detection infrastructure
- Still maintains compatibility back to CMake 2.8 (at least for now)
- With new detection, selecting only the C compiler as it speeds up the CMake generaion process
- Added a GCC 4.9 minimum version requirement for Bootloader
master
Jacob Alexander 7 years ago
parent
commit
9cc29cbffc
3 changed files with 64 additions and 19 deletions
  1. 15
    1
      Bootloader/CMakeLists.txt
  2. 4
    4
      CMakeLists.txt
  3. 45
    14
      Lib/CMake/arm.cmake

+ 15
- 1
Bootloader/CMakeLists.txt View File

# #


#| Project #| Project
project ( kiibohd_bootloader )
project ( kiibohd_bootloader C )


#| Target Name (output name) #| Target Name (output name)
set ( TARGET kiibohd_bootloader ) set ( TARGET kiibohd_bootloader )






###
# 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 # CMake Build Env
# #

+ 4
- 4
CMakeLists.txt View File

#| clang does work though #| clang does work though
#| Currently only arm is supported with clang #| Currently only arm is supported with clang
set( COMPILER 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" CACHE STRING "Compiler Type"
) )


### ###
# Compiler Intialization # 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 ) include( initialize )




# #


#| Project #| Project
project( kiibohd_controller )
project( kiibohd_controller C )


#| Target Name (output name) #| Target Name (output name)
set( TARGET kiibohd ) set( TARGET kiibohd )

+ 45
- 14
Lib/CMake/arm.cmake View File

### ###




###
# 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 () 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 () endif ()