File fix_zlib_linking.patch of Package libsc

From fad3a1ad9489ac482eb95b32fb48e48d94262cd0 Mon Sep 17 00:00:00 2001
From: Pierre Kestener <pierre.kestener@cea.fr>
Date: Thu, 20 Apr 2023 16:00:54 +0200
Subject: [PATCH] Cmake update to allow to chose if zlib is built or detected.

---
 cmake/config.cmake  | 14 ++++++++++++++
 cmake/options.cmake |  3 ++-
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/cmake/config.cmake b/cmake/config.cmake
index d576f6d84..718d9f78b 100644
--- a/cmake/config.cmake
+++ b/cmake/config.cmake
@@ -9,12 +9,26 @@ include(CheckCSourceCompiles)
 if(mpi)
   find_package(MPI COMPONENTS C REQUIRED)
 endif()
+
 if(openmp)
   find_package(OpenMP COMPONENTS C REQUIRED)
 endif()
+
 if(zlib)
+  message(STATUS "Using builtin zlib")
   include(${CMAKE_CURRENT_LIST_DIR}/zlib.cmake)
+  set(SC_HAVE_ZLIB true)
+else()
+  find_package(ZLIB)
+  if(ZLIB_FOUND)
+    message(STATUS "Using system zlib : ${ZLIB_VERSION_STRING}")
+    set(SC_HAVE_ZLIB true)
+  else()
+    message(STATUS "Zlib disabled (not found). Consider using cmake \"-Dzlib=ON\" to turn on builtin zlib.")
+    set(SC_HAVE_ZLIB false)
+  endif()
 endif()
+
 find_package(Threads)
 
 # --- set global compile environment
diff --git a/cmake/options.cmake b/cmake/options.cmake
index b4b9537fd..9be8620d9 100644
--- a/cmake/options.cmake
+++ b/cmake/options.cmake
@@ -1,8 +1,9 @@
+
 include(GNUInstallDirs)
 
 option(mpi "use MPI library" off)
 option(openmp "use OpenMP" off)
-option(zlib "use ZLIB" on)
+option(zlib "build ZLIB" on)
 option(BUILD_TESTING "build libsc self-tests" on)
 option(BUILD_SHARED_LIBS "build shared libsc")
 
openSUSE Build Service is sponsored by