-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
91 lines (75 loc) · 4 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
cmake_minimum_required(VERSION 3.10)
# declare project name
project(teensy-cpp VERSION 0.1 LANGUAGES C CXX ASM)
# options
option(PRINT_SIZE_INFO_AFTER_LINK "Prints verbose size info to stdout" ON)
# Teensy Loader CLI command arguments options
option(TEENSY_LOADER_WAIT_TO_FLASH "Waits on Teensy detection to flash" ON)
option(TEENSY_LOADER_USE_HARD_REBOOT "Use hard reboot if Teensy is not online" OFF)
option(TEENSY_LOADER_USE_SOFT_REBOOT "Use soft reboot if device is not online" OFF)
option(TEENSY_LOADER_NO_REBOOT "Do not reboot Teensy after programming" OFF)
option(TEENSY_LOADER_BOOT_ONLY "Boot Teensy only, do not program" OFF)
option(TEENSY_LOADER_VERBOSE "Enables or disables verbose output" ON)
# how to generate the flash command
# POST_BUILD - adds a post-build command to your executable
# UTILITY_TARGET - creates a utility target with a post-build command
# NONE - does not generate a flash command
set(TEENSY_LOADER_CLI_GENERATOR_TYPE "UTILITY_TARGET")
# set output path to /bin, /lib, etc.
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY${${CMAKE_BUILD_TYPE}} ${CMAKE_CURRENT_LIST_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY${${CMAKE_BUILD_TYPE}} ${CMAKE_CURRENT_LIST_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY${${CMAKE_BUILD_TYPE}} ${CMAKE_CURRENT_LIST_DIR}/lib)
# set the paths for our teensy firmware loader
# and the cmake arm embedded toolchain path
set(TEENSY_LOADER_SUBMODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/submodules/teensy_loader_cli)
set(CMAKE_ARM_EMBEDDED_SUBMODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/submodules/cmake-arm-embedded)
# set the linker script for our teensy 4.0 and include that beeoch's cmake toolchain flags
set(LINKER_SCRIPT "${CMAKE_CURRENT_LIST_DIR}/etc/imxrt1062_t41.ld")
include(${CMAKE_ARM_EMBEDDED_SUBMODULE_PATH}/teensy41.cmake)
add_subdirectory(3rdparty/imxrt1062)
# add our executable
add_embedded_arm_executable(${PROJECT_NAME})
target_link_libraries(${PROJECT_NAME} imxrt1062)
# our sources
set(PROJ_INCLUDE_DIR ${CMAKE_CURRENT_LIST_DIR}/include)
set(PROJ_SRC_DIR ${CMAKE_CURRENT_LIST_DIR}/src)
target_include_directories(${PROJECT_NAME} PRIVATE ${PROJ_INCLUDE_DIR})
target_sources(${PROJECT_NAME} PRIVATE
${PROJ_SRC_DIR}/teensy/bootdata.c # lookup tables and memory signatures for booting
${PROJ_SRC_DIR}/teensy/startup.c # the first C code that is run on the MCU, calls main()
${PROJ_SRC_DIR}/teensy/cpp-compat.cpp # adds some missing primitive C++ functions
${PROJ_INCLUDE_DIR}/imxrt1062-chrono.h # adds some primitive timer/delay functions based on CPU counter
${PROJ_INCLUDE_DIR}/morse-code.hpp # morse code table
${PROJ_SRC_DIR}/main.cpp # our hello world code
)
if("${TEENSY_LOADER_CLI_GENERATOR_TYPE}" STREQUAL "POST_BUILD" OR "${TEENSY_LOADER_CLI_GENERATOR_TYPE}" STREQUAL "UTILITY_TARGET")
include(${TEENSY_LOADER_SUBMODULE_PATH}/cmake/TeensyFlashTarget.cmake)
if(WIN32)
get_filename_component(TEENSY_LOADER_COMMAND ${TEENSY_LOADER_SUBMODULE_PATH}/bin/teensy_loader_cli.exe ABSOLUTE)
else()
get_filename_component(TEENSY_LOADER_COMMAND ${TEENSY_LOADER_SUBMODULE_PATH}/bin/teensy_loader_cli ABSOLUTE)
endif()
if("${TEENSY_LOADER_CLI_GENERATOR_TYPE}" STREQUAL "UTILITY_TARGET")
add_teensy_flash_target(
${PROJECT_NAME}
"imxrt1062"
${TEENSY_LOADER_WAIT_TO_FLASH}
${TEENSY_LOADER_USE_HARD_REBOOT}
${TEENSY_LOADER_USE_SOFT_REBOOT}
${TEENSY_LOADER_NO_REBOOT}
${TEENSY_LOADER_BOOT_ONLY}
${TEENSY_LOADER_VERBOSE}
)
elseif("${TEENSY_LOADER_CLI_GENERATOR_TYPE}" STREQUAL "POST_BUILD")
add_teensy_flash_command(
${PROJECT_NAME}
"imxrt1062"
${TEENSY_LOADER_WAIT_TO_FLASH}
${TEENSY_LOADER_USE_HARD_REBOOT}
${TEENSY_LOADER_USE_SOFT_REBOOT}
${TEENSY_LOADER_NO_REBOOT}
${TEENSY_LOADER_BOOT_ONLY}
${TEENSY_LOADER_VERBOSE}
)
endif()
endif()