mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-07-04 23:35:40 +08:00
58 lines
1.9 KiB
PHP
58 lines
1.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Package\Library;
|
|
|
|
use StaticPHP\Attribute\Package\BuildFor;
|
|
use StaticPHP\Attribute\Package\Library;
|
|
use StaticPHP\Package\LibraryPackage;
|
|
use StaticPHP\Runtime\Executor\UnixCMakeExecutor;
|
|
use StaticPHP\Runtime\Executor\WindowsCMakeExecutor;
|
|
use StaticPHP\Util\FileSystem;
|
|
|
|
#[Library('gmssl')]
|
|
class gmssl
|
|
{
|
|
#[BuildFor('Linux')]
|
|
#[BuildFor('Darwin')]
|
|
public function build(LibraryPackage $lib): void
|
|
{
|
|
UnixCMakeExecutor::create($lib)
|
|
->addConfigureArgs('-DENABLE_SM2_PRIVATE_KEY_EXPORT=ON')
|
|
->build();
|
|
}
|
|
|
|
#[BuildFor('Windows')]
|
|
public function buildWin(LibraryPackage $lib): void
|
|
{
|
|
$buildDir = "{$lib->getSourceDir()}\\builddir";
|
|
|
|
// GmSSL requires NMake Makefiles generator on Windows
|
|
WindowsCMakeExecutor::create($lib)
|
|
->setBuildDir($buildDir)
|
|
->setCustomDefaultArgs(
|
|
'-G "NMake Makefiles"',
|
|
'-DWIN32=ON',
|
|
'-DBUILD_SHARED_LIBS=OFF',
|
|
'-DENABLE_SM2_PRIVATE_KEY_EXPORT=ON',
|
|
'-DCMAKE_BUILD_TYPE=Release',
|
|
'-DCMAKE_C_FLAGS_RELEASE="/MT /O2 /Ob2 /DNDEBUG"',
|
|
'-DCMAKE_CXX_FLAGS_RELEASE="/MT /O2 /Ob2 /DNDEBUG"',
|
|
'-DCMAKE_INSTALL_PREFIX=' . escapeshellarg($lib->getBuildRootPath()),
|
|
'-B ' . escapeshellarg($buildDir),
|
|
)
|
|
->toStep(1)
|
|
->build();
|
|
|
|
cmd()->cd($buildDir)->exec('nmake gmssl XCFLAGS=/MT');
|
|
|
|
$libPath = "{$lib->getBuildRootPath()}/lib";
|
|
$incPath = "{$lib->getBuildRootPath()}/include/gmssl";
|
|
FileSystem::createDir($libPath);
|
|
FileSystem::createDir($incPath);
|
|
FileSystem::copy("{$buildDir}\\bin\\gmssl.lib", "{$libPath}/gmssl.lib");
|
|
FileSystem::copyDir("{$lib->getSourceDir()}\\include\\gmssl", $incPath);
|
|
}
|
|
}
|