@@ -20,15 +20,39 @@ include(${MBED_PATH}/tools/cmake/profile.cmake)
20
20
21
21
enable_language (C CXX ASM )
22
22
23
- # Find Python and needed packages
24
- find_package (Python3 )
23
+ # Find Python
24
+ find_package (Python3 COMPONENTS Interpreter )
25
25
include (${CMAKE_CURRENT_LIST_DIR} /CheckPythonPackage.cmake )
26
- check_python_package (intelhex HAVE_INTELHEX )
27
- check_python_package (prettytable HAVE_PRETTYTABLE )
28
26
29
- if (Python3_FOUND AND HAVE_INTELHEX AND HAVE_PRETTYTABLE )
27
+ # Check python packages from requirements.txt
28
+ file (STRINGS ${CMAKE_CURRENT_LIST_DIR} /requirements.txt PYTHON_REQUIREMENTS )
29
+ foreach (REQUIREMENT ${PYTHON_REQUIREMENTS} )
30
+
31
+ # Look for a string from the start of each line that does not contain "<", ">", "=", or " ".
32
+ if (REQUIREMENT MATCHES "^([^<>= ]+)" )
33
+
34
+ set (PACKAGE_NAME ${CMAKE_MATCH_1} )
35
+ string (TOUPPER ${PACKAGE_NAME} PACKAGE_NAME_UCASE ) # Ucase name needed for CMake variable
36
+ string (TOLOWER ${PACKAGE_NAME} PACKAGE_NAME_LCASE ) # Lcase name needed for import statement
37
+
38
+ check_python_package (${PACKAGE_NAME_LCASE} HAVE_PYTHON_${PACKAGE_NAME_UCASE} )
39
+ if (NOT HAVE_PYTHON_${PACKAGE_NAME_UCASE} )
40
+ message (WARNING "Missing Python dependency ${PACKAGE_NAME} " )
41
+ endif ()
42
+
43
+ else ()
44
+
45
+ message (FATAL_ERROR "Cannot parse line \" ${REQUIREMENT} \" in requirements.txt" )
46
+
47
+ endif ()
48
+
49
+ endforeach ()
50
+
51
+ # Check deps for memap
52
+ if (Python3_FOUND AND HAVE_PYTHON_INTELHEX AND HAVE_PYTHON_PRETTYTABLE )
30
53
set (HAVE_MEMAP_DEPS TRUE )
31
54
else ()
32
55
set (HAVE_MEMAP_DEPS FALSE )
33
56
message (STATUS "Missing Python dependencies (python3, intelhex, prettytable) so the memory map cannot be printed" )
34
- endif ()
57
+ endif ()
58
+
0 commit comments