3
3
# SPDX-License-Identifier: BSD-3-Clause
4
4
function (mcux_add_source )
5
5
set (single_value BASE_PATH CONFIG PREINCLUDE EXCLUDE SCOPE )
6
- set (multi_value SOURCES ${MCUX_SOURCE_CONDITION} )
6
+ set (multi_value SOURCES PREINCLUDE_TYPE ${MCUX_SOURCE_CONDITION} )
7
7
cmake_parse_arguments (_ "${options} " "${single_value} " "${multi_value} "
8
8
${ARGN} )
9
9
@@ -66,8 +66,13 @@ function(mcux_add_source)
66
66
if (match )
67
67
file (GLOB files "${directory} /${file} " )
68
68
else ()
69
- # add source_abs_path to list file
70
- list (APPEND files "${source_abs_path} " )
69
+ string (REGEX MATCH "\\ *\\ *" match "${file} " )
70
+ if (match )
71
+ file (GLOB_RECURSE files "${directory} /*" )
72
+ else ()
73
+ # add source_abs_path to list file
74
+ list (APPEND files "${source_abs_path} " )
75
+ endif ()
71
76
endif ()
72
77
foreach (source_abs_path ${files} )
73
78
# process config files, project customized config files have higher priority
@@ -171,8 +176,17 @@ function(mcux_add_source)
171
176
set (pre_flag "-include ${source_abs_path} " )
172
177
endif ()
173
178
if (pre_flag )
174
- mcux_append_single_compiler_flags_variable ("CC" "${pre_flag} " )
175
- mcux_append_single_compiler_flags_variable ("CX" "${pre_flag} " )
179
+ if (__PREINCLUDE_TYPE )
180
+ if ("c_include" IN_LIST __PREINCLUDE_TYPE )
181
+ mcux_append_single_compiler_flags_variable ("CC" "${pre_flag} " )
182
+ endif ()
183
+ if ("cpp_include" IN_LIST __PREINCLUDE_TYPE )
184
+ mcux_append_single_compiler_flags_variable ("CX" "${pre_flag} " )
185
+ endif ()
186
+ else ()
187
+ mcux_append_single_compiler_flags_variable ("CC" "${pre_flag} " )
188
+ mcux_append_single_compiler_flags_variable ("CX" "${pre_flag} " )
189
+ endif ()
176
190
endif ()
177
191
if (${CONFIG_TOOLCHAIN} STREQUAL "codewarrior" )
178
192
# don't set preinclude file for codewarrior assembler, otherwise build failed
@@ -184,16 +198,30 @@ function(mcux_add_source)
184
198
# Error: ^
185
199
# Unrecognized mnemonic: CONFIG_DBI_USE_MIPI_PANE
186
200
elseif (as_pre_flag )
187
- mcux_append_single_compiler_flags_variable ("AS" "${as_pre_flag} " )
201
+ if (__PREINCLUDE_TYPE )
202
+ if ("asm_include" IN_LIST __PREINCLUDE_TYPE )
203
+ mcux_append_single_compiler_flags_variable ("AS" "${as_pre_flag} " )
204
+ endif ()
205
+ else ()
206
+ mcux_append_single_compiler_flags_variable ("AS" "${as_pre_flag} " )
207
+ endif ()
188
208
else ()
189
- mcux_append_single_compiler_flags_variable ("AS" "${pre_flag} " )
209
+ if (__PREINCLUDE_TYPE )
210
+ if ("asm_include" IN_LIST __PREINCLUDE_TYPE )
211
+ mcux_append_single_compiler_flags_variable ("AS" "${pre_flag} " )
212
+ endif ()
213
+ else ()
214
+ mcux_append_single_compiler_flags_variable ("AS" "${pre_flag} " )
215
+ endif ()
190
216
endif ()
191
217
endif ()
192
218
193
219
if (NOT __EXCLUDE )
194
220
target_sources (${MCUX_SDK_PROJECT_NAME} ${source_scope} ${source_abs_path} )
195
221
log_debug ("Add source ${source_abs_path} into project"
196
222
${CMAKE_CURRENT_LIST_FILE} )
223
+ else ()
224
+ mcux_set_property (MCUX_EXCLUDE_FILE_LIST ${source_abs_path} APPEND )
197
225
endif ()
198
226
199
227
# need to go through remove source list and remove the source from
@@ -480,6 +508,13 @@ function(mcux_set_variable name value)
480
508
CACHE STRING "Selected ${name} : ${value} " )
481
509
endif ()
482
510
511
+ if (${name} STREQUAL device )
512
+ # for west cmd to find cached variable
513
+ set (CACHED_DEVICE
514
+ ${value}
515
+ CACHE STRING "Selected ${name} : ${value} " )
516
+ endif ()
517
+
483
518
set (${name} ${value} CACHE STRING "The variable ${name} : ${value} " FORCE )
484
519
485
520
log_debug ("Variable ${name} is set to ${value} " ${CMAKE_CURRENT_LIST_FILE} )
@@ -505,7 +540,7 @@ function(post_build_process)
505
540
endfunction ()
506
541
507
542
function (mcux_convert_binary )
508
- set (single_value BINARY )
543
+ set (single_value BINARY TARGET )
509
544
set (multi_value TOOLCHAINS EXTRA_ARGS )
510
545
cmake_parse_arguments (_ "${options} " "${single_value} " "${multi_value} "
511
546
${ARGN} )
@@ -524,6 +559,19 @@ function(mcux_convert_binary)
524
559
if (NOT binary_name )
525
560
return ()
526
561
endif ()
562
+
563
+ if (__TARGET )
564
+ set (target_name ${__TARGET} )
565
+ else ()
566
+ set (target_name ${MCUX_SDK_PROJECT_NAME} )
567
+ endif ()
568
+
569
+ # Library can not be converted to binary file, only convert executable
570
+ get_target_property (TARGET_TYPE ${target_name} TYPE )
571
+ if (NOT TARGET_TYPE STREQUAL "EXECUTABLE" )
572
+ log_warn ("${target_name} is library type, can't be converted to binary file by mcux_convert_binary" ${CMAKE_CURRENT_LIST_FILE} )
573
+ return ()
574
+ endif ()
527
575
528
576
# Get the absolute folder path
529
577
get_filename_component (FILE_PATH ${binary_name} DIRECTORY )
@@ -548,27 +596,33 @@ function(mcux_convert_binary)
548
596
if (NOT __EXTRA_ARGS )
549
597
set (__EXTRA_ARGS -gap-fill 0xff -flash-start-x 0x20000 )
550
598
endif ()
551
- target_link_options (${MCUX_SDK_PROJECT_NAME } PRIVATE ${OBJDUMP_BIN_CMD} ${__EXTRA_ARGS} )
599
+ target_link_options (${target_name } PRIVATE ${OBJDUMP_BIN_CMD} ${__EXTRA_ARGS} )
552
600
return ()
601
+ else ()
602
+ if (__EXTRA_ARGS )
603
+ string (REPLACE " " ";" extra_args "${__EXTRA_ARGS} " )
604
+ else ()
605
+ set (extra_args )
606
+ endif ()
553
607
endif ()
554
608
555
- get_target_property (IMAGE_FILE_NAME ${MCUX_SDK_PROJECT_NAME } OUTPUT_NAME )
609
+ get_target_property (IMAGE_FILE_NAME ${target_name } OUTPUT_NAME )
556
610
if (${IMAGE_FILE_NAME} STREQUAL "IMAGE_FILE_NAME-NOTFOUND" )
557
- set (IMAGE_FILE_NAME ${MCUX_SDK_PROJECT_NAME } )
611
+ set (IMAGE_FILE_NAME ${target_name } )
558
612
endif ()
559
613
add_custom_command (
560
- TARGET ${MCUX_SDK_PROJECT_NAME }
614
+ TARGET ${target_name }
561
615
POST_BUILD
562
616
COMMAND
563
- ${CMAKE_OBJCOPY} ${OBJDUMP_BIN_CMD}
617
+ ${CMAKE_OBJCOPY} ${OBJDUMP_BIN_CMD} ${extra_args}
564
618
${CMAKE_CURRENT_BINARY_DIR} /${IMAGE_FILE_NAME}${CMAKE_EXECUTABLE_SUFFIX}
565
619
${OBJDUMP_OUT_CMD} ${binary_name} )
566
620
567
- get_target_property (clean_files ${MCUX_SDK_PROJECT_NAME }
621
+ get_target_property (clean_files ${target_name }
568
622
ADDITIONAL_CLEAN_FILES )
569
623
list (APPEND clean_files ${binary_name} )
570
624
571
- set_target_properties (${MCUX_SDK_PROJECT_NAME }
625
+ set_target_properties (${target_name }
572
626
PROPERTIES ADDITIONAL_CLEAN_FILES "${clean_files} " )
573
627
endfunction ()
574
628
@@ -1098,12 +1152,33 @@ endfunction()
1098
1152
1099
1153
function (mcux_add_cmakelists path )
1100
1154
set (add_cmakelist 0 )
1101
- file (RELATIVE_PATH relative_path ${SdkRootDirPath} ${path} )
1102
1155
set (cmakelist_path ${path} /CMakeLists.txt )
1156
+ file (RELATIVE_PATH relative_path ${SdkRootDirPath} ${path} )
1157
+
1158
+ string (FIND ${relative_path} "../" sdk_path_index )
1159
+ if (${sdk_path_index} GREATER -1 )
1160
+ string (REGEX REPLACE "^([.][.]/)+" "custom/" relative_path ${relative_path} )
1161
+ endif ()
1103
1162
1104
1163
if (ARGC EQUAL 1 )
1105
1164
set (add_cmakelist 1 )
1165
+ get_filename_component (binary_path "${APPLICATION_BINARY_DIR} /${relative_path} " ABSOLUTE )
1106
1166
elseif (ARGC EQUAL 2 )
1167
+ string (TOUPPER ${ARGV1} ARGV1 )
1168
+ if (${ARGV1} STREQUAL OPTIONAL )
1169
+ if (EXISTS ${cmakelist_path} )
1170
+ set (add_cmakelist 1 )
1171
+ get_filename_component (binary_path "${APPLICATION_BINARY_DIR} /${relative_path} " ABSOLUTE )
1172
+ else ()
1173
+ log_debug ("No CMakeLists.txt in ${path} " ${CMAKE_CURRENT_LIST_FILE} )
1174
+ endif ()
1175
+ else ()
1176
+ # If the second argument is not OPTIONAL, treat it as binary_path
1177
+ set (add_cmakelist 1 )
1178
+ set (binary_path ${ARGV1} )
1179
+ endif ()
1180
+ elseif (ARGC EQUAL 3 )
1181
+ set (binary_path ${ARGV2} )
1107
1182
string (TOUPPER ${ARGV1} ARGV1 )
1108
1183
if (${ARGV1} STREQUAL OPTIONAL )
1109
1184
if (EXISTS ${cmakelist_path} )
@@ -1116,6 +1191,10 @@ function(mcux_add_cmakelists path)
1116
1191
"Wrong argument in mcux_add_cmakelists, second argument only supports OPTIONAL"
1117
1192
${CMAKE_CURRENT_LIST_FILE} )
1118
1193
endif ()
1194
+ else ()
1195
+ log_fatal (
1196
+ "Wrong number of arguments in mcux_add_cmakelists, expected 1, 2, or 3 arguments"
1197
+ ${CMAKE_CURRENT_LIST_FILE} )
1119
1198
endif ()
1120
1199
1121
1200
if (${add_cmakelist} EQUAL 1 )
@@ -1124,7 +1203,13 @@ function(mcux_add_cmakelists path)
1124
1203
else ()
1125
1204
log_debug ("Include CMakeLists.txt from ${path} "
1126
1205
${CMAKE_CURRENT_LIST_FILE} )
1127
- add_subdirectory (${path} ${CMAKE_CURRENT_BINARY_DIR} /${relative_path} )
1206
+ get_property (ADDED_SUBDIRS GLOBAL PROPERTY ADDED_SUBDIRS )
1207
+ get_filename_component (path "${path} " REALPATH )
1208
+ list (FIND ADDED_SUBDIRS ${path} SUBDIR_FOUND )
1209
+ if (SUBDIR_FOUND EQUAL -1 )
1210
+ add_subdirectory (${path} ${binary_path} )
1211
+ set_property (GLOBAL APPEND PROPERTY ADDED_SUBDIRS ${path} )
1212
+ endif ()
1128
1213
endif ()
1129
1214
endif ()
1130
1215
endfunction ()
@@ -1135,41 +1220,53 @@ function(mcux_load_project_ide_data)
1135
1220
foreach (f
1136
1221
${SdkRootDirPath} /devices/IDE.yml
1137
1222
${SdkRootDirPath} /devices/${soc_portfolio}/IDE.yml
1138
- ${SdkRootDirPath} /devices/${soc_portfolio}/${soc_series}/IDE.yml
1139
- ${SdkRootDirPath} /devices/${soc_portfolio}/${soc_series}/${device}/IDE.yml
1140
- ${SdkRootDirPath} /examples/IDE.yml
1141
- ${SdkRootDirPath} /examples/_boards/IDE.yml
1142
- ${SdkRootDirPath} /examples/_boards/${board}/IDE.yml )
1223
+ ${SdkRootDirPath} /${device_root}/${soc_portfolio}/${soc_series}/IDE.yml
1224
+ ${SdkRootDirPath} /${device_root}/${soc_portfolio}/${soc_series}/${device}/IDE.yml )
1143
1225
if (EXISTS ${f} )
1144
1226
list (APPEND IDE_yml_list ${f} )
1145
1227
endif ()
1146
1228
endforeach ()
1229
+
1230
+ if (DEFINED board )
1231
+ foreach (f
1232
+ ${SdkRootDirPath} /examples/IDE.yml
1233
+ ${SdkRootDirPath} /examples/_boards/IDE.yml
1234
+ ${SdkRootDirPath} /${board_root}/${board}/IDE.yml )
1235
+ if (EXISTS ${f} )
1236
+ list (APPEND IDE_yml_list ${f} )
1237
+ endif ()
1238
+ endforeach ()
1239
+ endif ()
1147
1240
else ()
1148
1241
foreach (f
1149
1242
${SdkRootDirPath} /devices/IDE.yml
1150
1243
${SdkRootDirPath} /devices/${soc_portfolio}/IDE.yml
1151
- ${SdkRootDirPath} /devices/${soc_portfolio}/${soc_series}/IDE.yml
1152
- ${SdkRootDirPath} /devices/${soc_portfolio}/${soc_series}/${device}/IDE.yml
1153
- ${SdkRootDirPath} /devices/${soc_portfolio}/${soc_series}/${device}/${core_id}/IDE.yml
1154
- ${SdkRootDirPath} /examples/IDE.yml
1155
- ${SdkRootDirPath} /examples/_boards/IDE.yml
1156
- ${SdkRootDirPath} /examples/_boards/${board}/IDE.yml
1157
- ${SdkRootDirPath} /examples/_boards/${board}/${core_id}/IDE.yml )
1244
+ ${SdkRootDirPath} /${device_root}/${soc_portfolio}/${soc_series}/IDE.yml
1245
+ ${SdkRootDirPath} /${device_root}/${soc_portfolio}/${soc_series}/${device}/IDE.yml
1246
+ ${SdkRootDirPath} /${device_root}/${soc_portfolio}/${soc_series}/${device}/${core_id}/IDE.yml )
1158
1247
if (EXISTS ${f} )
1159
1248
list (APPEND IDE_yml_list ${f} )
1160
1249
endif ()
1161
1250
endforeach ()
1251
+
1252
+ if (DEFINED board )
1253
+ foreach (f
1254
+ ${SdkRootDirPath} /examples/IDE.yml
1255
+ ${SdkRootDirPath} /examples/_boards/IDE.yml
1256
+ ${SdkRootDirPath} /${board_root}/${board}/IDE.yml
1257
+ ${SdkRootDirPath} /${board_root}/${board}/${core_id}/IDE.yml )
1258
+ if (EXISTS ${f} )
1259
+ list (APPEND IDE_yml_list ${f} )
1260
+ endif ()
1261
+ endforeach ()
1262
+ endif ()
1162
1263
endif ()
1163
1264
1164
- if (DEFINED project_board_port_path )
1165
- if (DEFINED INTERNAL_EXAMPLE )
1166
- get_target_source_in_sub_folders (${APPLICATION_SOURCE_DIR} ${INTERNAL_EXAMPLE_FOLDER} "IDE.yml" )
1167
- else ()
1168
- get_target_source_in_sub_folders (${APPLICATION_SOURCE_DIR} "examples" "IDE.yml" )
1169
- endif ()
1265
+ if (DEFINED project_board_port_path OR DEFINED project_device_port_path )
1266
+ get_target_source_in_sub_folders (${APPLICATION_SOURCE_DIR} ${EXAMPLE_FOLDER} "IDE.yml" )
1170
1267
list (APPEND IDE_yml_list ${GET_TARGET_SOURCE_IN_SUB_FOLDERS_OUTPUT} )
1171
1268
1172
- get_target_source_in_sub_folders (${full_project_board_port_path } "${board } " "IDE.yml" )
1269
+ get_target_source_in_sub_folders (${full_project_port_path } "${board_device_folder } " "IDE.yml" )
1173
1270
list (APPEND IDE_yml_list ${GET_TARGET_SOURCE_IN_SUB_FOLDERS_OUTPUT} )
1174
1271
else ()
1175
1272
if (EXISTS ${APPLICATION_SOURCE_DIR} /IDE.yml )
@@ -2389,7 +2486,58 @@ function(reset_app_link_order)
2389
2486
target_link_libraries (app PRIVATE -Wl,--end-group )
2390
2487
endif ()
2391
2488
2392
- # Workaround: there will a an extra "-Wl,--start-group" without the statement below
2393
- target_link_libraries (app PRIVATE McuxSDK )
2489
+ # Workaround:
2490
+ # Without the statement below, there are two errors:
2491
+ # missing --end-group
2492
+ # undefined reference to `_exit'
2493
+ if (${CONFIG_TOOLCHAIN} STREQUAL "armgcc" )
2494
+ target_link_libraries (app PRIVATE -Wl,--start-group )
2495
+ target_link_libraries (app PRIVATE "-lm" )
2496
+ target_link_libraries (app PRIVATE "-lc" )
2497
+ target_link_libraries (app PRIVATE "-lgcc" )
2498
+ target_link_libraries (app PRIVATE "-lnosys" )
2499
+ target_link_libraries (app PRIVATE -Wl,--end-group )
2500
+ endif ()
2394
2501
endfunction ()
2395
2502
2503
+ # Usage
2504
+ # _get_subfolder_file(<output-var> <directory> <pattern> <level>)
2505
+ #
2506
+ # get designated file path from subfolder with designed deepth level
2507
+ function (_get_subfolder_file OUTPUT_VAR CURRENT_DIR PATTERN LEVEL )
2508
+ set (current_level 1 )
2509
+ set (dir_queue "${CURRENT_DIR} " )
2510
+
2511
+ while ( dir_queue AND (${current_level} LESS_EQUAL ${LEVEL} ))
2512
+ list (LENGTH dir_queue queue_length )
2513
+
2514
+ math (EXPR end_index "${queue_length} - 1" )
2515
+ foreach (index RANGE ${end_index} )
2516
+ list (GET dir_queue ${index} dir )
2517
+ file (GLOB children RELATIVE "${dir} " "${dir} /*/" )
2518
+
2519
+ foreach (child ${children} )
2520
+ if (IS_DIRECTORY "${dir} /${child} " )
2521
+ list (APPEND dir_queue "${dir} /${child} " )
2522
+ endif ()
2523
+ endforeach ()
2524
+
2525
+ endforeach ()
2526
+
2527
+ math (EXPR end_index "${queue_length} - 1" )
2528
+ foreach (index RANGE ${end_index} )
2529
+ list (REMOVE_AT dir_queue 0 )
2530
+ endforeach ()
2531
+
2532
+
2533
+ math (EXPR current_level "${current_level} + 1" )
2534
+ endwhile ()
2535
+
2536
+ foreach (dir ${dir_queue} )
2537
+ if (EXISTS ${dir} /${PATTERN} )
2538
+ set (${OUTPUT_VAR} ${dir} /${PATTERN} PARENT_SCOPE )
2539
+ break ()
2540
+ endif ()
2541
+ endforeach ()
2542
+
2543
+ endfunction ()
0 commit comments