-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
154 lines (125 loc) · 5.7 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
cmake_minimum_required(VERSION 3.10)
project(TeensyAudioSPISharedLibrary)
set(CMAKE_CXX_STANDARD 11)
# This toolchain file is based on https://github.com/apmorton/teensy-template/blob/master/Makefile
# and on the Teensy Makefile.
include(CMakeForceCompiler)
# User configurable variables
# (show up in cmake-gui)
#
set(TEENSY_VERSION 40 CACHE STRING "Set to the Teensy version corresponding to your board (30 or 31 allowed)" FORCE)
set(CPU_CORE_SPEED 600000000 CACHE STRING "Set to 24000000, 48000000, 72000000 or 96000000 to set CPU core speed" FORCE)
set(ARDUINOPATH "/Applications/Teensyduino.app/Contents/Java/" CACHE STRING "Path to Arduino installation" FORCE)
# Derived variables
#
set(CPU cortex-m7)
set(TOOLSPATH "${ARDUINOPATH}hardware/tools/")
set(COMPILERPATH "${TOOLSPATH}arm/bin/")
set(COREPATH "${ARDUINOPATH}hardware/teensy/avr/cores/teensy4/")
set(CUSTOM_LIBRARY_PATH "/Users/johnsmith/Documents/Arduino/libraries/")
# Normal toolchain configuration
#
# this one is important
set(CMAKE_SYSTEM_NAME Generic)
# specify the cross compiler
cmake_force_c_compiler(${COMPILERPATH}arm-none-eabi-gcc GNU)
cmake_force_cxx_compiler(${COMPILERPATH}arm-none-eabi-g++ GNU)
# where is the target environment
set(CMAKE_FIND_ROOT_PATH ${COMPILERPATH})
# search for programs in the build host directories
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# for libraries and headers in the target directories
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
# Additional C and CPP files for Arduino support
#
file(GLOB TEENSY_C_FILES ${COREPATH}*.c)
file(GLOB TEENSY_CPP_FILES ${COREPATH}*.cpp)
set(TEENSY_SOURCES ${TEENSY_C_FILES} ${TEENSY_CPP_FILES})
list(REMOVE_ITEM TEENSY_SOURCES ${COREPATH}main.cpp)
# Teensy 3.0 and 3.1 differentiation
#
message("TEENSY_VERSION ${TEENSY_VERSION}")
if (TEENSY_VERSION EQUAL 30)
set(CPU_DEFINE __MK20DX128__)
set(LINKER_FILE ${COREPATH}mk20dx128.ld)
endif()
if (TEENSY_VERSION EQUAL 40)
set(CPU_DEFINE __IMXRT1062__)
set(LINKER_FILE ${COREPATH}imxrt1062.ld)
endif()
if(TEENSY_VERSION EQUAL 31)
set(CPU_DEFINE __MK20DX256__)
set(LINKER_FILE ${COREPATH}mk20dx256.ld)
endif()
set(TEENSY_DEFINITIONS USB_SERIAL
LAYOUT_US_ENGLISH
F_CPU=${CPU_CORE_SPEED}
${CPU_DEFINE}
TEENSYDUINO=151
ARDUINO=10812
ARDUINO_TEENSY40
USB_SERIAL
BUILD_TEENSYDUINO_MAIN)
# Macros to wrap add_[executable|library] for seamless Teensy integration
#
function(teensy_add_executable TARGET)
message("Corepath " ${COREPATH})
set(ELFTARGET ${TARGET}.elf)
message("mm ${ELFTARGET} ${ARGN} ${TEENSY_SOURCES}")
add_executable(${ELFTARGET} ${ARGN} ${TEENSY_SOURCES})
set_target_properties(${ELFTARGET} PROPERTIES COMPILE_FLAGS "-Wall -g -Os -mcpu=${CPU} -mthumb -nostdlib -MMD -felide-constructors -fno-exceptions -fno-rtti -std=gnu++0x")
set_target_properties(${ELFTARGET} PROPERTIES COMPILE_DEFINITIONS "${TEENSY_DEFINITIONS} ${INCLUDE_DIRECTORIES} -D __arm__ -DTEENSYDUINO -I/Users/nicholasnewdigate/Downloads/SerialFlash-master")
set_target_properties(${ELFTARGET} PROPERTIES INCLUDE_DIRECTORIES "${COREPATH}")
set_target_properties(${ELFTARGET} PROPERTIES LINK_FLAGS "-Os -Wl,--gc-sections,--defsym=__rtc_localtime=0 --specs=nano.specs -mcpu=${CPU} -mthumb -T${LINKER_FILE}")
add_custom_command(OUTPUT ${TARGET}.hex
COMMAND ${COMPILERPATH}arm-none-eabi-size ${ELFTARGET}
COMMAND ${COMPILERPATH}arm-none-eabi-objcopy -O ihex -R .eeprom ${ELFTARGET} ${TARGET}.hex
COMMAND ${TOOLSPATH}teensy_post_compile -file=${TARGET} -path=${CMAKE_CURRENT_BINARY_DIR} -tools=${TOOLSPATH}
DEPENDS ${ELFTARGET}
COMMENT "Creating HEX file for ${ELFTARGET}")
add_custom_target(hex ALL DEPENDS ${TARGET}.hex)
endfunction()
macro(import_arduino_library LIB_NAME)
# Check if we can find the library.
if(NOT EXISTS ${ARDUINO_LIB_ROOT})
message(FATAL_ERROR "Could not find the Arduino library directory")
endif(NOT EXISTS ${ARDUINO_LIB_ROOT})
set(LIB_DIR "${ARDUINO_LIB_ROOT}/${LIB_NAME}")
#message(LIB_DIR ${LIB_DIR})
if(NOT EXISTS "${LIB_DIR}")
message("Could not find the directory for library '${LIB_NAME}' (${LIB_DIR})")
set(LIB_DIR "${CUSTOM_LIBRARY_PATH}/${LIB_NAME}")
if(NOT EXISTS "${LIB_DIR}")
message(FATAL_ERROR "Could not find the directory for library '${LIB_NAME}' (${LIB_DIR})")
endif(NOT EXISTS "${LIB_DIR}")
endif(NOT EXISTS "${LIB_DIR}")
# Add it to the include path.
include_directories("${LIB_DIR}")
set(INCLUDE_DIRECTORIES "${INCLUDE_DIRECTORIES}-I${LIB_DIR} ")
message("include_directories " ${LIB_DIR} " - " ${INCLUDE_DIRECTORIES})
# Mark source files to be built along with the sketch code.
file(GLOB SOURCES_CPP ABSOLUTE "${LIB_DIR}" "${LIB_DIR}/*.cpp")
foreach(SOURCE_CPP ${SOURCES_CPP})
set(TEENSY_LIB_SOURCES ${TEENSY_LIB_SOURCES} ${SOURCE_CPP})
endforeach(SOURCE_CPP ${SOURCES_CPP})
file(GLOB SOURCES_C ABSOLUTE "${LIB_DIR}" "${LIB_DIR}/*.c")
foreach(SOURCE_C ${SOURCES_C})
set(TEENSY_LIB_SOURCES ${TEENSY_LIB_SOURCES} ${SOURCE_C})
message("lib src ${TEENSY_LIB_SOURCES}")
endforeach(SOURCE_C ${SOURCES_C})
endmacro(import_arduino_library)
set(ARDUINO_LIB_ROOT "/Applications/Teensyduino.app/Contents/Java/hardware/teensy/avr/libraries")
import_arduino_library(Wire)
import_arduino_library(Audio)
import_arduino_library(SPI)
import_arduino_library(SD)
teensy_add_executable(TeensyAudioSPISharedLibrary
main.cpp
output_shared_ad5754_dual.cpp
output_shared_ad5754_dual.h
input_shared_ad7606.cpp
input_shared_ad7606.h
common_ad5754_ad7606.h
common_ad5754_ad7606.cpp
)