-
Notifications
You must be signed in to change notification settings - Fork 0
/
CmakeLists.txt
162 lines (128 loc) · 7.07 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
155
156
157
158
159
160
161
162
include("${TOOLCHAIN_OFFSET}/tools/toolchain.cmake")
#-DCUSTOM_BUILD_PATH_PREFIX:STRING= #Can be used for some sketchy pre-build Stuff if needed
cmake_minimum_required(VERSION 3.20)
set(TEENSY_MODEL ${ENV_CORE_MODEL}) #36 40 41
set(TEENSY_CORE_SPEED ${ENV_CORE_SPEED})
set(USB_SETTING ${ENV_USB_SETTING})
if(TEENSY_MODEL EQUAL 36)
set(TEENSY_CORE "teensy3")
set(TEENSY_CORE_NAME "MK66FX1M0" CACHE INTERNAL "")
set(TEENSY_CPU "cortex-m4")
set(FLOAT_HARDWARE fpv4-sp-d16)
set(LINKER_MATH arm_cortexM4lf_math)
set(TEENSY_ARDUINO ARDUINO_TEENSY36)
message(STATUS "Configuring for Teensy 3.6")
elseif(TEENSY_MODEL EQUAL 40)
set(TEENSY_CORE "teensy4")
set(TEENSY_CORE_NAME "IMXRT1062" CACHE INTERNAL "")
set(TEENSY_CPU "cortex-m7")
set(FLOAT_HARDWARE fpv5-d16)
set(LINKER_MATH arm_cortexM7lfsp_math)
set(TEENSY_ARDUINO ARDUINO_TEENSY40)
message(STATUS "Configuring for Teensy 4.0")
elseif(TEENSY_MODEL EQUAL 41)
set(TEENSY_CORE "teensy4")
set(TEENSY_CORE_NAME "IMXRT1062" CACHE INTERNAL "")
set(TEENSY_CPU "cortex-m7")
set(FLOAT_HARDWARE fpv5-d16)
set(LINKER_MATH arm_cortexM7lfsp_math)
set(LINKER_EXTENSION "_t41")
set(TEENSY_ARDUINO ARDUINO_TEENSY41)
message(STATUS "Configuring for Teensy 4.1")
else()
message(FATAL_ERROR "Unsupported teensy model given: ${TEENSY_MODEL}" )
endif()
project(IIT_ECU_Teensy${TEENSY_MODEL})
set(FRONT_BIN Teensy${TEENSY_MODEL}_Front)
set(BACK_BIN Teensy${TEENSY_MODEL}_Back)
set(CMAKE_BUILD_TYPE "Release")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/lib")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/lib")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
set(LIBRARY_PATH ${CUSTOM_BUILD_PATH_PREFIX}libraries CACHE INTERNAL "")
set(SOURCE_PATH ${CUSTOM_BUILD_PATH_PREFIX}src CACHE INTERNAL "")
# Compile flags and definitions
add_compile_definitions(_GNU_SOURCE USING_MAKEFILE LAYOUT_US_ENGLISH F_CPU=${TEENSY_CORE_SPEED} __${TEENSY_CORE_NAME}__)
add_compile_definitions(ARDUINO=${ARDUINO_VER} TEENSYDUINO=${TEENSYDUINO_VER} ${TEENSY_ARDUINO} ${TEENSY_CORE} ${USB_SETTING} )
add_compile_options(-O3 -CC -Wall -Wno-error=narrowing -MMD -nostdlib) # -E
add_compile_options(-ffunction-sections -fdata-sections -fno-exceptions)
add_compile_options(-mcpu=${TEENSY_CPU} -mfloat-abi=hard -mfpu=${FLOAT_HARDWARE} -mthumb)
string(APPEND CMAKE_CXX_FLAGS "-felide-constructors -fpermissive -fno-rtti") # use add_compile_options instead?
string(APPEND CMAKE_ASM_FLAGS "-x assembler-with-cpp")
set(CMAKE_C_STANDARD 17)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED on)
set(CORE_PATH "${TOOLCHAIN_ROOT_PATH}/teensy/avr/cores/${TEENSY_CORE}")
string(TOLOWER ${TEENSY_CORE_NAME} TEENSY_CORE_NAME_LOWER)
set(TEENSY_CORE_LD_SCRIPT "${CORE_PATH}/${TEENSY_CORE_NAME_LOWER}${LINKER_EXTENSION}.ld" CACHE INTERNAL "")
# TODO: Find if __rtc_localtime differs between cores; 1499566176, 1547051415, 1610195861? does it matter?
add_link_options(-Wl,--gc-sections,--relax,-defsym=__rtc_localtime=0 -lm -lstdc++ -l${LINKER_MATH} -T${TEENSY_CORE_LD_SCRIPT})
add_link_options(-mcpu=${TEENSY_CPU} -mfloat-abi=hard -mfpu=${FLOAT_HARDWARE} -mthumb)
if(EXISTS "../script.disable") # TODO: Ensure this file is always caught
message(STATUS "Mapped logging disabled")
add_compile_definitions(CONF_LOGGING_MAPPED_MODE=0)
else()
message(STATUS "Mapped logging enabled")
add_compile_definitions(CONF_LOGGING_MAPPED_MODE=1)
endif()
# Locate and setup libraries and ECU core
MACRO(HEADER_DIRECTORIES return_list path_prefix)
FILE(GLOB_RECURSE new_list ${path_prefix}/*.h | ${path_prefix}/*.hpp)
SET(dir_list "")
FOREACH(file_path ${new_list})
GET_FILENAME_COMPONENT(dir_path ${file_path} PATH)
SET(dir_list ${dir_list} ${dir_path})
ENDFOREACH()
LIST(REMOVE_DUPLICATES dir_list)
SET(${return_list} ${dir_list})
ENDMACRO()
HEADER_DIRECTORIES(LIBRARY_INCLUDE ${LIBRARY_PATH})
HEADER_DIRECTORIES(CORE_INCLUDE ${CORE_PATH})
file(GLOB_RECURSE L_ASM_BUILD_FILES ${LIBRARY_PATH}/*.S)
file(GLOB_RECURSE L_C_BUILD_FILES ${LIBRARY_PATH}/*.c)
file(GLOB_RECURSE L_CXX_BUILD_FILES ${LIBRARY_PATH}/*.cpp)
file(GLOB_RECURSE S_ASM_BUILD_FILES ${SOURCE_PATH}/*.S)
file(GLOB_RECURSE S_C_BUILD_FILES ${SOURCE_PATH}/*.c)
file(GLOB_RECURSE S_CXX_BUILD_FILES ${SOURCE_PATH}/*.cpp)
file(GLOB_RECURSE C_ASM_BUILD_FILES ${CORE_PATH}/*.S)
file(GLOB_RECURSE C_C_BUILD_FILES ${CORE_PATH}/*.c)
file(GLOB_RECURSE C_CXX_BUILD_FILES ${CORE_PATH}/*.cpp)
add_library(core STATIC ${C_ASM_BUILD_FILES} ${C_C_BUILD_FILES} ${C_CXX_BUILD_FILES})
target_include_directories(core PUBLIC ${CORE_PATH} ${CORE_INCLUDE})
# Front Libraries
add_library(libraries_Front STATIC ${L_ASM_BUILD_FILES} ${L_C_BUILD_FILES} ${L_CXX_BUILD_FILES})
target_include_directories(libraries_Front PUBLIC ${LIBRARY_PATH} ${LIBRARY_INCLUDE})
target_link_libraries(libraries_Front core)
target_compile_definitions(libraries_Front PRIVATE CONF_ECU_POSITION=FRONT_ECU)
# Back Libraries
add_library(libraries_Back STATIC ${L_ASM_BUILD_FILES} ${L_C_BUILD_FILES} ${L_CXX_BUILD_FILES})
target_include_directories(libraries_Back PUBLIC ${LIBRARY_PATH} ${LIBRARY_INCLUDE})
target_link_libraries(libraries_Back core)
target_compile_definitions(libraries_Back PRIVATE CONF_ECU_POSITION=BACK_ECU)
# Front Executable
add_executable(${FRONT_BIN} ${S_ASM_BUILD_FILES} ${S_C_BUILD_FILES} ${S_CXX_BUILD_FILES})
target_link_libraries(${FRONT_BIN} libraries_Front core)
target_compile_definitions(${FRONT_BIN} PRIVATE CONF_ECU_POSITION=FRONT_ECU)
set_target_properties(${FRONT_BIN} PROPERTIES LINK_DEPENDS ${TEENSY_CORE_LD_SCRIPT})
set_target_properties(${FRONT_BIN} PROPERTIES OUTPUT_NAME ${FRONT_BIN} SUFFIX ".elf")
set(FRONT_OUTPUT_FILE "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${FRONT_BIN}.hex" CACHE INTERNAL "")
set(FRONT_TARGET_ELF "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${FRONT_BIN}.elf")
add_custom_command(TARGET ${FRONT_BIN} POST_BUILD
COMMAND ${CMAKE_SIZE_UTIL} "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${FRONT_BIN}.elf"
COMMAND ${CMAKE_OBJCOPY} -O ihex -R .eeprom ${FRONT_TARGET_ELF} ${FRONT_OUTPUT_FILE}
COMMAND echo.)
set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_CLEAN_FILES "${FRONT_OUTPUT_FILE}")
# Back Executable
add_executable(${BACK_BIN} ${S_ASM_BUILD_FILES} ${S_C_BUILD_FILES} ${S_CXX_BUILD_FILES})
target_link_libraries(${BACK_BIN} libraries_Back core)
target_compile_definitions(${BACK_BIN} PRIVATE CONF_ECU_POSITION=BACK_ECU)
set_target_properties(${BACK_BIN} PROPERTIES LINK_DEPENDS ${TEENSY_CORE_LD_SCRIPT})
set_target_properties(${BACK_BIN} PROPERTIES OUTPUT_NAME ${BACK_BIN} SUFFIX ".elf")
set(BACK_OUTPUT_FILE "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${BACK_BIN}.hex" CACHE INTERNAL "")
set(BACK_TARGET_ELF "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${BACK_BIN}.elf")
add_custom_command(TARGET ${BACK_BIN} POST_BUILD
COMMAND ${CMAKE_SIZE_UTIL} "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${BACK_BIN}.elf"
COMMAND ${CMAKE_OBJCOPY} -O ihex -R .eeprom ${BACK_TARGET_ELF} ${BACK_OUTPUT_FILE}
COMMAND echo.)
set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_CLEAN_FILES "${BACK_OUTPUT_FILE}")