|
1 |
| -if (NOT TARGET _family_support_marker) |
2 |
| - add_library(_family_support_marker INTERFACE) |
| 1 | +if (TARGET _family_support_marker) |
| 2 | + return() |
| 3 | +endif () |
3 | 4 |
|
4 |
| - include(CMakePrintHelpers) |
| 5 | +add_library(_family_support_marker INTERFACE) |
5 | 6 |
|
6 |
| - # Default to gcc |
7 |
| - if(NOT DEFINED TOOLCHAIN) |
8 |
| - set(TOOLCHAIN gcc) |
9 |
| - endif() |
| 7 | +include(CMakePrintHelpers) |
10 | 8 |
|
11 |
| - if (NOT FAMILY) |
12 |
| - message(FATAL_ERROR "You must set a FAMILY variable for the build (e.g. rp2040, eps32s2, esp32s3). You can do this via -DFAMILY=xxx on the cmake command line") |
13 |
| - endif() |
| 9 | +# Default to gcc |
| 10 | +if(NOT DEFINED TOOLCHAIN) |
| 11 | + set(TOOLCHAIN gcc) |
| 12 | +endif() |
14 | 13 |
|
15 |
| - if (NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/${FAMILY}/family.cmake) |
16 |
| - message(FATAL_ERROR "Family '${FAMILY}' is not known/supported") |
17 |
| - endif() |
| 14 | +if (NOT FAMILY) |
| 15 | + message(FATAL_ERROR "You must set a FAMILY variable for the build (e.g. rp2040, eps32s2, esp32s3). You can do this via -DFAMILY=xxx on the cmake command line") |
| 16 | +endif() |
18 | 17 |
|
19 |
| - function(family_filter RESULT DIR) |
20 |
| - get_filename_component(DIR ${DIR} ABSOLUTE BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) |
21 |
| - |
22 |
| - if (EXISTS "${DIR}/only.txt") |
23 |
| - file(READ "${DIR}/only.txt" ONLYS) |
24 |
| - # Replace newlines with semicolon so that it is treated as a list by CMake |
25 |
| - string(REPLACE "\n" ";" ONLYS_LINES ${ONLYS}) |
26 |
| - # For each mcu |
27 |
| - foreach(MCU IN LISTS FAMILY_MCUS) |
28 |
| - # For each line in only.txt |
29 |
| - foreach(_line ${ONLYS_LINES}) |
30 |
| - # If mcu:xxx exists for this mcu or board:xxx then include |
31 |
| - if (${_line} STREQUAL "mcu:${MCU}" OR ${_line} STREQUAL "board:${BOARD}") |
32 |
| - set(${RESULT} 1 PARENT_SCOPE) |
33 |
| - return() |
34 |
| - endif() |
35 |
| - endforeach() |
36 |
| - endforeach() |
| 18 | +if (NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/${FAMILY}/family.cmake) |
| 19 | + message(FATAL_ERROR "Family '${FAMILY}' is not known/supported") |
| 20 | +endif() |
37 | 21 |
|
38 |
| - # Didn't find it in only file so don't build |
39 |
| - set(${RESULT} 0 PARENT_SCOPE) |
40 |
| - |
41 |
| - elseif (EXISTS "${DIR}/skip.txt") |
42 |
| - file(READ "${DIR}/skip.txt" SKIPS) |
43 |
| - # Replace newlines with semicolon so that it is treated as a list by CMake |
44 |
| - string(REPLACE "\n" ";" SKIPS_LINES ${SKIPS}) |
45 |
| - # For each mcu |
46 |
| - foreach(MCU IN LISTS FAMILY_MCUS) |
47 |
| - # For each line in only.txt |
48 |
| - foreach(_line ${SKIPS_LINES}) |
49 |
| - # If mcu:xxx exists for this mcu then skip |
50 |
| - if (${_line} STREQUAL "mcu:${MCU}") |
51 |
| - set(${RESULT} 0 PARENT_SCOPE) |
52 |
| - return() |
53 |
| - endif() |
54 |
| - endforeach() |
| 22 | +function(family_filter RESULT DIR) |
| 23 | + get_filename_component(DIR ${DIR} ABSOLUTE BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) |
| 24 | + |
| 25 | + if (EXISTS "${DIR}/only.txt") |
| 26 | + file(READ "${DIR}/only.txt" ONLYS) |
| 27 | + # Replace newlines with semicolon so that it is treated as a list by CMake |
| 28 | + string(REPLACE "\n" ";" ONLYS_LINES ${ONLYS}) |
| 29 | + # For each mcu |
| 30 | + foreach(MCU IN LISTS FAMILY_MCUS) |
| 31 | + # For each line in only.txt |
| 32 | + foreach(_line ${ONLYS_LINES}) |
| 33 | + # If mcu:xxx exists for this mcu or board:xxx then include |
| 34 | + if (${_line} STREQUAL "mcu:${MCU}" OR ${_line} STREQUAL "board:${BOARD}") |
| 35 | + set(${RESULT} 1 PARENT_SCOPE) |
| 36 | + return() |
| 37 | + endif() |
| 38 | + endforeach() |
| 39 | + endforeach() |
| 40 | + |
| 41 | + # Didn't find it in only file so don't build |
| 42 | + set(${RESULT} 0 PARENT_SCOPE) |
| 43 | + |
| 44 | + elseif (EXISTS "${DIR}/skip.txt") |
| 45 | + file(READ "${DIR}/skip.txt" SKIPS) |
| 46 | + # Replace newlines with semicolon so that it is treated as a list by CMake |
| 47 | + string(REPLACE "\n" ";" SKIPS_LINES ${SKIPS}) |
| 48 | + # For each mcu |
| 49 | + foreach(MCU IN LISTS FAMILY_MCUS) |
| 50 | + # For each line in only.txt |
| 51 | + foreach(_line ${SKIPS_LINES}) |
| 52 | + # If mcu:xxx exists for this mcu then skip |
| 53 | + if (${_line} STREQUAL "mcu:${MCU}") |
| 54 | + set(${RESULT} 0 PARENT_SCOPE) |
| 55 | + return() |
| 56 | + endif() |
55 | 57 | endforeach()
|
| 58 | + endforeach() |
56 | 59 |
|
57 |
| - # Didn't find in skip file so build |
58 |
| - set(${RESULT} 1 PARENT_SCOPE) |
| 60 | + # Didn't find in skip file so build |
| 61 | + set(${RESULT} 1 PARENT_SCOPE) |
59 | 62 |
|
60 |
| - else() |
| 63 | + else() |
61 | 64 |
|
62 |
| - # Didn't find skip or only file so build |
63 |
| - set(${RESULT} 1 PARENT_SCOPE) |
| 65 | + # Didn't find skip or only file so build |
| 66 | + set(${RESULT} 1 PARENT_SCOPE) |
64 | 67 |
|
65 |
| - endif() |
| 68 | + endif() |
66 | 69 |
|
67 |
| - endfunction() |
| 70 | +endfunction() |
68 | 71 |
|
69 |
| - function(family_add_subdirectory DIR) |
70 |
| - family_filter(SHOULD_ADD "${DIR}") |
71 |
| - if (SHOULD_ADD) |
72 |
| - add_subdirectory(${DIR}) |
73 |
| - endif() |
74 |
| - endfunction() |
| 72 | +function(family_add_subdirectory DIR) |
| 73 | + family_filter(SHOULD_ADD "${DIR}") |
| 74 | + if (SHOULD_ADD) |
| 75 | + add_subdirectory(${DIR}) |
| 76 | + endif() |
| 77 | +endfunction() |
| 78 | + |
| 79 | +function(family_get_project_name OUTPUT_NAME DIR) |
| 80 | + get_filename_component(SHORT_NAME ${DIR} NAME) |
| 81 | + set(${OUTPUT_NAME} ${TINYUSB_FAMILY_PROJECT_NAME_PREFIX}${SHORT_NAME} PARENT_SCOPE) |
| 82 | +endfunction() |
75 | 83 |
|
76 |
| - function(family_get_project_name OUTPUT_NAME DIR) |
| 84 | +function(family_initialize_project PROJECT DIR) |
| 85 | + family_filter(ALLOWED "${DIR}") |
| 86 | + if (NOT ALLOWED) |
77 | 87 | get_filename_component(SHORT_NAME ${DIR} NAME)
|
78 |
| - set(${OUTPUT_NAME} ${TINYUSB_FAMILY_PROJECT_NAME_PREFIX}${SHORT_NAME} PARENT_SCOPE) |
79 |
| - endfunction() |
80 |
| - |
81 |
| - function(family_initialize_project PROJECT DIR) |
82 |
| - family_filter(ALLOWED "${DIR}") |
83 |
| - if (NOT ALLOWED) |
84 |
| - get_filename_component(SHORT_NAME ${DIR} NAME) |
85 |
| - message(FATAL_ERROR "${SHORT_NAME} is not supported on FAMILY=${FAMILY}") |
86 |
| - endif() |
87 |
| - endfunction() |
88 |
| - |
89 |
| - function(family_add_default_example_warnings TARGET) |
90 |
| - target_compile_options(${TARGET} PUBLIC |
91 |
| - -Wall |
92 |
| - -Wextra |
93 |
| - -Werror |
94 |
| - -Wfatal-errors |
95 |
| - -Wdouble-promotion |
96 |
| - -Wfloat-equal |
97 |
| - -Wshadow |
98 |
| - -Wwrite-strings |
99 |
| - -Wsign-compare |
100 |
| - -Wmissing-format-attribute |
101 |
| - -Wunreachable-code |
102 |
| - -Wcast-align |
103 |
| - -Wcast-qual |
104 |
| - -Wnull-dereference |
105 |
| - -Wuninitialized |
106 |
| - -Wunused |
107 |
| - -Wredundant-decls |
108 |
| - #-Wstrict-prototypes |
109 |
| - #-Werror-implicit-function-declaration |
110 |
| - #-Wundef |
111 |
| - ) |
112 |
| - |
113 |
| - if (CMAKE_C_COMPILER_ID STREQUAL "GNU") |
114 |
| - # GCC 10 |
115 |
| - if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 10.0) |
116 |
| - target_compile_options(${TARGET} PUBLIC -Wconversion) |
117 |
| - endif() |
118 |
| - |
119 |
| - # GCC 8 |
120 |
| - if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 8.0) |
121 |
| - target_compile_options(${TARGET} PUBLIC -Wcast-function-type -Wstrict-overflow) |
122 |
| - endif() |
123 |
| - |
124 |
| - # GCC 6 |
125 |
| - if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 6.0) |
126 |
| - target_compile_options(${TARGET} PUBLIC -Wno-strict-aliasing) |
127 |
| - endif() |
| 88 | + message(FATAL_ERROR "${SHORT_NAME} is not supported on FAMILY=${FAMILY}") |
| 89 | + endif() |
| 90 | +endfunction() |
| 91 | + |
| 92 | +function(family_add_default_example_warnings TARGET) |
| 93 | + target_compile_options(${TARGET} PUBLIC |
| 94 | + -Wall |
| 95 | + -Wextra |
| 96 | + -Werror |
| 97 | + -Wfatal-errors |
| 98 | + -Wdouble-promotion |
| 99 | + -Wfloat-equal |
| 100 | + -Wshadow |
| 101 | + -Wwrite-strings |
| 102 | + -Wsign-compare |
| 103 | + -Wmissing-format-attribute |
| 104 | + -Wunreachable-code |
| 105 | + -Wcast-align |
| 106 | + -Wcast-qual |
| 107 | + -Wnull-dereference |
| 108 | + -Wuninitialized |
| 109 | + -Wunused |
| 110 | + -Wredundant-decls |
| 111 | + #-Wstrict-prototypes |
| 112 | + #-Werror-implicit-function-declaration |
| 113 | + #-Wundef |
| 114 | + ) |
| 115 | + |
| 116 | + if (CMAKE_C_COMPILER_ID STREQUAL "GNU") |
| 117 | + if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 12.0) |
| 118 | + target_link_options(${TARGET} PUBLIC "LINKER:--no-warn-rwx-segments") |
128 | 119 | endif()
|
129 |
| - endfunction() |
130 |
| - |
131 |
| - # configure an executable target to link to tinyusb in device mode, and add the board implementation |
132 |
| - function(family_configure_device_example TARGET) |
133 |
| - # default implementation is empty, the function should be redefined in the FAMILY/family.cmake |
134 |
| - endfunction() |
135 | 120 |
|
136 |
| - # configure an executable target to link to tinyusb in host mode, and add the board implementation |
137 |
| - function(family_configure_host_example TARGET) |
138 |
| - # default implementation is empty, the function should be redefined in the FAMILY/family.cmake |
139 |
| - endfunction() |
| 121 | + # GCC 10 |
| 122 | + if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 10.0) |
| 123 | + target_compile_options(${TARGET} PUBLIC -Wconversion) |
| 124 | + endif() |
140 | 125 |
|
141 |
| - include(${CMAKE_CURRENT_LIST_DIR}/${FAMILY}/family.cmake) |
| 126 | + # GCC 8 |
| 127 | + if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 8.0) |
| 128 | + target_compile_options(${TARGET} PUBLIC -Wcast-function-type -Wstrict-overflow) |
| 129 | + endif() |
142 | 130 |
|
143 |
| - if (NOT FAMILY_MCUS) |
144 |
| - set(FAMILY_MCUS ${FAMILY}) |
| 131 | + # GCC 6 |
| 132 | + if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 6.0) |
| 133 | + target_compile_options(${TARGET} PUBLIC -Wno-strict-aliasing) |
| 134 | + endif() |
145 | 135 | endif()
|
146 |
| - |
147 |
| - # save it in case of re-inclusion |
148 |
| - set(FAMILY_MCUS ${FAMILY_MCUS} CACHE INTERNAL "") |
| 136 | +endfunction() |
| 137 | + |
| 138 | +# Add flash jlink target |
| 139 | +function(family_flash_jlink TARGET) |
| 140 | + if (NOT DEFINED JLINKEXE) |
| 141 | + set(JLINKEXE JLinkExe) |
| 142 | + endif () |
| 143 | + |
| 144 | + file(GENERATE |
| 145 | + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.jlink |
| 146 | + CONTENT "halt |
| 147 | +loadfile $<TARGET_FILE:${TARGET}> |
| 148 | +r |
| 149 | +go |
| 150 | +exit" |
| 151 | + ) |
| 152 | + |
| 153 | + add_custom_target(${TARGET}-jlink |
| 154 | + DEPENDS ${TARGET} |
| 155 | + COMMAND ${JLINKEXE} -device ${JLINK_DEVICE} -if swd -JTAGConf -1,-1 -speed auto -CommandFile ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.jlink |
| 156 | + ) |
| 157 | +endfunction() |
| 158 | + |
| 159 | +# Add flash pycod target |
| 160 | +function(family_flash_pyocd TARGET) |
| 161 | + if (NOT DEFINED PYOC) |
| 162 | + set(PYOCD pyocd) |
| 163 | + endif () |
| 164 | + |
| 165 | + add_custom_target(${TARGET}-pyocd |
| 166 | + DEPENDS ${TARGET} |
| 167 | + COMMAND ${PYOCD} flash -t ${PYOCD_TARGET} $<TARGET_FILE:${TARGET}> |
| 168 | + ) |
| 169 | +endfunction() |
| 170 | + |
| 171 | +# Add flash using NXP's LinkServer (redserver) |
| 172 | +# https://www.nxp.com/design/software/development-software/mcuxpresso-software-and-tools-/linkserver-for-microcontrollers:LINKERSERVER |
| 173 | +function(family_flash_nxplink TARGET) |
| 174 | + if (NOT DEFINED LINKSERVER) |
| 175 | + set(LINKSERVER LinkServer) |
| 176 | + endif () |
| 177 | + |
| 178 | + # LinkServer has a bug that can only execute with full path otherwise it throws: |
| 179 | + # realpath error: No such file or directory |
| 180 | + execute_process(COMMAND which ${LINKSERVER} OUTPUT_VARIABLE LINKSERVER_PATH OUTPUT_STRIP_TRAILING_WHITESPACE) |
| 181 | + |
| 182 | + add_custom_target(${TARGET}-nxplink |
| 183 | + DEPENDS ${TARGET} |
| 184 | + COMMAND ${LINKSERVER_PATH} flash ${NXPLINK_DEVICE} load $<TARGET_FILE:${TARGET}> |
| 185 | + ) |
| 186 | +endfunction() |
| 187 | + |
| 188 | +# configure an executable target to link to tinyusb in device mode, and add the board implementation |
| 189 | +function(family_configure_device_example TARGET) |
| 190 | + # default implementation is empty, the function should be redefined in the FAMILY/family.cmake |
| 191 | +endfunction() |
| 192 | + |
| 193 | +# configure an executable target to link to tinyusb in host mode, and add the board implementation |
| 194 | +function(family_configure_host_example TARGET) |
| 195 | + # default implementation is empty, the function should be redefined in the FAMILY/family.cmake |
| 196 | +endfunction() |
| 197 | + |
| 198 | +include(${CMAKE_CURRENT_LIST_DIR}/${FAMILY}/family.cmake) |
| 199 | + |
| 200 | +if (NOT FAMILY_MCUS) |
| 201 | + set(FAMILY_MCUS ${FAMILY}) |
149 | 202 | endif()
|
| 203 | + |
| 204 | +# save it in case of re-inclusion |
| 205 | +set(FAMILY_MCUS ${FAMILY_MCUS} CACHE INTERNAL "") |
0 commit comments