tangled
alpha
login
or
join now
pyrox.dev
/
nixpkgs
0
fork
atom
lol
0
fork
atom
overview
issues
pulls
pipelines
opencv4: cuda: fix libstdc++ errors
Someone Serge
2 years ago
4735963a
a122884c
+26
-29
1 changed file
expand all
collapse all
unified
split
pkgs
development
libraries
opencv
4.x.nix
+26
-29
pkgs/development/libraries/opencv/4.x.nix
···
83
, Accelerate
84
, bzip2
85
, callPackage
86
-
}:
87
88
let
89
version = "4.7.0";
0
0
0
0
0
90
91
src = fetchFromGitHub {
92
owner = "opencv";
···
121
sha256 = "1msbkc3zixx61rcg6a04i1bcfhw1phgsrh93glq1n80hgsk3nbjq";
122
} + "/ippicv";
123
files = let name = platform: "ippicv_2019_${platform}_general_20180723.tgz"; in
124
-
if stdenv.hostPlatform.system == "x86_64-linux" then
125
{ ${name "lnx_intel64"} = "c0bd78adb4156bbf552c1dfe90599607"; }
126
-
else if stdenv.hostPlatform.system == "i686-linux" then
127
{ ${name "lnx_ia32"} = "4f38432c30bfd6423164b7a24bbc98a0"; }
128
-
else if stdenv.hostPlatform.system == "x86_64-darwin" then
129
{ ${name "mac_intel64"} = "fe6b2bb75ae0e3f19ad3ae1a31dfa4a2"; }
130
else
131
throw "ICV is not available for this platform (or not yet supported by this package)";
···
232
#https://github.com/xianyi/OpenBLAS/wiki/Faq/4bded95e8dc8aadc70ce65267d1093ca7bdefc4c#multi-threaded
233
openblas_ = blas.provider.override { singleThreaded = true; };
234
235
-
inherit (cudaPackages) backendStdenv cudaFlags cudaVersion;
236
inherit (cudaFlags) cudaCapabilities;
237
238
cuda-common-redist = with cudaPackages; [
0
239
cuda_cccl # <thrust/*>
240
libnpp # npp.h
241
] ++ lib.optionals enableCublas [
···
246
libcufft # cufft.h
247
];
248
249
-
cuda-native-redist = symlinkJoin {
250
-
name = "cuda-native-redist-${cudaVersion}";
251
-
paths = with cudaPackages; [
252
-
cuda_cudart # cuda_runtime.h
253
-
cuda_nvcc
254
-
] ++ cuda-common-redist;
255
-
};
256
-
257
cuda-redist = symlinkJoin {
258
name = "cuda-redist-${cudaVersion}";
259
paths = cuda-common-redist;
260
};
261
in
262
263
-
stdenv.mkDerivation {
264
pname = "opencv";
265
inherit version src;
266
···
319
320
buildInputs = [ zlib pcre boost gflags protobuf3_21 ]
321
++ lib.optional enablePython pythonPackages.python
322
-
++ lib.optional (stdenv.buildPlatform == stdenv.hostPlatform) hdf5
323
++ lib.optional enableGtk2 gtk2
324
++ lib.optional enableGtk3 gtk3
325
++ lib.optional enableVtk vtk
···
330
++ lib.optionals enableEXR [ openexr ilmbase ]
331
++ lib.optional enableJPEG2000 openjpeg
332
++ lib.optional enableFfmpeg ffmpeg
333
-
++ lib.optionals (enableFfmpeg && stdenv.isDarwin)
334
[ VideoDecodeAcceleration bzip2 ]
335
++ lib.optionals enableGStreamer (with gst_all_1; [ gstreamer gst-plugins-base gst-plugins-good ])
336
++ lib.optional enableOvis ogre
···
343
# tesseract & leptonica.
344
++ lib.optionals enableTesseract [ tesseract leptonica ]
345
++ lib.optional enableTbb tbb
346
-
++ lib.optionals stdenv.isDarwin [
347
bzip2 AVFoundation Cocoa VideoDecodeAcceleration CoreMedia MediaToolbox Accelerate
348
]
349
++ lib.optionals enableDocs [ doxygen graphviz-nox ]
···
357
pythonPackages.pip
358
pythonPackages.wheel
359
pythonPackages.setuptools
360
-
] ++ lib.optionals enableCuda [ cuda-native-redist ];
0
0
361
362
env.NIX_CFLAGS_COMPILE = lib.optionalString enableEXR "-I${ilmbase.dev}/include/OpenEXR";
363
···
400
(opencvFlag "ENABLE_LTO" enableLto)
401
(opencvFlag "ENABLE_THIN_LTO" (
402
enableLto && (
403
-
# Only clang supports thin LTO, so we must either be using clang through the stdenv,
404
-
stdenv.cc.isClang ||
405
-
# or through the backend stdenv.
406
-
(enableCuda && backendStdenv.cc.isClang)
407
)
408
))
409
] ++ lib.optionals enableCuda [
410
"-DCUDA_FAST_MATH=ON"
411
-
# We need to set the C and C++ host compilers for CUDA to the same compiler.
412
-
"-DCMAKE_C_COMPILER=${backendStdenv.cc}/bin/cc"
413
-
"-DCMAKE_CXX_COMPILER=${backendStdenv.cc}/bin/c++"
414
"-DCUDA_NVCC_FLAGS=--expt-relaxed-constexpr"
415
416
# OpenCV respects at least three variables:
···
421
"-DCUDA_ARCH_PTX=${lib.last cudaCapabilities}"
422
423
"-DNVIDIA_OPTICAL_FLOW_2_0_HEADERS_PATH=${nvidia-optical-flow-sdk}"
424
-
] ++ lib.optionals stdenv.isDarwin [
425
"-DWITH_OPENCL=OFF"
426
"-DWITH_LAPACK=OFF"
427
···
435
"-DBUILD_JPEG=OFF"
436
"-DBUILD_PNG=OFF"
437
"-DBUILD_WEBP=OFF"
438
-
] ++ lib.optionals (!stdenv.isDarwin) [
439
"-DOPENCL_LIBRARY=${ocl-icd}/lib/libOpenCL.so"
440
] ++ lib.optionals enablePython [
441
"-DOPENCV_SKIP_PYTHON_LOADER=ON"
···
489
tests = {
490
inherit (gst_all_1) gst-plugins-bad;
491
}
492
-
// lib.optionalAttrs (!stdenv.isDarwin) { inherit qimgv; }
493
// lib.optionalAttrs (!enablePython) { pythonEnabled = pythonPackages.opencv4; }
494
-
// lib.optionalAttrs (stdenv.buildPlatform != "x86_64-darwin") {
495
opencv4-tests = callPackage ./tests.nix {
496
inherit enableGStreamer enableGtk2 enableGtk3 runAccuracyTests runPerformanceTests testDataSrc;
497
inherit opencv4;
···
83
, Accelerate
84
, bzip2
85
, callPackage
86
+
}@inputs:
87
88
let
89
version = "4.7.0";
90
+
91
+
# It's necessary to consistently use backendStdenv when building with CUDA
92
+
# support, otherwise we get libstdc++ errors downstream
93
+
stdenv = throw "Use effectiveStdenv instead";
94
+
effectiveStdenv = if enableCuda then cudaPackages.backendStdenv else inputs.stdenv;
95
96
src = fetchFromGitHub {
97
owner = "opencv";
···
126
sha256 = "1msbkc3zixx61rcg6a04i1bcfhw1phgsrh93glq1n80hgsk3nbjq";
127
} + "/ippicv";
128
files = let name = platform: "ippicv_2019_${platform}_general_20180723.tgz"; in
129
+
if effectiveStdenv.hostPlatform.system == "x86_64-linux" then
130
{ ${name "lnx_intel64"} = "c0bd78adb4156bbf552c1dfe90599607"; }
131
+
else if effectiveStdenv.hostPlatform.system == "i686-linux" then
132
{ ${name "lnx_ia32"} = "4f38432c30bfd6423164b7a24bbc98a0"; }
133
+
else if effectiveStdenv.hostPlatform.system == "x86_64-darwin" then
134
{ ${name "mac_intel64"} = "fe6b2bb75ae0e3f19ad3ae1a31dfa4a2"; }
135
else
136
throw "ICV is not available for this platform (or not yet supported by this package)";
···
237
#https://github.com/xianyi/OpenBLAS/wiki/Faq/4bded95e8dc8aadc70ce65267d1093ca7bdefc4c#multi-threaded
238
openblas_ = blas.provider.override { singleThreaded = true; };
239
240
+
inherit (cudaPackages) cudaFlags cudaVersion;
241
inherit (cudaFlags) cudaCapabilities;
242
243
cuda-common-redist = with cudaPackages; [
244
+
cuda_cudart
245
cuda_cccl # <thrust/*>
246
libnpp # npp.h
247
] ++ lib.optionals enableCublas [
···
252
libcufft # cufft.h
253
];
254
0
0
0
0
0
0
0
0
255
cuda-redist = symlinkJoin {
256
name = "cuda-redist-${cudaVersion}";
257
paths = cuda-common-redist;
258
};
259
in
260
261
+
effectiveStdenv.mkDerivation {
262
pname = "opencv";
263
inherit version src;
264
···
317
318
buildInputs = [ zlib pcre boost gflags protobuf3_21 ]
319
++ lib.optional enablePython pythonPackages.python
320
+
++ lib.optional (effectiveStdenv.buildPlatform == effectiveStdenv.hostPlatform) hdf5
321
++ lib.optional enableGtk2 gtk2
322
++ lib.optional enableGtk3 gtk3
323
++ lib.optional enableVtk vtk
···
328
++ lib.optionals enableEXR [ openexr ilmbase ]
329
++ lib.optional enableJPEG2000 openjpeg
330
++ lib.optional enableFfmpeg ffmpeg
331
+
++ lib.optionals (enableFfmpeg && effectiveStdenv.isDarwin)
332
[ VideoDecodeAcceleration bzip2 ]
333
++ lib.optionals enableGStreamer (with gst_all_1; [ gstreamer gst-plugins-base gst-plugins-good ])
334
++ lib.optional enableOvis ogre
···
341
# tesseract & leptonica.
342
++ lib.optionals enableTesseract [ tesseract leptonica ]
343
++ lib.optional enableTbb tbb
344
+
++ lib.optionals effectiveStdenv.isDarwin [
345
bzip2 AVFoundation Cocoa VideoDecodeAcceleration CoreMedia MediaToolbox Accelerate
346
]
347
++ lib.optionals enableDocs [ doxygen graphviz-nox ]
···
355
pythonPackages.pip
356
pythonPackages.wheel
357
pythonPackages.setuptools
358
+
] ++ lib.optionals enableCuda [
359
+
cudaPackages.cuda_nvcc
360
+
];
361
362
env.NIX_CFLAGS_COMPILE = lib.optionalString enableEXR "-I${ilmbase.dev}/include/OpenEXR";
363
···
400
(opencvFlag "ENABLE_LTO" enableLto)
401
(opencvFlag "ENABLE_THIN_LTO" (
402
enableLto && (
403
+
# Only clang supports thin LTO, so we must either be using clang through the effectiveStdenv,
404
+
effectiveStdenv.cc.isClang ||
405
+
# or through the backend effectiveStdenv.
406
+
(enableCuda && effectiveStdenv.cc.isClang)
407
)
408
))
409
] ++ lib.optionals enableCuda [
410
"-DCUDA_FAST_MATH=ON"
0
0
0
411
"-DCUDA_NVCC_FLAGS=--expt-relaxed-constexpr"
412
413
# OpenCV respects at least three variables:
···
418
"-DCUDA_ARCH_PTX=${lib.last cudaCapabilities}"
419
420
"-DNVIDIA_OPTICAL_FLOW_2_0_HEADERS_PATH=${nvidia-optical-flow-sdk}"
421
+
] ++ lib.optionals effectiveStdenv.isDarwin [
422
"-DWITH_OPENCL=OFF"
423
"-DWITH_LAPACK=OFF"
424
···
432
"-DBUILD_JPEG=OFF"
433
"-DBUILD_PNG=OFF"
434
"-DBUILD_WEBP=OFF"
435
+
] ++ lib.optionals (!effectiveStdenv.isDarwin) [
436
"-DOPENCL_LIBRARY=${ocl-icd}/lib/libOpenCL.so"
437
] ++ lib.optionals enablePython [
438
"-DOPENCV_SKIP_PYTHON_LOADER=ON"
···
486
tests = {
487
inherit (gst_all_1) gst-plugins-bad;
488
}
489
+
// lib.optionalAttrs (!effectiveStdenv.isDarwin) { inherit qimgv; }
490
// lib.optionalAttrs (!enablePython) { pythonEnabled = pythonPackages.opencv4; }
491
+
// lib.optionalAttrs (effectiveStdenv.buildPlatform != "x86_64-darwin") {
492
opencv4-tests = callPackage ./tests.nix {
493
inherit enableGStreamer enableGtk2 enableGtk3 runAccuracyTests runPerformanceTests testDataSrc;
494
inherit opencv4;