mirror of
https://github.com/threeal/cmake-action.git
synced 2025-06-10 03:01:21 +00:00
* feat: remove setting the default of `source-dir` to `.` * feat: append source dir to configure Cmake args only if specified
52 lines
1.2 KiB
TypeScript
52 lines
1.2 KiB
TypeScript
import { exec } from "@actions/exec";
|
|
import type { Inputs } from "./inputs.js";
|
|
|
|
/**
|
|
* Configures the build system of a CMake project.
|
|
*
|
|
* @param inputs - The action inputs.
|
|
*/
|
|
export async function configureProject(inputs: Inputs): Promise<void> {
|
|
const configureArgs = [];
|
|
|
|
if (inputs.sourceDir) {
|
|
configureArgs.push(inputs.sourceDir);
|
|
}
|
|
|
|
configureArgs.push("-B", inputs.buildDir);
|
|
|
|
if (inputs.generator) {
|
|
configureArgs.push(...["-G", inputs.generator]);
|
|
}
|
|
|
|
if (inputs.cCompiler) {
|
|
configureArgs.push("-DCMAKE_C_COMPILER=" + inputs.cCompiler);
|
|
}
|
|
|
|
if (inputs.cxxCompiler) {
|
|
configureArgs.push("-DCMAKE_CXX_COMPILER=" + inputs.cxxCompiler);
|
|
}
|
|
|
|
if (inputs.cFlags) {
|
|
configureArgs.push("-DCMAKE_C_FLAGS=" + inputs.cFlags);
|
|
}
|
|
|
|
if (inputs.cxxFlags) {
|
|
configureArgs.push("-DCMAKE_CXX_FLAGS=" + inputs.cxxFlags);
|
|
}
|
|
|
|
configureArgs.push(...inputs.options.map((opt) => "-D" + opt));
|
|
configureArgs.push(...inputs.args);
|
|
|
|
await exec("cmake", configureArgs);
|
|
}
|
|
|
|
/**
|
|
* Build a CMake project.
|
|
*
|
|
* @param inputs - The action inputs.
|
|
*/
|
|
export async function buildProject(inputs: Inputs): Promise<void> {
|
|
await exec("cmake", ["--build", inputs.buildDir, ...inputs.buildArgs]);
|
|
}
|