|
4 | 4 |
|
5 | 5 | namespace SPC\builder\traits; |
6 | 6 |
|
7 | | -use SPC\exception\FileSystemException; |
8 | | -use SPC\store\FileSystem; |
9 | | - |
10 | 7 | /** |
11 | 8 | * Unix 系统的工具函数 Trait,适用于 Linux、macOS |
12 | 9 | */ |
13 | 10 | trait UnixSystemUtilTrait |
14 | 11 | { |
15 | | - /** |
16 | | - * 生成 toolchain.cmake,用于 cmake 构建 |
17 | | - * |
18 | | - * @param string $os 操作系统代号 |
19 | | - * @param string $target_arch 目标架构 |
20 | | - * @param string $cflags CFLAGS 参数 |
21 | | - * @param null|string $cc CC 参数(默认空) |
22 | | - * @param null|string $cxx CXX 参数(默认空) |
23 | | - * @throws FileSystemException |
24 | | - */ |
25 | | - public static function makeCmakeToolchainFile( |
26 | | - string $os, |
27 | | - string $target_arch, |
28 | | - string $cflags, |
29 | | - ?string $cc = null, |
30 | | - ?string $cxx = null |
31 | | - ): string { |
32 | | - logger()->debug("making cmake tool chain file for {$os} {$target_arch} with CFLAGS='{$cflags}'"); |
33 | | - $root = BUILD_ROOT_PATH; |
34 | | - $ccLine = ''; |
35 | | - if ($cc) { |
36 | | - $ccLine = 'SET(CMAKE_C_COMPILER ' . $cc . ')'; |
37 | | - } |
38 | | - $cxxLine = ''; |
39 | | - if ($cxx) { |
40 | | - $cxxLine = 'SET(CMAKE_CXX_COMPILER ' . $cxx . ')'; |
41 | | - } |
42 | | - $toolchain = <<<CMAKE |
43 | | -{$ccLine} |
44 | | -{$cxxLine} |
45 | | -SET(CMAKE_C_FLAGS "{$cflags}") |
46 | | -SET(CMAKE_CXX_FLAGS "{$cflags}") |
47 | | -SET(CMAKE_FIND_ROOT_PATH "{$root}") |
48 | | -SET(CMAKE_PREFIX_PATH "{$root}") |
49 | | -SET(CMAKE_INSTALL_PREFIX "{$root}") |
50 | | -SET(CMAKE_INSTALL_LIBDIR "lib") |
51 | | -
|
52 | | -set(PKG_CONFIG_EXECUTABLE "{$root}/bin/pkg-config") |
53 | | -set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) |
54 | | -set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) |
55 | | -set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) |
56 | | -set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) |
57 | | -set(CMAKE_EXE_LINKER_FLAGS "-ldl -lpthread -lm -lutil") |
58 | | -CMAKE; |
59 | | - // 有时候系统的 cmake 找不到 ar 命令,真奇怪 |
60 | | - if (PHP_OS_FAMILY === 'Linux') { |
61 | | - $toolchain .= "\nSET(CMAKE_AR \"ar\")"; |
62 | | - } |
63 | | - FileSystem::writeFile(SOURCE_PATH . '/toolchain.cmake', $toolchain); |
64 | | - return realpath(SOURCE_PATH . '/toolchain.cmake'); |
65 | | - } |
66 | | - |
67 | 12 | /** |
68 | 13 | * @param string $name 命令名称 |
69 | 14 | * @param array $paths 寻找的目标路径(如果不传入,则使用环境变量 PATH) |
|
0 commit comments