Skip to content
This repository was archived by the owner on Oct 18, 2023. It is now read-only.

Commit 3289136

Browse files
author
Simon Hofmann
committed
Updated opencvBuild import
1 parent d45182e commit 3289136

File tree

5 files changed

+28
-21
lines changed

5 files changed

+28
-21
lines changed

lib/commons.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,32 @@
1-
const fs = require('fs');
2-
const path = require('path');
1+
const path = require("path");
32

43
function resolvePath(filePath, file) {
54
if (!filePath) {
65
return undefined;
76
}
8-
return (file ? path.resolve(filePath, file) : path.resolve(filePath)).replace(/\\/g, '/');
7+
return (file ? path.resolve(filePath, file) : path.resolve(filePath)).replace(
8+
/\\/g,
9+
"/"
10+
);
911
}
1012

11-
const defaultDir = '/usr/local';
13+
const defaultDir = "/usr/local";
1214

1315
function getLibDir() {
14-
const libPath = resolvePath(process.env.OPENCV_LIB_DIR)
15-
if (process.platform === 'win32' && !libPath) {
16-
throw new Error('OPENCV_LIB_DIR is not defined')
16+
const libPath = resolvePath(process.env.OPENCV_LIB_DIR);
17+
if (process.platform === "win32" && !libPath) {
18+
throw new Error("OPENCV_LIB_DIR is not defined");
1719
}
1820
return libPath || `${defaultDir}/lib`;
1921
}
2022

23+
function linkSystemLibs() {
24+
return !!process.env.OPENCV_LINK_SYSTEM_LIBS;
25+
}
26+
2127
module.exports = {
2228
resolvePath,
2329
defaultDir,
24-
getLibDir
30+
getLibDir,
31+
linkSystemLibs
2532
};

lib/cv.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
const path = require('path');
2-
const opencvBuild = require('opencv-build');
3-
const { resolvePath } = require('./commons');
2+
const opencvBuild = require(`@nut-tree/opencv-build-${process.platform}`);
3+
const { resolvePath, linkSystemLibs } = require('./commons');
44

55
// ensure binaries are added to path on windows
6-
if (opencvBuild.isAutoBuildEnabled() && process.platform === 'win32') {
6+
if (!linkSystemLibs() && process.platform === 'win32') {
77
// append opencv binary path to node process
88
if (!process.env.path.includes(opencvBuild.opencvBinDir)) {
99
process.env.path = `${process.env.path};${opencvBuild.opencvBinDir};`

lib/defines.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
const opencvBuild = require('opencv-build');
2-
const { getLibDir } = require('./commons');
1+
const opencvBuild = require(`@nut-tree/opencv-build-${process.platform}`);
2+
const { getLibDir, linkSystemLibs } = require('./commons');
33

4-
if (!opencvBuild.isAutoBuildEnabled()) {
4+
if (linkSystemLibs()) {
55
opencvBuild.getLibs(getLibDir())
66
.filter(lib => lib.libPath)
77
.map(lib => lib.opencvModule)

lib/includes.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
const opencvBuild = require('opencv-build');
2-
const { resolvePath, defaultDir } = require('./commons');
1+
const opencvBuild = require(`@nut-tree/opencv-build-${process.platform}`);
2+
const { resolvePath, defaultDir, linkSystemLibs } = require('./commons');
33

4-
if (opencvBuild.isAutoBuildEnabled()) {
4+
if (linkSystemLibs()) {
55
console.log(resolvePath(process.env.OPENCV_INCLUDE_DIR) || `${defaultDir}/include`);
66
return;
77
}

lib/libs.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const opencvBuild = require('opencv-build');
2-
const { resolvePath, getLibDir } = require('./commons');
1+
const opencvBuild = require(`@nut-tree/opencv-build-${process.platform}`);
2+
const { resolvePath, getLibDir, linkSystemLibs } = require('./commons');
33

44
function linkLibs(libs) {
55
libs
@@ -8,7 +8,7 @@ function linkLibs(libs) {
88
.forEach(libPath => console.log(resolvePath(libPath)));
99
}
1010

11-
if (!opencvBuild.isAutoBuildEnabled()) {
11+
if (linkSystemLibs()) {
1212
linkLibs(opencvBuild.getLibs(getLibDir()));
1313
return;
1414
}
@@ -21,5 +21,5 @@ if (process.platform === 'win32') {
2121

2222
// if not windows, link libs dynamically
2323
console.log('-L' + resolvePath(opencvBuild.opencvLibDir));
24-
opencvBuild.opencvModules.forEach(lib => console.log('-lopencv_' + lib));
24+
opencvBuild.opencvModules.forEach(lib => console.log(`-lopencv_${lib}`));
2525
console.log('-Wl,-rpath,' + resolvePath(opencvBuild.opencvLibDir));

0 commit comments

Comments
 (0)