feat: pass more arguments during CMake configuration (#78)

* feat: parse and pass `generator` input

* feat: parse and pass `c-compiler` and `cxx-compiler` inputs

* feat: parse and pass `c-flags` and `cxx-flags` inputs

* feat: parse and pass `options` input

* feat: parse and pass `args` input
This commit is contained in:
Alfi Maulana
2023-11-20 21:52:38 +07:00
committed by GitHub
parent 1829bd6347
commit 025d277e55
2 changed files with 54 additions and 2 deletions

View File

@@ -4,7 +4,36 @@ import exec from "@actions/exec";
async function main() {
const sourceDir = core.getInput("source-dir");
const buildDir = core.getInput("build-dir");
await exec.exec("cmake", [sourceDir || ".", "-B", buildDir || "build"]);
const configureArgs = [sourceDir || ".", "-B", buildDir || "build"];
const generator = core.getInput("generator");
if (generator) configureArgs.push(...["-G", generator]);
const cCompiler = core.getInput("c-compiler");
if (cCompiler) configureArgs.push("-DCMAKE_C_COMPILER=" + cCompiler);
const cxxCompiler = core.getInput("cxx-compiler");
if (cxxCompiler) configureArgs.push("-DCMAKE_CXX_COMPILER=" + cxxCompiler);
const cFlags = core.getMultilineInput("c-flags").join(" ");
if (cFlags) configureArgs.push("-DCMAKE_C_FLAGS=" + cFlags);
const cxxFlags = core.getMultilineInput("cxx-flags").join(" ");
if (cxxFlags) configureArgs.push("-DCMAKE_CXX_FLAGS=" + cxxFlags);
const options = core
.getMultilineInput("options")
.flatMap((opts) => opts.split(" "))
.map((opt) => "-D" + opt);
configureArgs.push(...options);
const args = core
.getMultilineInput("args")
.flatMap((args) => args.split(" "));
configureArgs.push(...args);
await exec.exec("cmake", configureArgs);
core.setOutput("build-dir", buildDir || "build");
const runBuild = core.getBooleanInput("run-build");