Subject: Re: bug#60640: Gnu: Add gdcm

From: Tor-björn Claesson <[email-masked]>
Date: Sat, 14 Jan 2023 23:58:43 +0200

And here is the last patch, which uses system packages where possible.
All  nice things in these patches are thanks to the help of Tobias,
any screwups are mine.

Thanks!
Tor-björn
>From 77a7609eb727c53028846d0bf54204cdf9f58f9c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tor-bj=C3=B6rn=20Claesson?= <[email-masked]>
Date: Sat, 14 Jan 2023 23:56:43 +0200
Subject: [PATCH] gnu: gdcm: Use system packages where possible.

---
 gnu/packages/bioinformatics.scm | 47 +++++++++++++++++++++++++++++++--
 1 file changed, 45 insertions(+), 2 deletions(-)

diff --git a/gnu/packages/bioinformatics.scm b/gnu/packages/bioinformatics.scm
index e45d33ec2b..41709fd9ed 100644
--- a/gnu/packages/bioinformatics.scm
+++ b/gnu/packages/bioinformatics.scm
@@ -17853,7 +17853,29 @@ (define-public gdcm
               (file-name (git-file-name name version))
               (sha256
                (base32
-                "1w78cmm9q7aavs7svdkl4dgilcqk4yazci9m6x7icrssb7cj991i"))))
+                "1w78cmm9q7aavs7svdkl4dgilcqk4yazci9m6x7icrssb7cj991i"))
+              (modules '((guix build utils)
+                         (ice-9 ftw)))
+              (snippet
+               '(begin
+                  (define (unbundle? file)
+                    (member file '("dicom3tools"
+                                   "gdcmexpat"
+                                   "gdcmutfcpp"
+                                   "gdcmuuid"
+                                   "gdcmzlib"
+                                   "getopt"
+                                   "KWStyle"
+                                   "pvrg"
+                                   "Release"
+                                   "Release"
+                                   "VTK")))
+                  (with-directory-excursion "Utilities"
+                    (for-each (lambda (utility)
+                                (delete-file-recursively utility)
+                                (substitute* "CMakeLists.txt"
+                                  (((string-append ".*/" utility "/.*")) "")))
+                              (scandir "." unbundle?)))))))
     (build-system cmake-build-system)
     (outputs '("out" "bin" "doc"))
     (arguments
@@ -17882,6 +17904,20 @@ (define-public gdcm
                              "|gdcmscu-find-dicomserver"
                              "|TestEcho"
                              "|TestFind'")
+              ;; Libraries
+              "-DGDCM_USE_SYSTEM_EXPAT:BOOL=ON"
+              "-DGDCM_USE_SYSTEM_JSON:BOOL=ON"
+              "-DGDCM_USE_SYSTEM_LIBXML2:BOOL=ON"
+              "-DGDCM_USE_SYSTEM_OPENSSL:BOOL=ON"
+              "-DGDCM_USE_SYSTEM_POPPLER:BOOL=ON"
+              "-DGDCM_USE_SYSTEM_UUID:BOOL=ON"
+              "-DGDCM_USE_SYSTEM_ZLIB:BOOL=ON"
+              ;; TODO: Unbundle these if possible.
+              "-DGDCM_USE_SYSTEM_CHARLS:BOOL=OFF"
+              "-DGDCM_USE_SYSTEM_LJPEG:BOOL=OFF"
+              "-DGDCM_USE_SYSTEM_OPENJPEG:BOOL=OFF"
+              "-DGDCM_USE_SYSTEM_PAPYRUS3:BOOL=OFF"
+              "-DGDCM_USE_SYSTEM_SOCKETXX:BOOL=OFF"
               ;; Documentation
               "-DGDCM_DOCUMENTATION:BOOL=ON"
               "-DGDCM_PDF_DOCUMENTATION:BOOL=ON"
@@ -17890,7 +17926,14 @@ (define-public gdcm
               "-DGDCM_BUILD_DOCBOOK_MANPAGES:BOOL=OFF" ;; TODO: need ‘xsl-ns’
               ;; Utilities
               "-DGDCM_BUILD_APPLICATIONS:BOOL=ON")))
-    (native-inputs (list doxygen ghostscript graphviz texlive))
+    (inputs (list expat
+                  json-c
+                  libxml2
+                  openssl
+                  poppler
+                  `(,util-linux "lib")
+                  zlib))
+    (native-inputs (list doxygen ghostscript graphviz pkg-config texlive))
     (home-page "https://gdcm.sourceforge.net/wiki/index.php/Main_Page")
     (synopsis "Grassroots DICOM library")
     (description
-- 
2.38.1