From fbb5e7f7cf1e8d0956ca457c5f952b8adc2e6443 Mon Sep 17 00:00:00 2001
From: Dmitry Kalinkin <dmitry.kalinkin@gmail.com>
Date: Sat, 15 Apr 2023 22:15:44 -0400
Subject: [PATCH] Decompression support was only added in HepMC3 v3.2.5

---
 CMakeLists.txt        | 12 ++++++-----
 DDTest/CMakeLists.txt | 48 ++++++++++++++++++++++---------------------
 2 files changed, 32 insertions(+), 28 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index f3e63d09a..b81ee3544 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -155,14 +155,16 @@ if(DD4HEP_USE_EDM4HEP)
 #  DD4HEP_SETUP_EDM4HEP_TARGETS()
 endif()
 
-IF(DD4HEP_USE_HEPMC3)
+if(DD4HEP_USE_HEPMC3)
   find_package(HepMC3 REQUIRED)
 
   # Optional dependencies for compressed input support
-  find_package(ZLIB)
-  find_package(LibLZMA)
-  find_package(BZip2)
-ENDIF()
+  if(${HEPMC3_VERSION} VERSION_GREATER_EQUAL "3.02.05")
+    find_package(ZLIB)
+    find_package(LibLZMA)
+    find_package(BZip2)
+  endif()
+endif()
 
 if(DD4HEP_USE_TBB)
   find_package(TBB REQUIRED CONFIG)
diff --git a/DDTest/CMakeLists.txt b/DDTest/CMakeLists.txt
index d3c331f8d..f0cd41e0f 100644
--- a/DDTest/CMakeLists.txt
+++ b/DDTest/CMakeLists.txt
@@ -60,29 +60,31 @@ if (DD4HEP_USE_GEANT4)
   if(DD4HEP_USE_HEPMC3)
     set(TEST_HEPMC3_EXTENSIONS)
 
-    if(ZLIB_FOUND)
-      file(ARCHIVE_CREATE
-        OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/Pythia_output.hepmc.gz
-        PATHS ${CMAKE_CURRENT_SOURCE_DIR}/inputFiles/Pythia_output.hepmc
-        FORMAT raw
-        COMPRESSION GZip)
-      list(APPEND TEST_HEPMC3_EXTENSIONS .gz)
-    endif()
-    if(LIBLZMA_FOUND)
-      file(ARCHIVE_CREATE
-        OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/Pythia_output.hepmc.xz
-        PATHS ${CMAKE_CURRENT_SOURCE_DIR}/inputFiles/Pythia_output.hepmc
-        FORMAT raw
-        COMPRESSION XZ)
-      list(APPEND TEST_HEPMC3_EXTENSIONS .xz)
-    endif()
-    if(BZIP2_FOUND)
-      file(ARCHIVE_CREATE
-        OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/Pythia_output.hepmc.bz2
-        PATHS ${CMAKE_CURRENT_SOURCE_DIR}/inputFiles/Pythia_output.hepmc
-        FORMAT raw
-        COMPRESSION BZip2)
-      list(APPEND TEST_HEPMC3_EXTENSIONS .bz2)
+    if(${HEPMC3_VERSION} VERSION_GREATER_EQUAL "3.02.05")
+      if(ZLIB_FOUND)
+        file(ARCHIVE_CREATE
+          OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/Pythia_output.hepmc.gz
+          PATHS ${CMAKE_CURRENT_SOURCE_DIR}/inputFiles/Pythia_output.hepmc
+          FORMAT raw
+          COMPRESSION GZip)
+        list(APPEND TEST_HEPMC3_EXTENSIONS .gz)
+      endif()
+      if(LIBLZMA_FOUND)
+        file(ARCHIVE_CREATE
+          OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/Pythia_output.hepmc.xz
+          PATHS ${CMAKE_CURRENT_SOURCE_DIR}/inputFiles/Pythia_output.hepmc
+          FORMAT raw
+          COMPRESSION XZ)
+        list(APPEND TEST_HEPMC3_EXTENSIONS .xz)
+      endif()
+      if(BZIP2_FOUND)
+        file(ARCHIVE_CREATE
+          OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/Pythia_output.hepmc.bz2
+          PATHS ${CMAKE_CURRENT_SOURCE_DIR}/inputFiles/Pythia_output.hepmc
+          FORMAT raw
+          COMPRESSION BZip2)
+        list(APPEND TEST_HEPMC3_EXTENSIONS .bz2)
+      endif()
     endif()
 
     foreach(TEST_HEPMC3_EXTENSION "" ${TEST_HEPMC3_EXTENSIONS})
-- 
GitLab