forked from Zealandia-Systems/Swordfish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
122 lines (100 loc) · 3.8 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
cmake_minimum_required(VERSION 3.22.0)
message(STATUS "---------------------")
message(STATUS "Configuring Swordfish")
message(STATUS "---------------------")
message(STATUS "CMake version: ${CMAKE_VERSION}")
if(CMAKE_BINARY_DIR STREQUAL CMAKE_SOURCE_DIR)
message(FATAL_ERROR "In-source builds are not supported. Please use separate folder for build.")
endif()
enable_language(C)
enable_language(CXX)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
find_package(Git REQUIRED)
find_package(Python3 REQUIRED)
if(GIT_EXECUTABLE)
# Generate a git-describe version string from Git repository tags
execute_process(
COMMAND ${GIT_EXECUTABLE} describe --tags --abbrev=0
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE GIT_DESCRIBE_VERSION
RESULT_VARIABLE GIT_DESCRIBE_ERROR_CODE
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(NOT GIT_DESCRIBE_ERROR_CODE)
set(SWORDFISH_VERSION_SHORT ${GIT_DESCRIBE_VERSION})
endif()
execute_process(
COMMAND ${GIT_EXECUTABLE} describe --tags --dirty
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE GIT_DESCRIBE_VERSION
RESULT_VARIABLE GIT_DESCRIBE_ERROR_CODE
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(NOT GIT_DESCRIBE_ERROR_CODE)
set(SWORDFISH_VERSION_LONG ${GIT_DESCRIBE_VERSION})
endif()
endif()
# Final fallback: Just use a bogus version string that is semantically older
# than anything else and spit out a warning to the developer.
if(NOT DEFINED SWORDFISH_VERSION_SHORT)
set(SWORDFISH_VERSION_SHORT v0.0.0)
message(WARNING "Failed to determine SWORDFISH_VERSION_SHORT from Git tags. Using default version \"${SWORDFISH_VERSION_SHORT}\".")
endif()
if(NOT DEFINED SWORDFISH_VERSION_LONG)
set(SWORDFISH_VERSION_LONG v0.0.0-unknown)
message(WARNING "Failed to determine SWORDFISH_VERSION_LONG from Git tags. Using default version \"${SWORDFISH_VERSION_LONG}\".")
endif()
configure_file(${CMAKE_SOURCE_DIR}/Version.h.in ${CMAKE_BINARY_DIR}/Version.h @ONLY)
message(STATUS "Short Version: ${SWORDFISH_VERSION_SHORT}")
message(STATUS "Long Version: ${SWORDFISH_VERSION_LONG}")
string(SUBSTRING ${SWORDFISH_VERSION_SHORT} 1 -1 SWORDFISH_PROJECT_VERSION)
string(REPLACE "-draft" "" SWORDFISH_PROJECT_VERSION ${SWORDFISH_PROJECT_VERSION})
message(STATUS "Project Version: ${SWORDFISH_PROJECT_VERSION}")
project(Swordfish VERSION ${SWORDFISH_PROJECT_VERSION})
add_executable(${PROJECT_NAME}.elf "")
add_subdirectory(external)
add_subdirectory(src)
target_compile_definitions(${PROJECT_NAME}.elf
PRIVATE
__SAMD51__
__SAMD51P20A__
__FPU_PRESENT
ARM_MATH_CM4
ARDUINO=180
ADAFRUIT_GRAND_CENTRAL_M4
ARDUINO_GRAND_CENTRAL_M4
ENABLE_CACHE
VARIANT_QSPI_BAUD_DEFAULT=50000000
USBCON
USB_VID=0x239A
USB_PID=0x0031
F_CPU=120000000
USB_PRODUCT="Swordfish CNC"
USB_MANUFACTURER="Zealandia Systems Ltd"
ARDUINO_ARCH_SAMD
ARDUINOSTL_M_H
MACHINE_TYPE=${SWORDFISH_MACHINE_TYPE}
MACHINE_NAME=${SWORDFISH_MACHINE_NAME}
INVERT_ENDSTOPS=${SWORDFISH_INVERT_ENDSTOPS}
)
target_include_directories(${PROJECT_NAME}.elf
PRIVATE
src
${CMAKE_BINARY_DIR}
)
add_custom_target(${PROJECT_NAME}.bin ALL DEPENDS ${PROJECT_NAME}.elf)
add_custom_command(TARGET ${PROJECT_NAME}.bin
COMMAND ${CMAKE_OBJCOPY} ARGS -O binary ${PROJECT_NAME}.elf ${PROJECT_NAME}.bin)
add_custom_target(uf2 ALL DEPENDS ${PROJECT_NAME}.bin)
add_custom_command(TARGET uf2
USES_TERMINAL
COMMAND ${Python3_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tools/uf2conv.py -c -b 0x4000 -o "${CMAKE_BINARY_DIR}/${PROJECT_NAME}-${SWORDFISH_VERSION_LONG}-${SWORDFISH_MACHINE_NAME}.uf2" "${CMAKE_BINARY_DIR}/${PROJECT_NAME}.bin")
add_custom_target(flash DEPENDS ${PROJECT_NAME}.bin)
add_custom_command(TARGET flash
USES_TERMINAL
COMMAND JLinkExe -CommanderScript ../flash.jlink)