2023-04-30 14:22:59 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace SPC\builder\unix\library;
|
|
|
|
|
|
2025-06-09 01:07:30 +08:00
|
|
|
use SPC\builder\unix\executor\UnixCMakeExecutor;
|
2023-08-20 19:51:45 +08:00
|
|
|
use SPC\exception\FileSystemException;
|
|
|
|
|
use SPC\exception\RuntimeException;
|
2023-04-30 14:22:59 +08:00
|
|
|
use SPC\store\FileSystem;
|
|
|
|
|
|
|
|
|
|
trait libevent
|
|
|
|
|
{
|
2024-07-09 15:05:53 +08:00
|
|
|
public function beforePack(): void
|
|
|
|
|
{
|
|
|
|
|
if (file_exists(BUILD_LIB_PATH . '/cmake/libevent/LibeventTargets-static.cmake')) {
|
|
|
|
|
FileSystem::replaceFileRegex(
|
|
|
|
|
BUILD_LIB_PATH . '/cmake/libevent/LibeventTargets-static.cmake',
|
|
|
|
|
'/set\(_IMPORT_PREFIX .*\)/m',
|
|
|
|
|
'set(_IMPORT_PREFIX "{BUILD_ROOT_PATH}")'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
FileSystem::replaceFileRegex(
|
|
|
|
|
BUILD_LIB_PATH . '/cmake/libevent/LibeventTargets-static.cmake',
|
|
|
|
|
'/INTERFACE_INCLUDE_DIRECTORIES ".*"/m',
|
|
|
|
|
'INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include"'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
FileSystem::replaceFileRegex(
|
|
|
|
|
BUILD_LIB_PATH . '/cmake/libevent/LibeventTargets-static.cmake',
|
|
|
|
|
'/INTERFACE_LINK_LIBRARIES "libevent::core;.*"/m',
|
|
|
|
|
'INTERFACE_LINK_LIBRARIES "libevent::core;${_IMPORT_PREFIX}/lib/libssl.a;${_IMPORT_PREFIX}/lib/libcrypto.a"'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-20 19:51:45 +08:00
|
|
|
/**
|
|
|
|
|
* @throws RuntimeException
|
|
|
|
|
* @throws FileSystemException
|
|
|
|
|
*/
|
|
|
|
|
protected function build(): void
|
2023-04-30 14:22:59 +08:00
|
|
|
{
|
2025-06-09 01:07:30 +08:00
|
|
|
UnixCMakeExecutor::create($this)
|
|
|
|
|
->addConfigureArgs(
|
|
|
|
|
'-DEVENT__LIBRARY_TYPE=STATIC',
|
|
|
|
|
'-DEVENT__DISABLE_BENCHMARK=ON',
|
|
|
|
|
'-DEVENT__DISABLE_THREAD_SUPPORT=ON',
|
|
|
|
|
'-DEVENT__DISABLE_MBEDTLS=ON',
|
|
|
|
|
'-DEVENT__DISABLE_TESTS=ON',
|
|
|
|
|
'-DEVENT__DISABLE_SAMPLES=ON',
|
2023-04-30 14:22:59 +08:00
|
|
|
)
|
2025-06-09 01:07:30 +08:00
|
|
|
->build();
|
2024-07-09 15:05:53 +08:00
|
|
|
|
|
|
|
|
$this->patchPkgconfPrefix(['libevent.pc', 'libevent_core.pc', 'libevent_extra.pc', 'libevent_openssl.pc']);
|
|
|
|
|
|
|
|
|
|
$this->patchPkgconfPrefix(
|
|
|
|
|
['libevent_openssl.pc'],
|
|
|
|
|
PKGCONF_PATCH_CUSTOM,
|
|
|
|
|
[
|
|
|
|
|
'/Libs.private:.*/m',
|
|
|
|
|
'Libs.private: -lssl -lcrypto',
|
|
|
|
|
]
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function install(): void
|
|
|
|
|
{
|
|
|
|
|
FileSystem::replaceFileStr(
|
|
|
|
|
BUILD_LIB_PATH . '/cmake/libevent/LibeventTargets-static.cmake',
|
|
|
|
|
'{BUILD_ROOT_PATH}',
|
|
|
|
|
BUILD_ROOT_PATH
|
|
|
|
|
);
|
2023-04-30 14:22:59 +08:00
|
|
|
}
|
|
|
|
|
}
|