]> git.donarmstrong.com Git - kiibohd-controller.git/commitdiff
Updating CMake build system to prepare for Teensy 3 integration.
authorJacob Alexander <triplehaata@gmail.com>
Sat, 26 Jan 2013 09:34:33 +0000 (04:34 -0500)
committerJacob Alexander <triplehaata@gmail.com>
Sat, 26 Jan 2013 09:34:33 +0000 (04:34 -0500)
- Tested with the AVR builds
- Partially tested with basic ARM test builds

CMakeLists.txt
arm.cmake [new file with mode: 0644]
avr.cmake [new file with mode: 0644]
buildall.bash
setup.cmake

index 06aaeb6559c00d3d8c78f3847cc8276988845f6d..8f51c8accbf572abbf2b554b469cdb5e02f6cc38 100644 (file)
@@ -1,6 +1,6 @@
 ###| CMAKE Kiibohd Controller |###
 #
-# Written by Jacob Alexander in 2011 for the Kiibohd Controller
+# Jacob Alexander 2011-2013
 # Due to this file's usefulness:
 #
 # Released into the Public Domain
 set( CMAKE_LEGACY_CYGWIN_WIN32 0 )
 set( CMAKE_USE_RELATIVE_PATHS  1 )
 
+#| Add Dependency Macro
+include( AddFileDependencies )
 
-#| Set the Compilers (must be set first)
-include( CMakeForceCompiler )
-cmake_force_c_compiler  ( avr-gcc AVRCCompiler )
-cmake_force_cxx_compiler( avr-g++ AVRCxxCompiler )
 
 
-#| Add Dependency Macro
-include( AddFileDependencies )
+###
+# Compiler Family
+#
+
+#| Specify the compiler family to use
+#| Currently only supports AVR and ARM
+#| "avr"       # Teensy   1.0
+#| "avr"       # Teensy   2.0
+#| "avr"       # Teensy++ 1.0
+#| "avr"       # Teensy++ 2.0
+#| "arm"       # Teensy   3.0
+#set( COMPILER_FAMILY "arm" )
+set( COMPILER_FAMILY "avr" )
+
+
+
+#| Load the compiler family specific configurations
+include( ${COMPILER_FAMILY}.cmake )
+
 
 
 ###
@@ -49,6 +64,7 @@ cmake_minimum_required( VERSION 2.8 )
 include( setup.cmake )
 set( SRCS
        main.c
+       ${COMPILER_SRCS}
        ${SCAN_SRCS}
        ${MACRO_SRCS}
        ${USB_SRCS}
@@ -57,89 +73,6 @@ set( SRCS
 
 
 
-###
-# Atmel Defines and Linker Options
-#
-
-#| MCU Name
-#| You _MUST_ set this to match the board you are using
-#| type "make clean" after changing this, so all files will be rebuilt
-#|
-#| "at90usb162"       # Teensy   1.0
-#| "atmega32u4"       # Teensy   2.0
-#| "at90usb646"       # Teensy++ 1.0
-#| "at90usb1286"      # Teensy++ 2.0
-#set( MCU "atmega32u4" )
-set( MCU "at90usb1286" )
-
-
-#| Compiler flag to set the C Standard level.
-#|     c89   = "ANSI" C
-#|     gnu89 = c89 plus GCC extensions
-#|     c99   = ISO C99 standard (not yet fully implemented)
-#|     gnu99 = c99 plus GCC extensions
-set( CSTANDARD "-std=gnu99" )
-
-
-#| Warning Options
-#|  -Wall...:     warning level
-set( WARN "-Wall -Wstrict-prototypes" )
-
-
-#| Tuning Options
-#|  -f...:        tuning, see GCC manual and avr-libc documentation
-set( TUNING "-funsigned-char -funsigned-bitfields -ffunction-sections -fpack-struct -fshort-enums" )
-
-
-#| Optimization level, can be [0, 1, 2, 3, s]. 
-#|     0 = turn off optimization. s = optimize for size.
-#|     (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
-set( OPT "s" )
-
-
-#| Output Format
-#| srec, ihex, binary
-set( FORMAT "ihex" )
-
-
-#| Processor frequency.
-#|   Normally the first thing your program should do is set the clock prescaler,
-#|   so your program will run at the correct speed.  You should also set this
-#|   variable to same clock speed.  The _delay_ms() macro uses this, and many
-#|   examples use this variable to calculate timings.  Do not add a "UL" here.
-set( F_CPU "16000000" )
-
-
-#| Dependency Files
-#| Compiler flags to generate dependency files.
-set( GENDEPFLAGS "-MMD -MP" )
-
-
-#| Listing file
-set( TARGET_LST ${TARGET}.lst )
-
-
-#| Compiler Flags
-add_definitions( "-mmcu=${MCU} -DF_CPU=${F_CPU} -O${OPT} ${TUNING} ${WARN} ${CSTANDARD} ${GENDEPFLAGS}" )
-
-
-#| Linker Flags
-set( LINKER_FLAGS "-mmcu=${MCU} -Wl,-Map=${TARGET}.map,--cref -Wl,--relax -Wl,--gc-sections" )
-
-
-#| Hex Flags (XXX, CMake seems to have issues if you quote the arguments for the custom commands...)
-set( HEX_FLAGS -O ${FORMAT} -R .eeprom -R .fuse -R .lock -R .signature )
-
-
-#| Eep Flags
-set( EEP_FLAGS -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 --no-change-warnings -O ${FORMAT} )
-
-
-#| Lss Flags
-set( LSS_FLAGS -h -S -z )
-
-
-
 ###
 # Build Targets
 #
@@ -159,23 +92,15 @@ set_target_properties( ${TARGET_ELF} PROPERTIES
 #| Convert the .ELF into a .HEX to load onto the Teensy
 set( TARGET_HEX ${TARGET}.hex )
 add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
-       COMMAND avr-objcopy ${HEX_FLAGS} ${TARGET_ELF} ${TARGET_HEX}
+       COMMAND ${OBJCOPY} ${HEX_FLAGS} ${TARGET_ELF} ${TARGET_HEX}
        COMMENT "Creating load file for Flash:  ${TARGET_HEX}"
 )
 
 
-#| Convert the .ELF into a .EEP
-set( TARGET_EEP ${TARGET}.eep )
-add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
-       COMMAND avr-objcopy ${EEP_FLAGS} ${TARGET_ELF} ${TARGET_EEP}
-       COMMENT "Creating load file for EEPROM: ${TARGET_EEP}"
-)
-
-
 #| Generate the Extended .LSS
 set( TARGET_LSS ${TARGET}.lss )
 add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
-       COMMAND avr-objdump ${LSS_FLAGS} ${TARGET_ELF} > ${TARGET_LSS}
+       COMMAND ${OBJDUMP} ${LSS_FLAGS} ${TARGET_ELF} > ${TARGET_LSS}
        COMMENT "Creating Extended Listing:     ${TARGET_LSS}"
 )
 
@@ -183,7 +108,7 @@ add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
 #| Generate the Symbol Table .SYM
 set( TARGET_SYM ${TARGET}.sym )
 add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
-       COMMAND avr-nm -n ${TARGET_ELF} > ${TARGET_SYM}
+       COMMAND ${NM} -n ${TARGET_ELF} > ${TARGET_SYM}
        COMMENT "Creating Symbol Table:         ${TARGET_SYM}"
 )
 
@@ -194,7 +119,7 @@ add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
 #
 
 #| After Changes Size Information
-add_custom_target( SizeAfter ALL avr-size --target=${FORMAT} ${TARGET_HEX} ${TARGET_ELF}
+add_custom_target( SizeAfter ALL ${SIZE} --target=${FORMAT} ${TARGET_HEX} ${TARGET_ELF}
        DEPENDS ${TARGET_ELF}
        COMMENT "Size after generation:"
 )
diff --git a/arm.cmake b/arm.cmake
new file mode 100644 (file)
index 0000000..1b6a8ce
--- /dev/null
+++ b/arm.cmake
@@ -0,0 +1,111 @@
+###| CMAKE Kiibohd Controller |###
+#
+# Jacob Alexander 2011-2013
+# Due to this file's usefulness:
+#
+# Released into the Public Domain
+#
+# Freescale ARM CMake Build Configuration
+#
+###
+
+
+
+#| Set the Compilers (must be set first)
+include( CMakeForceCompiler )
+cmake_force_c_compiler  ( arm-none-eabi-gcc AVRCCompiler )
+cmake_force_cxx_compiler( arm-none-eabi-g++ AVRCxxCompiler )
+
+
+#| Compiler Binaries
+set( OBJCOPY "arm-none-eabi-objcopy" )
+set( OBJDUMP "arm-none-eabi-objdump" )
+set( NM      "arm-none-eabi-nm"      )
+set( SIZE    "arm-none-eabi-size"    )
+
+
+
+###
+# ARM Defines and Linker Options
+#
+
+#| Chip Name (Linker)
+#| You _MUST_ set this to match the board you are using
+#| type "make clean" after changing this, so all files will be rebuilt
+#|
+#| "mk20dx128"        # Teensy   3.0
+set( CHIP "mk20dx128" )
+
+
+#| CPU Type
+#| You _MUST_ set this to match the board you are using
+#| type "make clean" after changing this, so all files will be rebuilt
+#|
+#| "cortex-m4"        # Teensy   3.0
+set( CPU "cortex-m4" )
+
+
+#| Extra Compiler Sources
+#| Mostly for convenience functions like interrupt handlers
+set( COMPILER_SRCS
+       Lib/${CHIP}.c
+)
+
+
+#| Compiler flag to set the C Standard level.
+#|     c89   = "ANSI" C
+#|     gnu89 = c89 plus GCC extensions
+#|     c99   = ISO C99 standard (not yet fully implemented)
+#|     gnu99 = c99 plus GCC extensions
+set( CSTANDARD "-std=gnu99" )
+
+
+#| Warning Options
+#|  -Wall...:     warning level
+set( WARN "-Wall -g" )
+
+
+#| Tuning Options
+#|  -f...:        tuning, see GCC manual
+set( TUNING "-mthumb -nostdlib" )
+
+
+#| Optimization level, can be [0, 1, 2, 3, s]. 
+#|     0 = turn off optimization. s = optimize for size.
+#|     (Note: 3 is not always the best optimization level.)
+set( OPT "s" )
+
+
+#| Output Format
+#| srec, ihex, binary
+set( FORMAT "ihex" )
+
+
+#| Processor frequency.
+#|   Normally the first thing your program should do is set the clock prescaler,
+#|   so your program will run at the correct speed.  You should also set this
+#|   variable to same clock speed.  The _delay_ms() macro uses this, and many
+#|   examples use this variable to calculate timings.  Do not add a "UL" here.
+set( F_CPU "48000000" )
+
+
+#| Dependency Files
+#| Compiler flags to generate dependency files.
+set( GENDEPFLAGS "-MMD" )
+
+
+#| Compiler Flags
+add_definitions( "-mcpu=${CPU} -DF_CPU=${F_CPU} -O${OPT} ${TUNING} ${WARN} ${CSTANDARD} ${GENDEPFLAGS}" )
+
+
+#| Linker Flags
+set( LINKER_FLAGS "-mcpu=${CPU} -Wl,-Map=${TARGET}.map,--cref -Wl,--gc-sections -mthumb -T${CMAKE_CURRENT_SOURCE_DIR}/Lib/${CHIP}.ld" )
+
+
+#| Hex Flags (XXX, CMake seems to have issues if you quote the arguments for the custom commands...)
+set( HEX_FLAGS -O ${FORMAT} -R .eeprom )
+
+
+#| Lss Flags
+set( LSS_FLAGS -h -S -z )
+
diff --git a/avr.cmake b/avr.cmake
new file mode 100644 (file)
index 0000000..7b0a178
--- /dev/null
+++ b/avr.cmake
@@ -0,0 +1,111 @@
+###| CMAKE Kiibohd Controller |###
+#
+# Jacob Alexander 2011-2013
+# Due to this file's usefulness:
+#
+# Released into the Public Domain
+#
+# avr-gcc CMake Build Configuration
+#
+###
+
+
+
+#| Set the Compilers (must be set first)
+include( CMakeForceCompiler )
+cmake_force_c_compiler  ( avr-gcc AVRCCompiler )
+cmake_force_cxx_compiler( avr-g++ AVRCxxCompiler )
+
+
+#| Compiler Binaries
+set( OBJCOPY "avr-objcopy" )
+set( OBJDUMP "avr-objdump" )
+set( NM      "avr-nm"      )
+set( SIZE    "avr-size"    )
+
+
+
+###
+# Atmel Defines and Linker Options
+#
+
+#| MCU Name
+#| You _MUST_ set this to match the board you are using
+#| type "make clean" after changing this, so all files will be rebuilt
+#|
+#| "at90usb162"       # Teensy   1.0
+#| "atmega32u4"       # Teensy   2.0
+#| "at90usb646"       # Teensy++ 1.0
+#| "at90usb1286"      # Teensy++ 2.0
+#set( MCU "atmega32u4" )
+set( MCU "at90usb1286" )
+
+
+#| Extra Compiler Sources
+#| Mostly for convenience functions like interrupt handlers
+set( COMPILER_SRCS
+       # XXX Not needed for avr-gcc
+)
+
+
+#| Compiler flag to set the C Standard level.
+#|     c89   = "ANSI" C
+#|     gnu89 = c89 plus GCC extensions
+#|     c99   = ISO C99 standard (not yet fully implemented)
+#|     gnu99 = c99 plus GCC extensions
+set( CSTANDARD "-std=gnu99" )
+
+
+#| Warning Options
+#|  -Wall...:     warning level
+set( WARN "-Wall -Wstrict-prototypes" )
+
+
+#| Tuning Options
+#|  -f...:        tuning, see GCC manual and avr-libc documentation
+set( TUNING "-funsigned-char -funsigned-bitfields -ffunction-sections -fpack-struct -fshort-enums" )
+
+
+#| Optimization level, can be [0, 1, 2, 3, s]. 
+#|     0 = turn off optimization. s = optimize for size.
+#|     (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
+set( OPT "s" )
+
+
+#| Output Format
+#| srec, ihex, binary
+set( FORMAT "ihex" )
+
+
+#| Processor frequency.
+#|   Normally the first thing your program should do is set the clock prescaler,
+#|   so your program will run at the correct speed.  You should also set this
+#|   variable to same clock speed.  The _delay_ms() macro uses this, and many
+#|   examples use this variable to calculate timings.  Do not add a "UL" here.
+set( F_CPU "16000000" )
+
+
+#| Dependency Files
+#| Compiler flags to generate dependency files.
+set( GENDEPFLAGS "-MMD -MP" )
+
+
+#| Compiler Flags
+add_definitions( "-mmcu=${MCU} -DF_CPU=${F_CPU} -O${OPT} ${TUNING} ${WARN} ${CSTANDARD} ${GENDEPFLAGS}" )
+
+
+#| Linker Flags
+set( LINKER_FLAGS "-mmcu=${MCU} -Wl,-Map=${TARGET}.map,--cref -Wl,--relax -Wl,--gc-sections" )
+
+
+#| Hex Flags (XXX, CMake seems to have issues if you quote the arguments for the custom commands...)
+set( HEX_FLAGS -O ${FORMAT} -R .eeprom -R .fuse -R .lock -R .signature )
+
+
+#| Eep Flags
+set( EEP_FLAGS -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 --no-change-warnings -O ${FORMAT} )
+
+
+#| Lss Flags
+set( LSS_FLAGS -h -S -z )
+
index 410460f17834cbaa63eb0bbe9c117c2c8149eb2f..8f24726582cebdb9ff5abe2e40ae86740914c373 100755 (executable)
@@ -40,7 +40,7 @@ main() {
                cmake -DScanModuleOverride=$module ../.. && make || let failCount++
 
                # Cleanup, for the next build
-               cd -
+               cd - > /dev/null
        done
 
        totalModules=$(echo $scanModules | wc -w)
index 79ede575d4d046cddeac7720ec86157d197de2c2..b56c5814e5317753259b2528007c58106775f180 100644 (file)
@@ -37,9 +37,9 @@ set( DebugModule  "full"   )
 ###
 # Module Overrides (Used in the buildall.bash script)
 #
-if ( EXISTS ${PROJECT_SOURCE_DIR}/Scan/${ScanModuleOverride} )
+if ( ( DEFINED ${ScanModuleOverride} ) AND ( EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/Scan/${ScanModuleOverride} ) )
        set( ScanModule ${ScanModuleOverride} )
-endif ( EXISTS ${PROJECT_SOURCE_DIR}/Scan/${ScanModuleOverride} )
+endif ( ( DEFINED ${ScanModuleOverride} ) AND ( EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/Scan/${ScanModuleOverride} ) )
 
 
 
@@ -52,7 +52,7 @@ set(   USBModulePath   "USB/${USBModule}"   )
 set( DebugModulePath "Debug/${DebugModule}" )
 
 #| Top-level directory adjustment
-set( HEAD_DIR "${PROJECT_SOURCE_DIR}" )
+set( HEAD_DIR "${CMAKE_CURRENT_SOURCE_DIR}" )