Add cmake tool functions

This commit is contained in:
crazywhalecc 2025-06-09 00:34:25 +08:00
parent 521af84797
commit 7d26aa533a
No known key found for this signature in database
GPG Key ID: 1F4BDD59391F2680
2 changed files with 16 additions and 5 deletions

View File

@ -48,14 +48,19 @@ class UnixCMakeExecutor extends Executor
* Add optional library configuration. * Add optional library configuration.
* This method checks if a library is available and adds the corresponding arguments to the CMake 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 $name library name to check
* @param string $true_args arguments to use if the library is available * @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 * @param string $false_args arguments to use if the library is not available
* @return $this * @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; return $this;
} }

View File

@ -210,3 +210,9 @@ function get_cmake_version(): ?string
} }
return null; 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;
}