Skip to content

Commit 0635bce

Browse files
committed
- make the symbol check optional
1 parent 346e23d commit 0635bce

1 file changed

Lines changed: 29 additions & 8 deletions

File tree

CMakeModules/FindZLIB.cmake

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (C) 2022 by Pedro Mendes, Rector and Visitors of the
1+
# Copyright (C) 2022 - 2025 by Pedro Mendes, Rector and Visitors of the
22
# University of Virginia, University of Heidelberg, and University
33
# of Connecticut School of Medicine.
44
# All rights reserved.
@@ -31,38 +31,43 @@ if (NOT (ZLIB_INCLUDE_DIR AND ZLIB_LIBRARY) OR NOT ZLIB_FOUND)
3131
find_path(ZLIB_INCLUDE_DIR zlib.h zlib/zlib.h
3232
PATHS $ENV{ZLIB_DIR}/include
3333
$ENV{ZLIB_DIR}
34-
${${_PROJECT_DEPENDENCY_DIR}}/include
34+
${${_PROJECT_DEPENDENCY_DIR}}/include
3535
~/Library/Frameworks
3636
/Library/Frameworks
3737
/sw/include # Fink
3838
/opt/local/include # MacPorts
3939
/opt/csw/include # Blastwave
4040
/opt/include
4141
/usr/freeware/include
42-
NO_DEFAULT_PATH)
42+
CMAKE_FIND_ROOT_PATH_BOTH
43+
NO_DEFAULT_PATH)
4344

4445
if (NOT ZLIB_INCLUDE_DIR)
45-
find_path(ZLIB_INCLUDE_DIR zlib.h zlib/zlib.h)
46+
find_path(ZLIB_INCLUDE_DIR zlib.h zlib/zlib.h
47+
CMAKE_FIND_ROOT_PATH_BOTH )
4648
endif ()
4749

4850
find_library(ZLIB_LIBRARY
49-
NAMES zdll.lib z zlib.lib libzlib zlib libzlib.a
51+
NAMES zdll.lib z zlib.lib libzlib zlib libzlib.a libzdll.a
5052
PATHS $ENV{ZLIB_DIR}/lib
5153
$ENV{ZLIB_DIR}/lib-dbg
5254
$ENV{ZLIB_DIR}
53-
${${_PROJECT_DEPENDENCY_DIR}}/${CMAKE_INSTALL_LIBDIR}
54-
${${_PROJECT_DEPENDENCY_DIR}}
55+
${${_PROJECT_DEPENDENCY_DIR}}/${CMAKE_INSTALL_LIBDIR}
56+
${${_PROJECT_DEPENDENCY_DIR}}/lib
57+
${${_PROJECT_DEPENDENCY_DIR}}
5558
~/Library/Frameworks
5659
/Library/Frameworks
5760
/sw/lib # Fink
5861
/opt/local/lib # MacPorts
5962
/opt/csw/lib # Blastwave
6063
/opt/lib
6164
/usr/freeware/lib64
65+
CMAKE_FIND_ROOT_PATH_BOTH
6266
NO_DEFAULT_PATH)
6367

6468
if (NOT ZLIB_LIBRARY)
65-
find_library(ZLIB_LIBRARY NAMES zdll.lib z zlib.lib libzlib zlib libzlib.a)
69+
find_library(ZLIB_LIBRARY NAMES zdll.lib z zlib.lib libzlib zlib libzlib.a libzdll.a
70+
CMAKE_FIND_ROOT_PATH_BOTH )
6671
endif ()
6772

6873
if (NOT WIN32)
@@ -77,6 +82,22 @@ if (NOT (ZLIB_INCLUDE_DIR AND ZLIB_LIBRARY) OR NOT ZLIB_FOUND)
7782
endif (PC_ZLIB_FOUND)
7883
endif (NOT WIN32)
7984

85+
86+
# make sure that we have a valid zip library
87+
if (ZLIB_CHECK_FOR_SYMBOLS)
88+
file(TO_CMAKE_PATH "${ZLIB_LIBRARY}" LIBZ_CMAKE_PATH)
89+
include(CheckLibraryExists)
90+
check_library_exists("${LIBZ_CMAKE_PATH}" "gzopen" "" LIBZ_FOUND_SYMBOL)
91+
92+
if(NOT LIBZ_FOUND_SYMBOL AND UNIX)
93+
message(WARNING
94+
"The chosen zlib library does not appear to be valid because it is
95+
missing certain required symbols. Please check that ${ZLIB_LIBRARY} is
96+
the correct zlib library. For details about the error, please see
97+
CMakeError.log or CMakeConfigureLog.yaml in the build directory.")
98+
endif()
99+
endif() # Check for symbols
100+
80101
mark_as_advanced(ZLIB_INCLUDE_DIR ZLIB_LIBRARY)
81102

82103
endif () # Check for cached values

0 commit comments

Comments
 (0)