Skip to content

Commit

Permalink
move cmake args to generate project
Browse files Browse the repository at this point in the history
  • Loading branch information
mehrdadh committed Jul 27, 2022
1 parent ae3e2a8 commit 0bfa420
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ set(ENV{QEMU_BIN_PATH} "${CMAKE_SOURCE_DIR}/qemu-hack")

set(QEMU_PIPE "\${QEMU_PIPE}") # QEMU_PIPE is set by the calling TVM instance.

set(ENABLE_CMSIS <ENABLE_CMSIS>)
<CMAKE_ARGS>

find_package(Zephyr HINTS $ENV{ZEPHYR_BASE})
project(microtvm_autogenerated_project)
Expand Down
55 changes: 30 additions & 25 deletions apps/microtvm/zephyr/template_project/microtvm_api_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,13 +275,13 @@ def _get_nrf_device_args(options):
),
server.ProjectOption(
"verbose",
optional=["build"],
optional=["generate_project"],
type="bool",
help="Run build with verbose output.",
),
server.ProjectOption(
"west_cmd",
optional=["build"],
optional=["generate_project"],
default=WEST_CMD,
type="str",
help=(
Expand All @@ -292,14 +292,14 @@ def _get_nrf_device_args(options):
server.ProjectOption(
"zephyr_base",
required=(["generate_project", "open_transport"] if not ZEPHYR_BASE else None),
optional=(["generate_project", "open_transport", "build"] if ZEPHYR_BASE else ["build"]),
optional=(["generate_project", "open_transport"] if ZEPHYR_BASE else ["build"]),
default=ZEPHYR_BASE,
type="str",
help="Path to the zephyr base directory.",
),
server.ProjectOption(
"zephyr_board",
required=["generate_project", "build", "flash", "open_transport"],
required=["generate_project", "flash", "open_transport"],
choices=list(BOARD_PROPERTIES),
type="str",
help="Name of the Zephyr board to build for.",
Expand Down Expand Up @@ -419,7 +419,7 @@ def _create_prj_conf(self, project_dir, options):
f.write("\n")

API_SERVER_CRT_LIBS_TOKEN = "<API_SERVER_CRT_LIBS>"
ENABLE_CMSIS_TOKEN = "<ENABLE_CMSIS>"
CMAKE_ARGS = "<CMAKE_ARGS>"

CRT_LIBS_BY_PROJECT_TYPE = {
"host_driven": "microtvm_rpc_server microtvm_rpc_common aot_executor_module aot_executor common",
Expand Down Expand Up @@ -457,6 +457,28 @@ def _cmsis_required(self, project_path: Union[str, pathlib.Path]) -> bool:
return True
return False

def _generate_cmake_args(self, mlf_extracted_path, options) -> str:
cmake_args = "\n# cmake args\n"
if options.get("verbose"):
cmake_args += "set(CMAKE_VERBOSE_MAKEFILE TRUE)\n"

if options.get("zephyr_base"):
cmake_args += f"set(ZEPHYR_BASE {options['zephyr_base']})\n"

if options.get("west_cmd"):
cmake_args += f"set(WEST {options['west_cmd']})\n"

if self._is_qemu(options):
# Some boards support more than one emulator, so ensure QEMU is set.
cmake_args += f"set(EMU_PLATFORM qemu)\n"

cmake_args += f"set(BOARD {options['zephyr_board']})\n"

enable_cmsis = self._cmsis_required(mlf_extracted_path)
cmake_args += f"set(ENABLE_CMSIS {str(enable_cmsis).upper()})\n"

return cmake_args

def generate_project(self, model_library_format_path, standalone_crt_dir, project_dir, options):
# Check Zephyr version
version = self._get_platform_version(get_zephyr_base(options))
Expand Down Expand Up @@ -510,9 +532,8 @@ def generate_project(self, model_library_format_path, standalone_crt_dir, projec
crt_libs = self.CRT_LIBS_BY_PROJECT_TYPE[options["project_type"]]
line = line.replace("<API_SERVER_CRT_LIBS>", crt_libs)

if self.ENABLE_CMSIS_TOKEN in line:
enable_cmsis = self._cmsis_required(extract_path)
line = line.replace(self.ENABLE_CMSIS_TOKEN, str(enable_cmsis).upper())
if self.CMAKE_ARGS in line:
line = self._generate_cmake_args(extract_path, options)

cmake_f.write(line)

Expand Down Expand Up @@ -542,23 +563,7 @@ def generate_project(self, model_library_format_path, standalone_crt_dir, projec
def build(self, options):
BUILD_DIR.mkdir()

cmake_args = ["cmake", ".."]
if options.get("verbose"):
cmake_args.append("-DCMAKE_VERBOSE_MAKEFILE:BOOL=TRUE")

if options.get("zephyr_base"):
cmake_args.append(f"-DZEPHYR_BASE:STRING={options['zephyr_base']}")

if options.get("west_cmd"):
cmake_args.append(f"-DWEST={options['west_cmd']}")

if self._is_qemu(options):
# Some boards support more than one emulator, so ensure QEMU is set.
cmake_args.append(f"-DEMU_PLATFORM=qemu")

cmake_args.append(f"-DBOARD:STRING={options['zephyr_board']}")

check_call(cmake_args, cwd=BUILD_DIR)
check_call(["cmake", ".."], cwd=BUILD_DIR)

args = ["make", "-j2"]
if options.get("verbose"):
Expand Down

0 comments on commit 0bfa420

Please sign in to comment.