Skip to content

Commit a13b204

Browse files
Added CMake support to 'ner build'. If CMake is detected, it runs CMake commands instead of Makefile commands.
1 parent c7704a9 commit a13b204

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

ner_environment/build_system/build_system.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,26 @@ def unsupported_option_cb(value:bool):
4747
# Build command
4848
# ==============================================================================
4949

50-
@app.command(help="Build the project with GCC ARM Toolchain and Make")
50+
@app.command(help="Build the project with GCC ARM Toolchain and Make/CMake")
5151
def build(profile: str = typer.Option(None, "--profile", "-p", callback=unsupported_option_cb, help="(planned) Specify the build profile (e.g., debug, release)", show_default=True),
5252
clean: bool = typer.Option(False, "--clean", help="Clean the build directory before building", show_default=True)):
5353

54-
if clean:
55-
command = ["docker", "compose", "run", "--rm", "ner-gcc-arm", "make", "clean"]
56-
else:
57-
command = ["docker", "compose", "run", "--rm", "ner-gcc-arm", "make", f"-j{os.cpu_count()}"]
58-
run_command(command, stream_output=True)
54+
is_cmake = os.path.exists("CMakeLists.txt")
55+
56+
if is_cmake: # Repo uses CMake, so execute CMake commands.
57+
# If the build directory doesn't exist, make it and configure CMake
58+
if not os.path.exists("build"):
59+
run_command(["docker", "compose", "run", "--rm", "ner-gcc-arm", "mkdir", "-p", "build"], stream_output=True)
60+
run_command(["docker", "compose", "run", "--rm", "ner-gcc-arm", "cmake", "-S", ".", "-B", "build"], stream_output=True)
61+
if clean:
62+
run_command(["docker", "compose", "run", "--rm", "ner-gcc-arm", "cmake", "--build", "build", "--target", "clean"], stream_output=True)
63+
else:
64+
run_command(["docker", "compose", "run", "--rm", "ner-gcc-arm", "cmake", "--build", "build", f"-j{os.cpu_count()}"], stream_output=True)
65+
else: # Repo uses Make, so execute Make commands.
66+
if clean:
67+
run_command(["docker", "compose", "run", "--rm", "ner-gcc-arm", "make", "clean"], stream_output=True)
68+
else:
69+
run_command(["docker", "compose", "run", "--rm", "ner-gcc-arm", "make", f"-j{os.cpu_count()}"], stream_output=True)
5970

6071
# ==============================================================================
6172
# Clang command

0 commit comments

Comments
 (0)