From 7d26aa533a317aed8595c06b4f3edbbd96a43d3e Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Mon, 9 Jun 2025 00:34:25 +0800 Subject: [PATCH] Add cmake tool functions --- .../builder/unix/executor/UnixCMakeExecutor.php | 15 ++++++++++----- src/globals/functions.php | 6 ++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/SPC/builder/unix/executor/UnixCMakeExecutor.php b/src/SPC/builder/unix/executor/UnixCMakeExecutor.php index b74d8fc8..421bd4bb 100644 --- a/src/SPC/builder/unix/executor/UnixCMakeExecutor.php +++ b/src/SPC/builder/unix/executor/UnixCMakeExecutor.php @@ -48,14 +48,19 @@ class UnixCMakeExecutor extends Executor * Add optional library configuration. * This method checks if a library is available and adds the corresponding arguments to the CMake configuration. * - * @param string $name library name to check - * @param string $true_args arguments to use if the library is available - * @param string $false_args arguments to use if the library is not available + * @param string $name library name to check + * @param \Closure|string $true_args arguments to use if the library is available (allow closure, returns string) + * @param string $false_args arguments to use if the library is not available * @return $this */ - public function optionalLib(string $name, string $true_args, string $false_args = ''): static + public function optionalLib(string $name, \Closure|string $true_args, string $false_args = ''): static { - $this->addConfigureArgs($this->library->getBuilder()->getLib($name) ? $true_args : $false_args); + if ($get = $this->library->getBuilder()->getLib($name)) { + $args = $true_args instanceof \Closure ? $true_args($get) : $true_args; + } else { + $args = $false_args; + } + $this->addConfigureArgs($args); return $this; } diff --git a/src/globals/functions.php b/src/globals/functions.php index 1b5474cb..ea96df58 100644 --- a/src/globals/functions.php +++ b/src/globals/functions.php @@ -210,3 +210,9 @@ function get_cmake_version(): ?string } return null; } + +function cmake_boolean_args(string $arg_name, bool $negative = false): array +{ + $res = ["-D{$arg_name}=ON", "-D{$arg_name}=OFF"]; + return $negative ? array_reverse($res) : $res; +}