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

Commit e3996c2

Browse files
author
Simon Hofmann
committed
Added defaults file to properly configure the build when no env vars are set (prebuild)
1 parent 298227f commit e3996c2

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

install/defaults.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
const opencvBuild = require(`@nut-tree/opencv-build-${process.platform}`)
2+
const { resolvePath } = require('../lib/commons')
3+
const fs = require('fs')
4+
5+
const libDir = resolvePath(opencvBuild.opencvLibDir);
6+
7+
if (!fs.existsSync(libDir)) {
8+
throw new Error("library dir does not exist: " + libDir);
9+
}
10+
11+
const libsFoundInDir = opencvBuild.getLibs(libDir).filter(lib => lib.libPath);
12+
13+
if (!libsFoundInDir.length) {
14+
throw new Error("No OpenCV libraries found in lib dir: " + libDir);
15+
}
16+
17+
const defines = libsFoundInDir.map(
18+
lib => `OPENCV4NODEJS_FOUND_LIBRARY_${lib.opencvModule.toUpperCase()}`
19+
);
20+
21+
const inc = [
22+
resolvePath(opencvBuild.opencvInclude),
23+
resolvePath(opencvBuild.opencv4Include)
24+
];
25+
26+
const libs = opencvBuild.isWin()
27+
? libsFoundInDir.map(lib => resolvePath(lib.libPath))
28+
: // dynamically link libs if not on windows
29+
["-L" + libDir]
30+
.concat(libsFoundInDir.map(lib => "-lopencv_" + lib.opencvModule))
31+
.concat("-Wl,-rpath," + libDir);
32+
33+
module.exports = {
34+
OPENCV4NODEJS_LIBRARIES: () => libs.join("\n"),
35+
OPENCV4NODEJS_INCLUDES: () => inc.join("\n"),
36+
OPENCV4NODEJS_DEFINES: () => defines.join("\n")
37+
}

0 commit comments

Comments
 (0)