2020-09-23 01:53:46 -04:00
|
|
|
# CMake fragment for MicroPython rules
|
|
|
|
|
|
|
|
set(MICROPY_GENHDR_DIR "${CMAKE_BINARY_DIR}/genhdr")
|
|
|
|
set(MICROPY_MPVERSION "${MICROPY_GENHDR_DIR}/mpversion.h")
|
2021-02-20 19:30:12 -05:00
|
|
|
set(MICROPY_QSTRDEFS_PY "${MICROPY_PY_DIR}/qstrdefs.h")
|
|
|
|
set(MICROPY_QSTRDEFS_LAST "${MICROPY_GENHDR_DIR}/qstr.i.last")
|
|
|
|
set(MICROPY_QSTRDEFS_SPLIT "${MICROPY_GENHDR_DIR}/qstr.split")
|
|
|
|
set(MICROPY_QSTRDEFS_COLLECTED "${MICROPY_GENHDR_DIR}/qstrdefs.collected.h")
|
|
|
|
set(MICROPY_QSTRDEFS_PREPROCESSED "${MICROPY_GENHDR_DIR}/qstrdefs.preprocessed.h")
|
|
|
|
set(MICROPY_QSTRDEFS_GENERATED "${MICROPY_GENHDR_DIR}/qstrdefs.generated.h")
|
2022-05-31 03:10:14 -04:00
|
|
|
set(MICROPY_MODULEDEFS_SPLIT "${MICROPY_GENHDR_DIR}/moduledefs.split")
|
|
|
|
set(MICROPY_MODULEDEFS_COLLECTED "${MICROPY_GENHDR_DIR}/moduledefs.collected")
|
|
|
|
set(MICROPY_MODULEDEFS "${MICROPY_GENHDR_DIR}/moduledefs.h")
|
2022-07-01 13:29:08 -04:00
|
|
|
set(MICROPY_ROOT_POINTERS_SPLIT "${MICROPY_GENHDR_DIR}/root_pointers.split")
|
|
|
|
set(MICROPY_ROOT_POINTERS_COLLECTED "${MICROPY_GENHDR_DIR}/root_pointers.collected")
|
|
|
|
set(MICROPY_ROOT_POINTERS "${MICROPY_GENHDR_DIR}/root_pointers.h")
|
2020-09-23 01:53:46 -04:00
|
|
|
|
2021-12-11 07:01:58 -05:00
|
|
|
# Need to do this before extracting MICROPY_CPP_DEF below. Rest of frozen
|
|
|
|
# manifest handling is at the end of this file.
|
|
|
|
if(MICROPY_FROZEN_MANIFEST)
|
|
|
|
target_compile_definitions(${MICROPY_TARGET} PUBLIC
|
|
|
|
MICROPY_QSTR_EXTRA_POOL=mp_qstr_frozen_const_pool
|
|
|
|
MICROPY_MODULE_FROZEN_MPY=\(1\)
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
2020-09-23 01:53:46 -04:00
|
|
|
# Provide defaults for preprocessor flags if not already defined
|
|
|
|
if(NOT MICROPY_CPP_FLAGS)
|
|
|
|
get_target_property(MICROPY_CPP_INC ${MICROPY_TARGET} INCLUDE_DIRECTORIES)
|
|
|
|
get_target_property(MICROPY_CPP_DEF ${MICROPY_TARGET} COMPILE_DEFINITIONS)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Compute MICROPY_CPP_FLAGS for preprocessor
|
|
|
|
list(APPEND MICROPY_CPP_INC ${MICROPY_CPP_INC_EXTRA})
|
|
|
|
list(APPEND MICROPY_CPP_DEF ${MICROPY_CPP_DEF_EXTRA})
|
|
|
|
set(_prefix "-I")
|
|
|
|
foreach(_arg ${MICROPY_CPP_INC})
|
|
|
|
list(APPEND MICROPY_CPP_FLAGS ${_prefix}${_arg})
|
|
|
|
endforeach()
|
|
|
|
set(_prefix "-D")
|
|
|
|
foreach(_arg ${MICROPY_CPP_DEF})
|
|
|
|
list(APPEND MICROPY_CPP_FLAGS ${_prefix}${_arg})
|
|
|
|
endforeach()
|
|
|
|
list(APPEND MICROPY_CPP_FLAGS ${MICROPY_CPP_FLAGS_EXTRA})
|
|
|
|
|
|
|
|
find_package(Python3 REQUIRED COMPONENTS Interpreter)
|
|
|
|
|
|
|
|
target_sources(${MICROPY_TARGET} PRIVATE
|
|
|
|
${MICROPY_MPVERSION}
|
2021-02-20 19:30:12 -05:00
|
|
|
${MICROPY_QSTRDEFS_GENERATED}
|
2022-05-31 03:10:14 -04:00
|
|
|
${MICROPY_MODULEDEFS}
|
2022-07-01 13:29:08 -04:00
|
|
|
${MICROPY_ROOT_POINTERS}
|
2020-09-23 01:53:46 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
# Command to force the build of another command
|
|
|
|
|
|
|
|
# Generate mpversion.h
|
|
|
|
|
2023-02-07 20:24:12 -05:00
|
|
|
add_custom_target(
|
|
|
|
BUILD_VERSION_HEADER ALL
|
|
|
|
BYPRODUCTS ${MICROPY_MPVERSION}
|
2020-09-23 01:53:46 -04:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E make_directory ${MICROPY_GENHDR_DIR}
|
|
|
|
COMMAND ${Python3_EXECUTABLE} ${MICROPY_DIR}/py/makeversionhdr.py ${MICROPY_MPVERSION}
|
|
|
|
)
|
|
|
|
|
|
|
|
# Generate qstrs
|
|
|
|
|
|
|
|
# If any of the dependencies in this rule change then the C-preprocessor step must be run.
|
|
|
|
# It only needs to be passed the list of MICROPY_SOURCE_QSTR files that have changed since
|
|
|
|
# it was last run, but it looks like it's not possible to specify that with cmake.
|
|
|
|
add_custom_command(
|
2021-02-20 19:30:12 -05:00
|
|
|
OUTPUT ${MICROPY_QSTRDEFS_LAST}
|
2021-02-23 17:57:14 -05:00
|
|
|
COMMAND ${Python3_EXECUTABLE} ${MICROPY_PY_DIR}/makeqstrdefs.py pp ${CMAKE_C_COMPILER} -E output ${MICROPY_GENHDR_DIR}/qstr.i.last cflags ${MICROPY_CPP_FLAGS} -DNO_QSTR cxxflags ${MICROPY_CPP_FLAGS} -DNO_QSTR sources ${MICROPY_SOURCE_QSTR}
|
2022-05-31 03:10:14 -04:00
|
|
|
DEPENDS ${MICROPY_MPVERSION}
|
2020-09-23 01:53:46 -04:00
|
|
|
${MICROPY_SOURCE_QSTR}
|
|
|
|
VERBATIM
|
2020-11-10 20:05:30 -05:00
|
|
|
COMMAND_EXPAND_LISTS
|
2020-09-23 01:53:46 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
add_custom_command(
|
2021-02-20 19:30:12 -05:00
|
|
|
OUTPUT ${MICROPY_QSTRDEFS_SPLIT}
|
2020-09-23 01:53:46 -04:00
|
|
|
COMMAND ${Python3_EXECUTABLE} ${MICROPY_PY_DIR}/makeqstrdefs.py split qstr ${MICROPY_GENHDR_DIR}/qstr.i.last ${MICROPY_GENHDR_DIR}/qstr _
|
2021-02-20 19:30:12 -05:00
|
|
|
COMMAND touch ${MICROPY_QSTRDEFS_SPLIT}
|
|
|
|
DEPENDS ${MICROPY_QSTRDEFS_LAST}
|
2020-09-23 01:53:46 -04:00
|
|
|
VERBATIM
|
2020-11-10 20:05:30 -05:00
|
|
|
COMMAND_EXPAND_LISTS
|
2020-09-23 01:53:46 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
add_custom_command(
|
2021-02-20 19:30:12 -05:00
|
|
|
OUTPUT ${MICROPY_QSTRDEFS_COLLECTED}
|
|
|
|
COMMAND ${Python3_EXECUTABLE} ${MICROPY_PY_DIR}/makeqstrdefs.py cat qstr _ ${MICROPY_GENHDR_DIR}/qstr ${MICROPY_QSTRDEFS_COLLECTED}
|
|
|
|
DEPENDS ${MICROPY_QSTRDEFS_SPLIT}
|
2020-09-23 01:53:46 -04:00
|
|
|
VERBATIM
|
2020-11-10 20:05:30 -05:00
|
|
|
COMMAND_EXPAND_LISTS
|
2020-09-23 01:53:46 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
add_custom_command(
|
2021-02-20 19:30:12 -05:00
|
|
|
OUTPUT ${MICROPY_QSTRDEFS_PREPROCESSED}
|
2021-02-20 19:32:00 -05:00
|
|
|
COMMAND cat ${MICROPY_QSTRDEFS_PY} ${MICROPY_QSTRDEFS_PORT} ${MICROPY_QSTRDEFS_COLLECTED} | sed "s/^Q(.*)/\"&\"/" | ${CMAKE_C_COMPILER} -E ${MICROPY_CPP_FLAGS} - | sed "s/^\\\"\\(Q(.*)\\)\\\"/\\1/" > ${MICROPY_QSTRDEFS_PREPROCESSED}
|
|
|
|
DEPENDS ${MICROPY_QSTRDEFS_PY}
|
|
|
|
${MICROPY_QSTRDEFS_PORT}
|
|
|
|
${MICROPY_QSTRDEFS_COLLECTED}
|
2020-09-23 01:53:46 -04:00
|
|
|
VERBATIM
|
2020-11-10 20:05:30 -05:00
|
|
|
COMMAND_EXPAND_LISTS
|
2020-09-23 01:53:46 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
add_custom_command(
|
2021-02-20 19:30:12 -05:00
|
|
|
OUTPUT ${MICROPY_QSTRDEFS_GENERATED}
|
|
|
|
COMMAND ${Python3_EXECUTABLE} ${MICROPY_PY_DIR}/makeqstrdata.py ${MICROPY_QSTRDEFS_PREPROCESSED} > ${MICROPY_QSTRDEFS_GENERATED}
|
|
|
|
DEPENDS ${MICROPY_QSTRDEFS_PREPROCESSED}
|
2020-09-23 01:53:46 -04:00
|
|
|
VERBATIM
|
2020-11-10 20:05:30 -05:00
|
|
|
COMMAND_EXPAND_LISTS
|
2020-09-23 01:53:46 -04:00
|
|
|
)
|
|
|
|
|
2022-05-31 03:10:14 -04:00
|
|
|
# Generate moduledefs.h
|
|
|
|
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${MICROPY_MODULEDEFS_SPLIT}
|
|
|
|
COMMAND ${Python3_EXECUTABLE} ${MICROPY_PY_DIR}/makeqstrdefs.py split module ${MICROPY_GENHDR_DIR}/qstr.i.last ${MICROPY_GENHDR_DIR}/module _
|
|
|
|
COMMAND touch ${MICROPY_MODULEDEFS_SPLIT}
|
|
|
|
DEPENDS ${MICROPY_QSTRDEFS_LAST}
|
|
|
|
VERBATIM
|
|
|
|
COMMAND_EXPAND_LISTS
|
|
|
|
)
|
|
|
|
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${MICROPY_MODULEDEFS_COLLECTED}
|
|
|
|
COMMAND ${Python3_EXECUTABLE} ${MICROPY_PY_DIR}/makeqstrdefs.py cat module _ ${MICROPY_GENHDR_DIR}/module ${MICROPY_MODULEDEFS_COLLECTED}
|
|
|
|
DEPENDS ${MICROPY_MODULEDEFS_SPLIT}
|
|
|
|
VERBATIM
|
|
|
|
COMMAND_EXPAND_LISTS
|
|
|
|
)
|
|
|
|
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${MICROPY_MODULEDEFS}
|
|
|
|
COMMAND ${Python3_EXECUTABLE} ${MICROPY_PY_DIR}/makemoduledefs.py ${MICROPY_MODULEDEFS_COLLECTED} > ${MICROPY_MODULEDEFS}
|
|
|
|
DEPENDS ${MICROPY_MODULEDEFS_COLLECTED}
|
|
|
|
)
|
|
|
|
|
2022-07-01 13:29:08 -04:00
|
|
|
# Generate root_pointers.h
|
|
|
|
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${MICROPY_ROOT_POINTERS_SPLIT}
|
|
|
|
COMMAND ${Python3_EXECUTABLE} ${MICROPY_PY_DIR}/makeqstrdefs.py split root_pointer ${MICROPY_GENHDR_DIR}/qstr.i.last ${MICROPY_GENHDR_DIR}/root_pointer _
|
|
|
|
COMMAND touch ${MICROPY_ROOT_POINTERS_SPLIT}
|
|
|
|
DEPENDS ${MICROPY_QSTRDEFS_LAST}
|
|
|
|
VERBATIM
|
|
|
|
COMMAND_EXPAND_LISTS
|
|
|
|
)
|
|
|
|
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${MICROPY_ROOT_POINTERS_COLLECTED}
|
|
|
|
COMMAND ${Python3_EXECUTABLE} ${MICROPY_PY_DIR}/makeqstrdefs.py cat root_pointer _ ${MICROPY_GENHDR_DIR}/root_pointer ${MICROPY_ROOT_POINTERS_COLLECTED}
|
|
|
|
DEPENDS ${MICROPY_ROOT_POINTERS_SPLIT}
|
|
|
|
VERBATIM
|
|
|
|
COMMAND_EXPAND_LISTS
|
|
|
|
)
|
|
|
|
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${MICROPY_ROOT_POINTERS}
|
|
|
|
COMMAND ${Python3_EXECUTABLE} ${MICROPY_PY_DIR}/make_root_pointers.py ${MICROPY_ROOT_POINTERS_COLLECTED} > ${MICROPY_ROOT_POINTERS}
|
|
|
|
DEPENDS ${MICROPY_ROOT_POINTERS_COLLECTED} ${MICROPY_PY_DIR}/make_root_pointers.py
|
|
|
|
)
|
|
|
|
|
2020-09-23 01:53:46 -04:00
|
|
|
# Build frozen code if enabled
|
|
|
|
|
|
|
|
if(MICROPY_FROZEN_MANIFEST)
|
|
|
|
set(MICROPY_FROZEN_CONTENT "${CMAKE_BINARY_DIR}/frozen_content.c")
|
|
|
|
|
|
|
|
target_sources(${MICROPY_TARGET} PRIVATE
|
|
|
|
${MICROPY_FROZEN_CONTENT}
|
|
|
|
)
|
|
|
|
|
2021-12-11 07:01:58 -05:00
|
|
|
# Note: target_compile_definitions already added earlier.
|
2020-09-23 01:53:46 -04:00
|
|
|
|
2021-05-22 08:09:25 -04:00
|
|
|
if(NOT MICROPY_LIB_DIR)
|
2022-07-08 01:00:33 -04:00
|
|
|
string(CONCAT GIT_SUBMODULES "${GIT_SUBMODULES} " lib/micropython-lib)
|
|
|
|
set(MICROPY_LIB_DIR ${MICROPY_DIR}/lib/micropython-lib)
|
|
|
|
endif()
|
|
|
|
|
2023-07-31 03:32:27 -04:00
|
|
|
if(ECHO_SUBMODULES)
|
2023-07-31 03:24:38 -04:00
|
|
|
# No-op, we're just doing submodule/variant discovery.
|
|
|
|
# Note: All the following rules are safe to run in discovery mode even
|
|
|
|
# though the submodule might not be available as they do not directly depend
|
|
|
|
# on anything from the submodule.
|
|
|
|
elseif(NOT EXISTS ${MICROPY_LIB_DIR}/README.md)
|
2022-07-08 01:00:33 -04:00
|
|
|
message(FATAL_ERROR " micropython-lib not initialized.\n Run 'make BOARD=${MICROPY_BOARD} submodules'")
|
2021-05-22 08:09:25 -04:00
|
|
|
endif()
|
|
|
|
|
2021-08-03 08:30:15 -04:00
|
|
|
# If MICROPY_MPYCROSS is not explicitly defined in the environment (which
|
|
|
|
# is what makemanifest.py will use) then create an mpy-cross dependency
|
|
|
|
# to automatically build mpy-cross if needed.
|
|
|
|
set(MICROPY_MPYCROSS $ENV{MICROPY_MPYCROSS})
|
|
|
|
if(NOT MICROPY_MPYCROSS)
|
2022-08-02 17:48:41 -04:00
|
|
|
set(MICROPY_MPYCROSS_DEPENDENCY ${MICROPY_DIR}/mpy-cross/build/mpy-cross)
|
2021-08-03 08:30:15 -04:00
|
|
|
if(NOT MICROPY_MAKE_EXECUTABLE)
|
|
|
|
set(MICROPY_MAKE_EXECUTABLE make)
|
|
|
|
endif()
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${MICROPY_MPYCROSS_DEPENDENCY}
|
|
|
|
COMMAND ${MICROPY_MAKE_EXECUTABLE} -C ${MICROPY_DIR}/mpy-cross
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
2023-02-07 20:24:12 -05:00
|
|
|
add_custom_target(
|
|
|
|
BUILD_FROZEN_CONTENT ALL
|
|
|
|
BYPRODUCTS ${MICROPY_FROZEN_CONTENT}
|
2023-01-24 00:55:23 -05:00
|
|
|
COMMAND ${Python3_EXECUTABLE} ${MICROPY_DIR}/tools/makemanifest.py -o ${MICROPY_FROZEN_CONTENT} -v "MPY_DIR=${MICROPY_DIR}" -v "MPY_LIB_DIR=${MICROPY_LIB_DIR}" -v "PORT_DIR=${MICROPY_PORT_DIR}" -v "BOARD_DIR=${MICROPY_BOARD_DIR}" -b "${CMAKE_BINARY_DIR}" -f${MICROPY_CROSS_FLAGS} --mpy-tool-flags=${MICROPY_MPY_TOOL_FLAGS} ${MICROPY_FROZEN_MANIFEST}
|
2023-02-07 20:24:12 -05:00
|
|
|
DEPENDS
|
2021-02-20 19:30:12 -05:00
|
|
|
${MICROPY_QSTRDEFS_GENERATED}
|
2022-07-01 13:29:08 -04:00
|
|
|
${MICROPY_ROOT_POINTERS}
|
2021-08-03 08:30:15 -04:00
|
|
|
${MICROPY_MPYCROSS_DEPENDENCY}
|
2020-09-23 01:53:46 -04:00
|
|
|
VERBATIM
|
|
|
|
)
|
|
|
|
endif()
|
2022-04-28 15:49:20 -04:00
|
|
|
|
|
|
|
# Update submodules
|
|
|
|
if(ECHO_SUBMODULES)
|
|
|
|
# If cmake is run with GIT_SUBMODULES defined on command line, process the port / board
|
2022-06-29 23:49:47 -04:00
|
|
|
# settings then print the final GIT_SUBMODULES variable and exit.
|
|
|
|
# Note: the GIT_SUBMODULES is done via echo rather than message, as message splits
|
|
|
|
# the output onto multiple lines
|
|
|
|
execute_process(COMMAND ${CMAKE_COMMAND} -E echo "GIT_SUBMODULES=${GIT_SUBMODULES}")
|
|
|
|
message(FATAL_ERROR "Done")
|
2022-04-28 15:49:20 -04:00
|
|
|
endif()
|