From 94afbe93f5660c61d3ac8490db2bcb87ba6c3798 Mon Sep 17 00:00:00 2001
From: Guilherme Amadio <amadio@cern.ch>
Date: Tue, 18 Jun 2019 07:59:28 +0200
Subject: [PATCH] Fail to configure if fail-on-missing=ON and zlib is not found

---
 cmake/modules/SearchInstalledSoftware.cmake | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/cmake/modules/SearchInstalledSoftware.cmake b/cmake/modules/SearchInstalledSoftware.cmake
index fdb25109093..80a82041d15 100644
--- a/cmake/modules/SearchInstalledSoftware.cmake
+++ b/cmake/modules/SearchInstalledSoftware.cmake
@@ -42,10 +42,14 @@ if(NOT builtin_zlib)
   foreach(suffix FOUND INCLUDE_DIR LIBRARY LIBRARY_DEBUG LIBRARY_RELEASE)
     unset(ZLIB_${suffix} CACHE)
   endforeach()
-  find_package(ZLIB)
-  if(NOT ZLIB_FOUND)
-    message(STATUS "Zlib not found. Switching on builtin_zlib option")
-    set(builtin_zlib ON CACHE BOOL "Enabled because Zlib not found (${builtin_zlib_description})" FORCE)
+  if(fail-on-missing)
+    find_package(ZLIB REQUIRED)
+  else()
+    find_package(ZLIB)
+    if(NOT ZLIB_FOUND)
+      message(STATUS "Zlib not found. Switching on builtin_zlib option")
+      set(builtin_zlib ON CACHE BOOL "Enabled because Zlib not found (${builtin_zlib_description})" FORCE)
+    endif()
   endif()
 endif()
 
-- 
GitLab