cmake-action/src/cmake.ts
Alfi Maulana d1c539d005
refactor: refactor inputs to context (#400)
* refactor: rename `inputs` to `context`

* refactor: merge compiler and flags inputs to options input

* refactor: separate configure and build context
2024-08-07 22:20:14 +08:00

38 lines
949 B
TypeScript

import { execFileSync } from "node:child_process";
import type { Context } from "./context.js";
/**
* Configures the build system of a CMake project.
*
* @param context - The action context.
*/
export function configureProject(context: Context): void {
const configureArgs = [];
if (context.sourceDir) {
configureArgs.push(context.sourceDir);
}
configureArgs.push("-B", context.buildDir);
if (context.configure.generator) {
configureArgs.push(...["-G", context.configure.generator]);
}
configureArgs.push(...context.configure.options.map((opt) => "-D" + opt));
configureArgs.push(...context.configure.args);
execFileSync("cmake", configureArgs, { stdio: "inherit" });
}
/**
* Build a CMake project.
*
* @param context - The action context.
*/
export function buildProject(context: Context): void {
execFileSync("cmake", ["--build", context.buildDir, ...context.build.args], {
stdio: "inherit",
});
}