forked from apache/orc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFindZLIB.cmake
97 lines (83 loc) · 2.92 KB
/
FindZLIB.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# ZLIB_HOME environmental variable is used to check for ZLIB headers and static library
# ZLIB_INCLUDE_DIR: directory containing headers
# ZLIB_LIBRARY: path to libz/libzlib
# ZLIB_STATIC_LIB: path to zlib.a
# ZLIB_FOUND: whether ZLIB has been found
if (NOT ZLIB_HOME)
if (DEFINED ENV{ZLIB_HOME})
set (ZLIB_HOME "$ENV{ZLIB_HOME}")
elseif (ZLIB_ROOT)
set (ZLIB_HOME "${ZLIB_ROOT}")
elseif (DEFINED ENV{ZLIB_ROOT})
set (ZLIB_HOME "$ENV{ZLIB_ROOT}")
endif ()
endif ()
if( NOT "${ZLIB_HOME}" STREQUAL "")
file (TO_CMAKE_PATH "${ZLIB_HOME}" _zlib_path)
endif()
message (STATUS "ZLIB_HOME: ${ZLIB_HOME}")
find_path (ZLIB_INCLUDE_DIR zlib.h HINTS
${_zlib_path}
NO_DEFAULT_PATH
PATH_SUFFIXES "include")
if (NOT ZLIB_STATIC_LIB_NAME)
set (ZLIB_STATIC_LIB_NAME z)
endif()
find_library (ZLIB_LIBRARY NAMES z zlib ${ZLIB_STATIC_LIB_NAME} HINTS
${_zlib_path}
PATH_SUFFIXES "lib")
find_library (ZLIB_STATIC_LIB NAMES ${CMAKE_STATIC_LIBRARY_PREFIX}${ZLIB_STATIC_LIB_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX} HINTS
${_zlib_path}
PATH_SUFFIXES "lib")
if (ZLIB_INCLUDE_DIR AND ZLIB_LIBRARY)
set (ZLIB_FOUND TRUE)
set (ZLIB_HEADER_NAME zlib.h)
set (ZLIB_HEADER ${ZLIB_INCLUDE_DIR}/${ZLIB_HEADER_NAME})
else ()
set (ZLIB_FOUND FALSE)
endif ()
if (ZLIB_FOUND)
message (STATUS "Found the ZLIB header: ${ZLIB_HEADER}")
message (STATUS "Found the ZLIB library: ${ZLIB_LIBRARY}")
if (ZLIB_STATIC_LIB)
message (STATUS "Found the ZLIB static library: ${ZLIB_STATIC_LIB}")
endif ()
else()
if (_zlib_path)
set (ZLIB_ERR_MSG "Could not find ZLIB. Looked in ${_zlib_path}.")
else ()
set (ZLIB_ERR_MSG "Could not find ZLIB in system search paths.")
endif()
if (ZLIB_FIND_REQUIRED)
message (FATAL_ERROR "${ZLIB_ERR_MSG}")
else ()
message (STATUS "${ZLIB_ERR_MSG}")
endif ()
endif()
mark_as_advanced (
ZLIB_INCLUDE_DIR
ZLIB_STATIC_LIB
ZLIB_LIBRARY
)
if(ZLIB_FOUND AND NOT TARGET ZLIB::ZLIB)
add_library(ZLIB::ZLIB UNKNOWN IMPORTED)
set_target_properties(ZLIB::ZLIB
PROPERTIES IMPORTED_LOCATION "${ZLIB_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${ZLIB_INCLUDE_DIR}")
endif()