mirror of
https://github.com/threeal/cmake-action.git
synced 2025-04-22 11:31:21 +00:00
* refactor: rename `inputs` to `context` * refactor: merge compiler and flags inputs to options input * refactor: separate configure and build context
38 lines
949 B
TypeScript
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",
|
|
});
|
|
}
|