-
Notifications
You must be signed in to change notification settings - Fork 0
/
FindMCUXpressoSDK.cmake
131 lines (121 loc) · 6.31 KB
/
FindMCUXpressoSDK.cmake
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
cmake_minimum_required(VERSION 3.21)
if (NOT DEFINED MCUXPRESSO_SDK_PATH)
message(FATAL_ERROR "MCUXPRESSO_SDK_PATH not found")
endif ()
file(REAL_PATH ${MCUXPRESSO_SDK_PATH} MCUXPRESSO_SDK_PATH EXPAND_TILDE)
if (NOT EXISTS ${MCUXPRESSO_SDK_PATH})
message(FATAL_ERROR "Directory '${MCUXPRESSO_SDK_PATH}' not found")
endif ()
if (NOT DEFINED MCUXPRESSO_SDK_DEVICE_PACKAGE)
message(WARNING "MCUXPRESSO_SDK_DEVICE_PACKAGE is not defined, to prevent SDK warning, please add definitions manually")
endif ()
get_filename_component(sdk_name ${MCUXPRESSO_SDK_PATH} NAME)
string(REGEX MATCH "SDK_([0-9]+)_([0-9]+)_([0-9]+)_(.*)" sdk_name_match_result ${sdk_name})
if (NOT CMAKE_MATCH_COUNT EQUAL 4)
message(FATAL_ERROR "Invalid MCUXPRESSO_SDK_PATH")
endif ()
set(sdk_major_version ${CMAKE_MATCH_1})
set(sdk_minor_version ${CMAKE_MATCH_2})
set(sdk_patch_version ${CMAKE_MATCH_3})
set(sdk_device ${CMAKE_MATCH_4})
set(sdk_version ${sdk_major_version}.${sdk_minor_version}.${sdk_patch_version})
file(GLOB temp "${MCUXPRESSO_SDK_PATH}/devices/${sdk_device}/system_${sdk_device}_*.c")
foreach (file IN LISTS temp)
get_filename_component(file_name ${file} NAME)
string(REGEX MATCH "system_${sdk_device}_(.*).c" file_name_match_result ${file_name})
if (NOT CMAKE_MATCH_COUNT EQUAL 1)
continue()
endif ()
list(APPEND cores ${CMAKE_MATCH_1})
endforeach ()
list(LENGTH cores cores_len)
if (cores_len EQUAL 0)
if (NOT TARGET MCUXpressoSDK::Device)
add_library(MCUXpressoSDK::Device INTERFACE IMPORTED)
target_include_directories(MCUXpressoSDK::Device INTERFACE "${MCUXPRESSO_SDK_PATH}/devices/${sdk_device}")
target_sources(MCUXpressoSDK::Device INTERFACE "${MCUXPRESSO_SDK_PATH}/devices/${sdk_device}/system_${sdk_device}.c")
if (DEFINED MCUXPRESSO_SDK_DEVICE_PACKAGE)
target_compile_definitions(MCUXpressoSDK::Device INTERFACE CPU_${MCUXPRESSO_SDK_DEVICE_PACKAGE})
endif ()
endif ()
if (NOT TARGET MCUXpressoSDK::Startup)
add_library(MCUXpressoSDK::Startup INTERFACE IMPORTED)
target_sources(MCUXpressoSDK::Startup INTERFACE "${MCUXPRESSO_SDK_PATH}/devices/${sdk_device}/gcc/startup_${sdk_device}.S")
endif ()
file(GLOB ld_files "${MCUXPRESSO_SDK_PATH}/devices/${sdk_device}/gcc/${sdk_device}_*.ld")
foreach (ld_file IN LISTS ld_files)
get_filename_component(ld_file_name ${ld_file} NAME)
string(REGEX MATCH "${sdk_device}_(.*).ld" ld_file_name_match_result ${ld_file_name})
if (NOT CMAKE_MATCH_COUNT EQUAL 1)
continue()
endif ()
if (NOT TARGET MCUXpressoSDK::Linker::${CMAKE_MATCH_1})
add_library(MCUXpressoSDK::Linker::${CMAKE_MATCH_1} INTERFACE IMPORTED)
target_link_options(MCUXpressoSDK::Linker::${CMAKE_MATCH_1} -T ${ld_file})
endif ()
endforeach ()
else ()
foreach (core IN LISTS cores)
if (NOT TARGET MCUXpressoSDK::Device::${core})
add_library(MCUXpressoSDK::Device::${core} INTERFACE IMPORTED)
target_include_directories(MCUXpressoSDK::Device::${core} INTERFACE "${MCUXPRESSO_SDK_PATH}/devices/${sdk_device}")
target_sources(MCUXpressoSDK::Device::${core} INTERFACE "${MCUXPRESSO_SDK_PATH}/devices/${sdk_device}/system_${sdk_device}_${core}.c")
if (DEFINED MCUXPRESSO_SDK_DEVICE_PACKAGE)
target_compile_definitions(MCUXpressoSDK::Device::${core} INTERFACE CPU_${MCUXPRESSO_SDK_DEVICE_PACKAGE}_${core})
endif ()
endif ()
if (NOT TARGET MCUXpressoSDK::Startup::${core})
add_library(MCUXpressoSDK::Startup::${core} INTERFACE IMPORTED)
target_sources(MCUXpressoSDK::Startup::${core} INTERFACE "${MCUXPRESSO_SDK_PATH}/devices/${sdk_device}/gcc/startup_${sdk_device}_${core}.S")
endif ()
file(GLOB ld_files "${MCUXPRESSO_SDK_PATH}/devices/${sdk_device}/gcc/${sdk_device}_${core}_*.ld")
foreach (ld_file IN LISTS ld_files)
string(REGEX MATCH "${sdk_device}_${core}_(.*).ld" ld_file_name_match_result ${ld_file})
if (NOT CMAKE_MATCH_COUNT EQUAL 1)
continue()
endif ()
if (NOT TARGET MCUXpressoSDK::Linker::${core}::${CMAKE_MATCH_1})
add_library(MCUXpressoSDK::Linker::${core}::${CMAKE_MATCH_1} INTERFACE IMPORTED)
target_link_options(MCUXpressoSDK::Linker::${core}::${CMAKE_MATCH_1} INTERFACE -T ${ld_file})
endif ()
endforeach ()
endforeach ()
endif ()
if (NOT TARGET MCUXpressoSDK::CMSIS)
add_library(MCUXpressoSDK::CMSIS INTERFACE IMPORTED)
target_include_directories(MCUXpressoSDK::CMSIS INTERFACE "${MCUXPRESSO_SDK_PATH}/CMSIS/Core/Include")
endif ()
if (NOT TARGET MCUXpressoSDK::Drivers_Include)
add_library(MCUXpressoSDK::Drivers_Include INTERFACE IMPORTED)
target_include_directories(MCUXpressoSDK::Drivers_Include INTERFACE "${MCUXPRESSO_SDK_PATH}/devices/${sdk_device}/drivers")
endif ()
file(GLOB driver_files ${MCUXPRESSO_SDK_PATH}/devices/${sdk_device}/drivers/*.c)
foreach (driver_file IN LISTS driver_files)
get_filename_component(driver_file_name ${driver_file} NAME)
string(REGEX MATCH "fsl_(.*).c" driver_file_name_match_result ${driver_file_name})
if (NOT CMAKE_MATCH_COUNT EQUAL 1)
continue()
endif ()
list(APPEND drivers ${CMAKE_MATCH_1})
endforeach ()
if (NOT DEFINED MCUXpressoSDK_FIND_COMPONENTS OR NOT MCUXpressoSDK_FIND_COMPONENTS)
set(MCUXpressoSDK_Find_COMPONENTS ${drivers})
endif ()
foreach (component IN LISTS MCUXpressoSDK_Find_COMPONENTS)
if (${component} IN_LIST drivers)
if (NOT TARGET MCUXpressoSDK::Drivers::${component})
add_library(MCUXpressoSDK::Drivers::${component} INTERFACE IMPORTED)
target_sources(MCUXpressoSDK::Drivers::${component} INTERFACE "${MCUXPRESSO_SDK_PATH}/devices/${sdk_device}/drivers/fsl_${component}.c")
target_link_libraries(MCUXpressoSDK::Drivers::${component} INTERFACE MCUXpressoSDK::Drivers_Include)
endif ()
endif ()
endforeach ()
if (NOT DEFINED MCUXpressoSDK::Syscall)
add_library(MCUXpressoSDK::Syscall INTERFACE IMPORTED)
target_sources(MCUXpressoSDK::Syscall INTERFACE "${CMAKE_CURRENT_LIST_DIR}/syscall_stub.c")
endif ()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(MCUXpressoSDK
REQUIRED_VARS MCUXPRESSO_SDK_PATH
VERSION_VAR sdk_version
)