]> git.donarmstrong.com Git - kiibohd-controller.git/blob - Bootloader/CMakeLists.txt
Fixing Mac OSX arm build options.
[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 )
25
26
27 ###
28 # Bootloader Configuration
29 #
30 set ( BOOTLOADER 1 )
31
32
33
34 ###
35 # Compiler Intialization
36 #
37 set ( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/../Lib/CMake )
38 include( initialize )
39
40
41
42 ##
43 # Source Defines
44 #
45 set( SRCS
46         main.c
47         dfu.c
48         dfu.desc.c
49         flash.c
50         kinetis.c
51         usb.c
52 )
53
54 message( STATUS "Bootloader Source Files:" )
55 message( "${SRCS}" )
56
57 #| Add Lib sources to main list
58 foreach( SRC_FILE ${COMPILER_SRCS} )
59         set( SRCS ${SRCS} ${CMAKE_SOURCE_DIR}/../${SRC_FILE} )
60 endforeach()
61
62
63
64
65 ###
66 # Directory Includes
67 #
68 include_directories( ${CMAKE_SOURCE_DIR}/../Lib )
69
70
71
72 ###
73 # Project Description
74 #
75
76 #| Project
77 project( kiibohd_bootloader )
78
79 #| Target Name (output name)
80 set( TARGET kiibohd_bootloader )
81
82 #| General Settings
83 cmake_minimum_required( VERSION 2.8 )
84
85
86
87 ###
88 # Generate Header Files
89 #
90 configure_file( _buildvars.h buildvars.h )
91 include_directories( ${CMAKE_BINARY_DIR} )
92
93
94
95 ###
96 # CMake Module Checking
97 #
98 find_package( Git REQUIRED )
99 find_package( Ctags ) # Optional
100
101
102
103 ###
104 # ctag Generation
105 #
106 if( CTAGS_EXECUTABLE )
107         # Generate the ctags
108         execute_process( COMMAND ctags ${SRCS}
109                 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
110         )
111 endif()
112
113
114
115 ###
116 # Disable -Wl,-search_paths_first for OSX (not supported by arm-none-eabi-gcc)
117 #
118
119 if ( APPLE )
120         string ( REPLACE "-Wl,-search_paths_first" "" CMAKE_C_LINK_FLAGS ${CMAKE_C_LINK_FLAGS} )
121         string ( REPLACE "-Wl,-search_paths_first" "" CMAKE_CXX_LINK_FLAGS ${CMAKE_CXX_LINK_FLAGS} )
122
123         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." )
124 endif ()
125
126
127
128 ###
129 # Build Targets
130 #
131
132 #| Create the .ELF file
133 set( TARGET_ELF ${TARGET}.elf )
134 add_executable( ${TARGET_ELF} ${SRCS} )
135
136
137 #| .ELF Properties
138 set_target_properties( ${TARGET_ELF} PROPERTIES
139         LINK_FLAGS ${LINKER_FLAGS}
140         SUFFIX ""                               # XXX Force Windows to keep the .exe off
141 )
142
143
144 #| Convert the .ELF into a .bin to load onto the McHCK
145 set( TARGET_BIN ${TARGET}.bin )
146 add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
147         COMMAND ${CMAKE_OBJCOPY} ${BIN_FLAGS} ${TARGET_ELF} ${TARGET_BIN}
148         COMMENT "Creating binary file to load:  ${TARGET_BIN}"
149 )
150
151
152 #| Generate the Extended .LSS
153 set( TARGET_LSS ${TARGET}.lss )
154 add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
155         COMMAND ${CMAKE_OBJDUMP} ${LSS_FLAGS} ${TARGET_ELF} > ${TARGET_LSS}
156         COMMENT "Creating Extended Listing:     ${TARGET_LSS}"
157 )
158
159
160 #| Generate the Symbol Table .SYM
161 set( TARGET_SYM ${TARGET}.sym )
162 add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
163         COMMAND ${CMAKE_NM} -n ${TARGET_ELF} > ${TARGET_SYM}
164         COMMENT "Creating Symbol Table:         ${TARGET_SYM}"
165 )
166
167
168 #| Compiler Selection Record
169 add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
170         COMMAND ${CMAKE_SOURCE_DIR}/../Lib/CMake/writer compiler ${COMPILER_FAMILY}
171 )
172
173
174
175 ###
176 # Size Information
177 #
178
179 #| After Changes Size Information
180 add_custom_target( SizeAfter ALL
181         COMMAND ${CMAKE_SOURCE_DIR}/../Lib/CMake/sizeCalculator ${CMAKE_SIZE} ram   ${TARGET_ELF} ${SIZE_RAM}   " SRAM"
182         COMMAND ${CMAKE_SOURCE_DIR}/../Lib/CMake/sizeCalculator ${CMAKE_SIZE} flash ${TARGET_ELF} ${SIZE_FLASH} "Flash"
183         DEPENDS ${TARGET_ELF}
184         COMMENT "Chip usage for ${CHIP}"
185 )
186