From dabf52511f84b068f4ebc9344f462f2d4348deeb Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Wed, 4 Jun 2025 17:18:09 +0700 Subject: [PATCH 1/4] force minimum version 3.5 for cmake policies in freetype --- src/SPC/builder/unix/library/freetype.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SPC/builder/unix/library/freetype.php b/src/SPC/builder/unix/library/freetype.php index 42e8f91c..fa035f3d 100644 --- a/src/SPC/builder/unix/library/freetype.php +++ b/src/SPC/builder/unix/library/freetype.php @@ -25,7 +25,7 @@ trait freetype shell()->cd($this->source_dir . '/build') ->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()]) ->execWithEnv( - "cmake {$this->builder->makeCmakeArgs()} -DFT_DISABLE_HARFBUZZ=ON " . + "cmake {$this->builder->makeCmakeArgs()} -DFT_DISABLE_HARFBUZZ=ON -DCMAKE_POLICY_VERSION_MINIMUM=3.5 " . '-DBUILD_SHARED_LIBS=OFF ' . "{$extra_libs}.." ) From ef7ebdfd1f146abe6fa38672e5905947fda181b9 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Wed, 4 Jun 2025 21:18:44 +0700 Subject: [PATCH 2/4] force minimum version 3.12 for cmake policies in freetype, only when cmake >= 4 --- src/SPC/builder/unix/library/freetype.php | 6 +++++- src/SPC/doctor/item/LinuxToolCheckList.php | 17 +++++++---------- src/globals/functions.php | 18 ++++++++++++++++++ src/globals/test-extensions.php | 8 ++++---- 4 files changed, 34 insertions(+), 15 deletions(-) diff --git a/src/SPC/builder/unix/library/freetype.php b/src/SPC/builder/unix/library/freetype.php index fa035f3d..7f553391 100644 --- a/src/SPC/builder/unix/library/freetype.php +++ b/src/SPC/builder/unix/library/freetype.php @@ -18,6 +18,10 @@ trait freetype */ protected function build(): void { + $extra = ''; + if (version_compare(get_cmake_version(), '4.0.0', '>=')) { + $extra .= '-DCMAKE_POLICY_VERSION_MINIMUM=3.12 '; + } $extra_libs = $this->builder->getLib('libpng') ? '-DFT_DISABLE_PNG=OFF ' : '-DFT_DISABLE_PNG=ON '; $extra_libs .= $this->builder->getLib('bzip2') ? '-DFT_DISABLE_BZIP2=OFF ' : '-DFT_DISABLE_BZIP2=ON '; $extra_libs .= $this->builder->getLib('brotli') ? '-DFT_DISABLE_BROTLI=OFF ' : '-DFT_DISABLE_BROTLI=ON '; @@ -25,7 +29,7 @@ trait freetype shell()->cd($this->source_dir . '/build') ->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()]) ->execWithEnv( - "cmake {$this->builder->makeCmakeArgs()} -DFT_DISABLE_HARFBUZZ=ON -DCMAKE_POLICY_VERSION_MINIMUM=3.5 " . + "cmake {$this->builder->makeCmakeArgs()} -DFT_DISABLE_HARFBUZZ=ON {$extra}" . '-DBUILD_SHARED_LIBS=OFF ' . "{$extra_libs}.." ) diff --git a/src/SPC/doctor/item/LinuxToolCheckList.php b/src/SPC/doctor/item/LinuxToolCheckList.php index 03702a84..976d5fd6 100644 --- a/src/SPC/doctor/item/LinuxToolCheckList.php +++ b/src/SPC/doctor/item/LinuxToolCheckList.php @@ -87,17 +87,14 @@ class LinuxToolCheckList #[AsCheckItem('if cmake version >= 3.18', limit_os: 'Linux')] public function checkCMakeVersion(): ?CheckResult { - $check_cmd = 'cmake --version'; - $pattern = '/cmake version (.*)/m'; - $out = shell()->execWithResult($check_cmd, false)[1][0]; - if (preg_match($pattern, $out, $match)) { - $ver = $match[1]; - if (version_compare($ver, '3.18.0') <= 0) { - return CheckResult::fail('cmake version is too low (' . $ver . '), please update it manually!'); - } - return CheckResult::ok($match[1]); + $ver = get_cmake_version(); + if ($ver === null) { + return CheckResult::fail('Failed to get cmake version'); } - return CheckResult::fail('Failed to get cmake version'); + if (version_compare($ver, '3.18.0') < 0) { + return CheckResult::fail('cmake version is too low (' . $ver . '), please update it manually!'); + } + return CheckResult::ok($ver); } /** @noinspection PhpUnused */ diff --git a/src/globals/functions.php b/src/globals/functions.php index 8432f947..cd1eb668 100644 --- a/src/globals/functions.php +++ b/src/globals/functions.php @@ -192,3 +192,21 @@ function f_putenv(string $env): bool logger()->debug('Setting env: ' . $env); return putenv($env); } + +/** + * Get the installed CMake version + * + * @return string|null The CMake version or null if it couldn't be determined + */ +function get_cmake_version(): ?string +{ + try { + [,$output] = shell()->execWithResult('cmake --version', false); + if (preg_match('/cmake version ([\d.]+)/i', $output[0], $matches)) { + return $matches[1]; + } + } catch (Exception $e) { + logger()->warning('Failed to get CMake version: ' . $e->getMessage()); + } + return null; +} diff --git a/src/globals/test-extensions.php b/src/globals/test-extensions.php index cee316e0..5e6200f9 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -13,9 +13,9 @@ declare(strict_types=1); // test php version (8.1 ~ 8.4 available, multiple for matrix) $test_php_version = [ - // '8.1', - // '8.2', - // '8.3', + '8.1', + '8.2', + '8.3', '8.4', ]; @@ -23,7 +23,7 @@ $test_php_version = [ $test_os = [ // 'macos-13', // 'macos-14', - 'macos-15', + // 'macos-15', 'ubuntu-latest', // 'ubuntu-22.04', // 'ubuntu-24.04', From 5add5348488e83ee84a804a5d65f35f88d641544 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Wed, 4 Jun 2025 21:20:00 +0700 Subject: [PATCH 3/4] don't use two extra variables --- src/SPC/builder/unix/library/freetype.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/SPC/builder/unix/library/freetype.php b/src/SPC/builder/unix/library/freetype.php index 7f553391..94998b7c 100644 --- a/src/SPC/builder/unix/library/freetype.php +++ b/src/SPC/builder/unix/library/freetype.php @@ -22,16 +22,16 @@ trait freetype if (version_compare(get_cmake_version(), '4.0.0', '>=')) { $extra .= '-DCMAKE_POLICY_VERSION_MINIMUM=3.12 '; } - $extra_libs = $this->builder->getLib('libpng') ? '-DFT_DISABLE_PNG=OFF ' : '-DFT_DISABLE_PNG=ON '; - $extra_libs .= $this->builder->getLib('bzip2') ? '-DFT_DISABLE_BZIP2=OFF ' : '-DFT_DISABLE_BZIP2=ON '; - $extra_libs .= $this->builder->getLib('brotli') ? '-DFT_DISABLE_BROTLI=OFF ' : '-DFT_DISABLE_BROTLI=ON '; + $extra .= $this->builder->getLib('libpng') ? '-DFT_DISABLE_PNG=OFF ' : '-DFT_DISABLE_PNG=ON '; + $extra .= $this->builder->getLib('bzip2') ? '-DFT_DISABLE_BZIP2=OFF ' : '-DFT_DISABLE_BZIP2=ON '; + $extra .= $this->builder->getLib('brotli') ? '-DFT_DISABLE_BROTLI=OFF ' : '-DFT_DISABLE_BROTLI=ON '; FileSystem::resetDir($this->source_dir . '/build'); shell()->cd($this->source_dir . '/build') ->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()]) ->execWithEnv( - "cmake {$this->builder->makeCmakeArgs()} -DFT_DISABLE_HARFBUZZ=ON {$extra}" . + "cmake {$this->builder->makeCmakeArgs()} -DFT_DISABLE_HARFBUZZ=ON " . '-DBUILD_SHARED_LIBS=OFF ' . - "{$extra_libs}.." + "{$extra}.." ) ->execWithEnv('make clean') ->execWithEnv("make -j{$this->builder->concurrency}") From 1b7404f194527d57aa50a47661cabef9f8a662ca Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Wed, 4 Jun 2025 21:22:05 +0700 Subject: [PATCH 4/4] php cs fix --- src/globals/functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/globals/functions.php b/src/globals/functions.php index cd1eb668..1b5474cb 100644 --- a/src/globals/functions.php +++ b/src/globals/functions.php @@ -196,7 +196,7 @@ function f_putenv(string $env): bool /** * Get the installed CMake version * - * @return string|null The CMake version or null if it couldn't be determined + * @return null|string The CMake version or null if it couldn't be determined */ function get_cmake_version(): ?string {