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