1{
2 lib,
3 stdenv,
4 fetchFromGitHub,
5 cmake,
6 enableVTK ? true,
7 vtk,
8 DarwinTools, # sw_vers
9 enablePython ? false,
10 python ? null,
11 swig,
12 expat,
13 libuuid,
14 openjpeg,
15 zlib,
16 pkg-config,
17}:
18
19stdenv.mkDerivation rec {
20 pname = if enablePython then "python-gdcm" else "gdcm";
21 version = "3.0.24";
22
23 src = fetchFromGitHub {
24 owner = "malaterre";
25 repo = "GDCM";
26 tag = "v${version}";
27 hash = "sha256-Zlb6UCP4aFZOJJNhFQBBrwzst+f37gs1zaCBMTOUgZE=";
28 };
29
30 cmakeFlags =
31 [
32 "-DGDCM_BUILD_APPLICATIONS=ON"
33 "-DGDCM_BUILD_SHARED_LIBS=ON"
34 "-DGDCM_BUILD_TESTING=ON"
35 "-DGDCM_USE_SYSTEM_EXPAT=ON"
36 "-DGDCM_USE_SYSTEM_ZLIB=ON"
37 "-DGDCM_USE_SYSTEM_UUID=ON"
38 "-DGDCM_USE_SYSTEM_OPENJPEG=ON"
39 # hack around usual "`RUNTIME_DESTINATION` must not be an absolute path" issue:
40 "-DCMAKE_INSTALL_LIBDIR=lib"
41 "-DCMAKE_INSTALL_BINDIR=bin"
42 "-DCMAKE_INSTALL_INCLUDEDIR=include"
43 ]
44 ++ lib.optionals enableVTK [
45 "-DGDCM_USE_VTK=ON"
46 ]
47 ++ lib.optionals enablePython [
48 "-DGDCM_WRAP_PYTHON:BOOL=ON"
49 "-DGDCM_INSTALL_PYTHONMODULE_DIR=${placeholder "out"}/${python.sitePackages}/python_gdcm"
50 ];
51
52 nativeBuildInputs = [
53 cmake
54 pkg-config
55 ] ++ lib.optional stdenv.hostPlatform.isDarwin DarwinTools;
56
57 buildInputs =
58 [
59 expat
60 libuuid
61 openjpeg
62 zlib
63 ]
64 ++ lib.optionals enableVTK [
65 vtk
66 ]
67 ++ lib.optionals enablePython [
68 swig
69 python
70 ];
71
72 postInstall = lib.optionalString enablePython ''
73 substitute \
74 ${./python_gdcm.egg-info} \
75 $out/${python.sitePackages}/python_gdcm-${version}.egg-info \
76 --subst-var-by GDCM_VER "${version}"
77 '';
78
79 disabledTests =
80 [
81 # require networking:
82 "TestEcho"
83 "TestFind"
84 "gdcmscu-echo-dicomserver"
85 "gdcmscu-find-dicomserver"
86 # seemingly ought to be disabled when the test data submodule is not present:
87 "TestvtkGDCMImageReader2_3"
88 "TestSCUValidation"
89 # errors because 3 classes not wrapped:
90 "TestWrapPython"
91 # AttributeError: module 'gdcm' has no attribute 'UIDGenerator_SetRoot'; maybe a wrapping regression:
92 "TestUIDGeneratorPython"
93 ]
94 ++ lib.optionals (stdenv.hostPlatform.isAarch64 && stdenv.hostPlatform.isLinux) [
95 "TestRescaler2"
96 ];
97
98 checkPhase = ''
99 runHook preCheck
100 ctest --exclude-regex '^(${lib.concatStringsSep "|" disabledTests})$'
101 runHook postCheck
102 '';
103 doCheck = true;
104 # note that when the test data is available to the build via `fetchSubmodules = true`,
105 # a number of additional but much slower tests are enabled
106
107 meta = with lib; {
108 description = "Grassroots cross-platform DICOM implementation";
109 longDescription = ''
110 Grassroots DICOM (GDCM) is an implementation of the DICOM standard designed to be open source so that researchers may access clinical data directly.
111 GDCM includes a file format definition and a network communications protocol, both of which should be extended to provide a full set of tools for a researcher or small medical imaging vendor to interface with an existing medical database.
112 '';
113 homepage = "https://gdcm.sourceforge.net/";
114 license = with licenses; [
115 bsd3
116 asl20
117 ];
118 maintainers = with maintainers; [ tfmoraes ];
119 platforms = platforms.all;
120 };
121}