]> git.donarmstrong.com Git - kiibohd-controller.git/blob - Bootloader/CMakeLists.txt
Preparing for mk20dx256vlh7
[kiibohd-controller.git] / Bootloader / CMakeLists.txt
1 ###| CMAKE Kiibohd Controller Bootloader |###
2 #
3 # Jacob Alexander 2011-2014
4 # Due to this file's usefulness:
5 #
6 # Released into the Public Domain
7 #
8 # This bootloader is based upon the MCHCK dfu-usb bootloader.
9 # DO NOT USE with Teensy based microcontrollers.
10 #
11 ###
12
13
14
15 ###
16 # Chip Selection
17 #
18
19 #| You _MUST_ set this to match the microcontroller you are trying to compile for
20 #| You _MUST_ clean the build directory if you change this value
21 #|
22 set( CHIP
23         "mk20dx128vlf5"    # McHCK    mk20dx128vlf5
24 #       "mk20dx256vlh7"    # Kiibohd-dfu
25 )
26
27
28 ###
29 # Bootloader Configuration
30 #
31 set ( BOOTLOADER 1 )
32
33
34
35 ###
36 # Compiler Intialization
37 #
38 set ( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/../Lib/CMake )
39 include( initialize )
40
41
42
43 ##
44 # Source Defines
45 #
46 set( SRCS
47         main.c
48         dfu.c
49         dfu.desc.c
50         flash.c
51         kinetis.c
52         usb.c
53 )
54
55 message( STATUS "Bootloader Source Files:" )
56 message( "${SRCS}" )
57
58 #| Add Lib sources to main list
59 foreach( SRC_FILE ${COMPILER_SRCS} )
60         set( SRCS ${SRCS} ${CMAKE_SOURCE_DIR}/../${SRC_FILE} )
61 endforeach()
62
63
64
65
66 ###
67 # Directory Includes
68 #
69 include_directories( ${CMAKE_SOURCE_DIR}/../Lib )
70
71
72
73 ###
74 # Project Description
75 #
76
77 #| Project
78 project( kiibohd_bootloader )
79
80 #| Target Name (output name)
81 set( TARGET kiibohd_bootloader )
82
83 #| General Settings
84 cmake_minimum_required( VERSION 2.8 )
85
86
87
88 ###
89 # Generate Header Files
90 #
91 configure_file( _buildvars.h buildvars.h )
92 include_directories( ${CMAKE_BINARY_DIR} )
93
94
95
96 ###
97 # CMake Module Checking
98 #
99 find_package( Git REQUIRED )
100 find_package( Ctags ) # Optional
101
102
103
104 ###
105 # ctag Generation
106 #
107 if( CTAGS_EXECUTABLE )
108         # Generate the ctags
109         execute_process( COMMAND ctags ${SRCS}
110                 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
111         )
112 endif()
113
114
115
116 ###
117 # Disable -Wl,-search_paths_first for OSX (not supported by arm-none-eabi-gcc)
118 #
119
120 if ( APPLE )
121         string ( REPLACE "-Wl,-search_paths_first" "" CMAKE_C_LINK_FLAGS ${CMAKE_C_LINK_FLAGS} )
122         string ( REPLACE "-Wl,-search_paths_first" "" CMAKE_CXX_LINK_FLAGS ${CMAKE_CXX_LINK_FLAGS} )
123
124         message ( AUTHOR_WARNING "Bootloader binary may not fit on device (must be less than 4096 bytes). Macports arm-none-eabi-gcc 4.7.3 doesn't seem to work properly with -flto. However, even disabling it doesn't shrink the binary enough... 4.9.1 is known to work on Arch Linux." )
125 endif ()
126
127
128
129 ###
130 # Build Targets
131 #
132
133 #| Create the .ELF file
134 set( TARGET_ELF ${TARGET}.elf )
135 add_executable( ${TARGET_ELF} ${SRCS} )
136
137
138 #| .ELF Properties
139 set_target_properties( ${TARGET_ELF} PROPERTIES
140         LINK_FLAGS ${LINKER_FLAGS}
141         SUFFIX ""                               # XXX Force Windows to keep the .exe off
142 )
143
144
145 #| Convert the .ELF into a .bin to load onto the McHCK
146 set( TARGET_BIN ${TARGET}.bin )
147 add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
148         COMMAND ${CMAKE_OBJCOPY} ${BIN_FLAGS} ${TARGET_ELF} ${TARGET_BIN}
149         COMMENT "Creating binary file to load:  ${TARGET_BIN}"
150 )
151
152
153 #| Generate the Extended .LSS
154 set( TARGET_LSS ${TARGET}.lss )
155 add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
156         COMMAND ${CMAKE_OBJDUMP} ${LSS_FLAGS} ${TARGET_ELF} > ${TARGET_LSS}
157         COMMENT "Creating Extended Listing:     ${TARGET_LSS}"
158 )
159
160
161 #| Generate the Symbol Table .SYM
162 set( TARGET_SYM ${TARGET}.sym )
163 add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
164         COMMAND ${CMAKE_NM} -n ${TARGET_ELF} > ${TARGET_SYM}
165         COMMENT "Creating Symbol Table:         ${TARGET_SYM}"
166 )
167
168
169 #| Compiler Selection Record
170 add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
171         COMMAND ${CMAKE_SOURCE_DIR}/../Lib/CMake/writer compiler ${COMPILER_FAMILY}
172 )
173
174
175
176 ###
177 # Size Information
178 #
179
180 #| After Changes Size Information
181 add_custom_target( SizeAfter ALL
182         COMMAND ${CMAKE_SOURCE_DIR}/../Lib/CMake/sizeCalculator ${CMAKE_SIZE} ram   ${TARGET_ELF} ${SIZE_RAM}   " SRAM"
183         COMMAND ${CMAKE_SOURCE_DIR}/../Lib/CMake/sizeCalculator ${CMAKE_SIZE} flash ${TARGET_ELF} ${SIZE_FLASH} "Flash"
184         DEPENDS ${TARGET_ELF}
185         COMMENT "Chip usage for ${CHIP}"
186 )
187