1# Copyright (c) 2009, 2018, Oracle and/or its affiliates. All rights reserved.
2#
3# This program is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation; version 2 of the License.
6#
7# This program is distributed in the hope that it will be useful,
8# but WITHOUT ANY WARRANTY; without even the implied warranty of
9# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10# GNU General Public License for more details.
11#
12# You should have received a copy of the GNU General Public License
13# along with this program; if not, write to the Free Software
14# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1335  USA
15
16MACRO (MYSQL_USE_BUNDLED_ZLIB)
17  SET(ZLIB_INCLUDE_DIR  ${CMAKE_SOURCE_DIR}/zlib ${CMAKE_BINARY_DIR}/zlib)
18  SET(BUILD_BUNDLED_ZLIB 1)
19  SET(ZLIB_LIBRARY zlib CACHE INTERNAL "Bundled zlib library")
20  SET(ZLIB_FOUND  TRUE)
21  SET(WITH_ZLIB "bundled" CACHE STRING "Use bundled zlib")
22  ADD_SUBDIRECTORY(zlib)
23ENDMACRO()
24
25# MYSQL_CHECK_ZLIB_WITH_COMPRESS
26#
27# Provides the following configure options:
28# WITH_ZLIB_BUNDLED
29# If this is set,we use bindled zlib
30# If this is not set,search for system zlib.
31# if system zlib is not found, use bundled copy
32# ZLIB_LIBRARIES, ZLIB_INCLUDE_DIR and ZLIB_SOURCES
33# are set after this macro has run
34
35MACRO (MYSQL_CHECK_ZLIB_WITH_COMPRESS)
36
37  IF(WITH_ZLIB STREQUAL "bundled")
38    MYSQL_USE_BUNDLED_ZLIB()
39  ELSE()
40    INCLUDE(FindZLIB)
41    IF(ZLIB_FOUND)
42     INCLUDE(CheckFunctionExists)
43      SET(CMAKE_REQUIRED_LIBRARIES z)
44      CHECK_FUNCTION_EXISTS(crc32 HAVE_CRC32)
45      CHECK_FUNCTION_EXISTS(compressBound HAVE_COMPRESSBOUND)
46      CHECK_FUNCTION_EXISTS(deflateBound HAVE_DEFLATEBOUND)
47      SET(CMAKE_REQUIRED_LIBRARIES)
48      IF(HAVE_CRC32 AND HAVE_COMPRESSBOUND AND HAVE_DEFLATEBOUND)
49        SET(WITH_ZLIB "system" CACHE STRING
50          "Which zlib to use (possible values are 'bundled' or 'system')")
51        SET(ZLIB_SOURCES "")
52      ELSE()
53        SET(ZLIB_FOUND FALSE CACHE INTERNAL "Zlib found but not usable")
54        MESSAGE(STATUS "system zlib found but not usable")
55      ENDIF()
56    ENDIF()
57    IF(NOT ZLIB_FOUND)
58      MYSQL_USE_BUNDLED_ZLIB()
59    ENDIF()
60  ENDIF()
61  SET(HAVE_COMPRESS 1)
62ENDMACRO()
63