From 4a2d2666a700740b314a71e0586a479f4b6cbc67 Mon Sep 17 00:00:00 2001 From: Frank Bergmann Date: Fri, 9 Aug 2024 13:35:09 +0200 Subject: [PATCH] Detect ZLIB using find module --- CMakeLists.txt | 71 +++++++------------------------------------------- 1 file changed, 10 insertions(+), 61 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b2e97c6f4..8e1aeba36 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -534,68 +534,25 @@ Separate multiple directories using semicolons." ) # # Locate zlib # - -set(ZLIB_INITIAL_VALUE) -if (NOT LIBZ_LIBRARY) -find_library(LIBZ_LIBRARY - NAMES zdll.lib z zlib.lib - PATHS /usr/lib /usr/local/lib - ${CMAKE_OSX_SYSROOT}/usr/lib - ${LIBSBML_DEPENDENCY_DIR}/lib - NO_DEFAULT_PATH - NO_CMAKE_ENVIRONMENT_PATH - NO_CMAKE_PATH - NO_SYSTEM_ENVIRONMENT_PATH - NO_CMAKE_SYSTEM_PATH - DOC "The file name of the zip compression library." - ) -endif() -if (NOT LIBZ_LIBRARY) -find_library(LIBZ_LIBRARY - NAMES zdll.lib z zlib.lib - PATHS /usr/lib /usr/local/lib - ${CMAKE_OSX_SYSROOT}/usr/lib - ${LIBSBML_DEPENDENCY_DIR}/lib - DOC "The file name of the zip compression library." - ) +find_package(ZLIB QUIET) +set(ZLIB_INITIAL_VALUE ON) +if(NOT TARGET ZLIB::ZLIB) +set(ZLIB_INITIAL_VALUE OFF) endif() -if(EXISTS ${LIBZ_LIBRARY}) - set(ZLIB_INITIAL_VALUE ON) -else() - set(ZLIB_INITIAL_VALUE OFF) -endif() option(WITH_ZLIB "Enable the use of zip compression." ${ZLIB_INITIAL_VALUE} ) set(USE_ZLIB OFF) if(WITH_ZLIB) - if (NOT LIBZ_INCLUDE_DIR) - find_path(LIBZ_INCLUDE_DIR - NAMES zlib.h zlib/zlib.h - PATHS ${CMAKE_OSX_SYSROOT}/usr/include - /usr/include /usr/local/include - ${LIBSBML_DEPENDENCY_DIR}/include - NO_DEFAULT_PATH - DOC "The directory containing the zlib include files." - ) - endif() - if (NOT LIBZ_INCLUDE_DIR) - find_path(LIBZ_INCLUDE_DIR - NAMES zlib.h zlib/zlib.h - PATHS ${CMAKE_OSX_SYSROOT}/usr/include - /usr/include /usr/local/include - ${LIBSBML_DEPENDENCY_DIR}/include - DOC "The directory containing the zlib include files." - ) - endif() - set(USE_ZLIB ON) - add_definitions( -DUSE_ZLIB ) + find_package(ZLIB REQUIRED) + set(USE_ZLIB ON) + add_definitions( -DUSE_ZLIB ) list(APPEND SWIG_EXTRA_ARGS -DUSE_ZLIB) # make sure that we have a valid zip library - file(TO_CMAKE_PATH "${LIBZ_LIBRARY}" LIBZ_CMAKE_PATH) - check_library_exists("${LIBZ_CMAKE_PATH}" "gzopen" "" LIBZ_FOUND_SYMBOL) + file(TO_CMAKE_PATH "${ZLIB_LIBRARY}" LIBZ_CMAKE_PATH) + check_library_exists("${LIBZ_CMAKE_PATH}" "gzopen" "" LIBZ_CMAKE_PATH) if(NOT LIBZ_FOUND_SYMBOL) # this is odd, but on windows this check always fails! must be a # bug in the current cmake version so for now only issue this @@ -609,20 +566,12 @@ ${LIBSBML_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log") endif() endif() - if(NOT EXISTS "${LIBZ_INCLUDE_DIR}/zlib.h") + if(NOT EXISTS "${ZLIB_INCLUDE_DIR}/zlib.h") message(FATAL_ERROR "The include directory specified for zlib does not appear to be valid. It should contain the file zlib.h, but it does not.") endif() - if(NOT TARGET ZLIB::ZLIB) - add_library(ZLIB::ZLIB UNKNOWN IMPORTED) - set_target_properties(ZLIB::ZLIB PROPERTIES - IMPORTED_LINK_INTERFACE_LANGUAGES "C" - IMPORTED_LOCATION "${LIBZ_LIBRARY}" - INTERFACE_INCLUDE_DIRECTORIES "${LIBZ_INCLUDE_DIR}") - endif() - list(APPEND LIBSBML_FIND_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/FindZLIB.cmake") endif(WITH_ZLIB)