Skip to content

Commit 2d96e25

Browse files
committed
cmake 安装
1 parent c1055df commit 2d96e25

File tree

3 files changed

+86
-1
lines changed

3 files changed

+86
-1
lines changed

change.log

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# 修改记录
2+
3+
4+
5+
6+
7+
8+
9+
## 1.0.0
10+
11+
2019年6月25日
12+
13+
- 1.简单安装命令
+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/bin/bash
22

33
# Detecting cmake on the system https://stackoverflow.com/questions/592620/how-to-check-if-a-program-exists-from-a-bash-script
4+
# 检测是否有cmake,如果没有则自动安装cmake
45
command -v cmake >/dev/null 2>&1 || { echo >&2 "Compiling OpenCV requires cmake, but no cmake was detected for system installation. Aborting."; exit 1; }
56
command -v pkg-config >/dev/null 2>&1 || { echo >&2 "Compiling OpenCV requires pkg-config, but no cmake was detected for system installation. Aborting."; exit 1; }

src/Command/Install.php

+72-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ class Install extends Command
2121
protected $installInfo = [];
2222

2323

24-
2524
use CommonTrait;
2625

2726
/**
@@ -44,6 +43,74 @@ protected function configure()
4443
}
4544

4645

46+
/**
47+
* 检测系统
48+
* @author hihozhou
49+
*/
50+
protected function checkOs()
51+
{
52+
if (file_exists('/usr/bin/yum')) {
53+
$pm = 'yum';
54+
$process = new Process('command -v lsb_release >/dev/null 2>&1 || { yum -y install redhat-lsb-core; }');//todo 给予当前用户
55+
try {
56+
$process->mustRun();
57+
} catch (\Exception $e) {
58+
throw new RuntimeException($process->getErrorOutput());
59+
}
60+
} else if (file_exists('/usr/bin/apt-get')) {
61+
$pm = 'apt-get';
62+
$process = new Process('command -v lsb_release >/dev/null 2>&1 || { yum -y install redhat-lsb-core; }');//todo 给予当前用户
63+
try {
64+
$process->mustRun();
65+
} catch (\Exception $e) {
66+
throw new RuntimeException($process->getErrorOutput());
67+
}
68+
}
69+
//
70+
$process = new Process('command -v lsb_release >/dev/null 2>&1 || { echo >&2 "Fail to use lsb_release!"; exit 1; }');
71+
try {
72+
$process->mustRun();
73+
} catch (\Exception $e) {
74+
throw new RuntimeException($process->getErrorOutput());
75+
}
76+
77+
78+
// if (file_exists('/etc/redhat-release')) {
79+
// //RedHat,Centos
80+
// $OS = 'CentOS';
81+
// }elseif (){}
82+
// else {
83+
// throw new RuntimeException('Does not support this OS, Please contact the author!');
84+
// }
85+
}
86+
87+
88+
//todo 检测并安装cmake
89+
protected function checkCmakeOrInstall(OutputInterface $output)
90+
{
91+
92+
$checkCommad = 'command -v cmake1 >/dev/null 2>&1 || { echo >&2 "Compiling OpenCV requires cmake, but no cmake was detected for system installation. Aborting."; exit 1; }';
93+
$process = new Process($checkCommad);//todo 给予当前用户
94+
try {
95+
$process->mustRun();
96+
} catch (\Exception $e) {
97+
98+
$output->writeln('Try install cmake.');
99+
// throw new RuntimeException($process->getErrorOutput());
100+
//安装cmake
101+
//检测系统
102+
//如果是ubuntu,直接apt-get
103+
//如果是centos则安装编译安装cmake
104+
$process = new Process('sudo apt-get install -y cmake');
105+
$process->mustRun();
106+
}
107+
108+
}
109+
110+
111+
//todo 检测并安装pkg-config
112+
113+
47114
/**
48115
* 检测安装环境
49116
* @author hihozhou
@@ -331,6 +398,7 @@ protected function getPecl(OutputInterface $output)
331398
protected function execute(InputInterface $input, OutputInterface $output)
332399
{
333400

401+
$this->checkOs();
334402
$peclBin = $this->getPecl($output);
335403
//todo 判断找到的pecl对应的php和执行的php是否相同
336404
//pecl config-get bin_dir ,找到bin目录
@@ -358,6 +426,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
358426

359427
$this->checkIsRoot();
360428
$this->checkExtensionIsInstall($output);
429+
430+
$this->checkCmakeOrInstall($output);
431+
361432
$this->buildEnvDetection();
362433
//创建目录
363434
$directory = $input->getOption('path');

0 commit comments

Comments
 (0)