1#
2# Copyright by The HDF Group.
3# All rights reserved.
4#
5# This file is part of HDF5.  The full HDF5 copyright notice, including
6# terms governing use, modification, and redistribution, is contained in
7# the COPYING file, which can be found at the root of the source code
8# distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases.
9# If you do not have access to either file, you may request a copy from
10# help@hdfgroup.org.
11#
12
13# - Find SZIP library
14# - Derived from the FindTiff.cmake that is included with cmake
15# Find the native SZIP includes and library
16# This module defines
17#  SZIP_INCLUDE_DIRS, where to find tiff.h, etc.
18#  SZIP_LIBRARIES, libraries to link against to use SZIP.
19#  SZIP_FOUND, If false, do not try to use SZIP.
20#    also defined, but not for general use are
21#  SZIP_LIBRARY, where to find the SZIP library.
22#  SZIP_LIBRARY_DEBUG - Debug version of SZIP library
23#  SZIP_LIBRARY_RELEASE - Release Version of SZIP library
24
25# message (STATUS "Finding SZIP library and headers..." )
26
27############################################
28#
29# Check the existence of the libraries.
30#
31############################################
32# This macro was taken directly from the FindQt4.cmake file that is included
33# with the CMake distribution. This is NOT my work. All work was done by the
34# original authors of the FindQt4.cmake file. Only minor modifications were
35# made to remove references to Qt and make this file more generally applicable
36#########################################################################
37
38macro (SZIP_ADJUST_LIB_VARS basename)
39  if (${basename}_INCLUDE_DIR)
40
41    # if only the release version was found, set the debug variable also to the release version
42    if (${basename}_LIBRARY_RELEASE AND NOT ${basename}_LIBRARY_DEBUG)
43      set (${basename}_LIBRARY_DEBUG ${${basename}_LIBRARY_RELEASE})
44      set (${basename}_LIBRARY       ${${basename}_LIBRARY_RELEASE})
45      set (${basename}_LIBRARIES     ${${basename}_LIBRARY_RELEASE})
46    endif ()
47
48    # if only the debug version was found, set the release variable also to the debug version
49    if (${basename}_LIBRARY_DEBUG AND NOT ${basename}_LIBRARY_RELEASE)
50      set (${basename}_LIBRARY_RELEASE ${${basename}_LIBRARY_DEBUG})
51      set (${basename}_LIBRARY         ${${basename}_LIBRARY_DEBUG})
52      set (${basename}_LIBRARIES       ${${basename}_LIBRARY_DEBUG})
53    endif ()
54    if (${basename}_LIBRARY_DEBUG AND ${basename}_LIBRARY_RELEASE)
55      # if the generator supports configuration types then set
56      # optimized and debug libraries, or if the CMAKE_BUILD_TYPE has a value
57      if (CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE)
58        set (${basename}_LIBRARY       optimized ${${basename}_LIBRARY_RELEASE} debug ${${basename}_LIBRARY_DEBUG})
59      else ()
60        # if there are no configuration types and CMAKE_BUILD_TYPE has no value
61        # then just use the release libraries
62        set (${basename}_LIBRARY       ${${basename}_LIBRARY_RELEASE} )
63      endif ()
64      set (${basename}_LIBRARIES       optimized ${${basename}_LIBRARY_RELEASE} debug ${${basename}_LIBRARY_DEBUG})
65    endif ()
66
67    set (${basename}_LIBRARY ${${basename}_LIBRARY} CACHE FILEPATH "The ${basename} library")
68
69    if (${basename}_LIBRARY)
70      set (${basename}_FOUND 1)
71    endif ()
72  endif ()
73
74  # Make variables changeble to the advanced user
75  MARK_AS_ADVANCED (${basename}_LIBRARY ${basename}_LIBRARY_RELEASE ${basename}_LIBRARY_DEBUG ${basename}_INCLUDE_DIR )
76endmacro ()
77
78
79# Look for the header file.
80set (SZIP_INCLUDE_SEARCH_DIRS
81    $ENV{SZIP_INSTALL}/include
82    $ENV{SZIP_INSTALL}/include/szip
83    /usr/include
84    /usr/include/szip
85)
86
87set (SZIP_LIB_SEARCH_DIRS
88    $ENV{SZIP_INSTALL}/lib
89    /usr/lib
90)
91
92set (SZIP_BIN_SEARCH_DIRS
93    $ENV{SZIP_INSTALL}/bin
94    /usr/bin
95)
96
97FIND_PATH (SZIP_INCLUDE_DIR
98    NAMES szlib.h
99    PATHS ${SZIP_INCLUDE_SEARCH_DIRS}
100    NO_DEFAULT_PATH
101)
102
103if (WIN32)
104    set (SZIP_SEARCH_DEBUG_NAMES "sz_d;libsz_d")
105    set (SZIP_SEARCH_RELEASE_NAMES "sz;libsz;libszip")
106else ()
107    set (SZIP_SEARCH_DEBUG_NAMES "sz_d")
108    set (SZIP_SEARCH_RELEASE_NAMES "sz;szip")
109endif ()
110
111# Look for the library.
112FIND_LIBRARY (SZIP_LIBRARY_DEBUG
113    NAMES ${SZIP_SEARCH_DEBUG_NAMES}
114    PATHS ${SZIP_LIB_SEARCH_DIRS}
115    NO_DEFAULT_PATH
116)
117
118FIND_LIBRARY (SZIP_LIBRARY_RELEASE
119    NAMES ${SZIP_SEARCH_RELEASE_NAMES}
120    PATHS ${SZIP_LIB_SEARCH_DIRS}
121    NO_DEFAULT_PATH
122)
123
124SZIP_ADJUST_LIB_VARS (SZIP)
125
126if (SZIP_INCLUDE_DIR AND SZIP_LIBRARY)
127  set (SZIP_FOUND 1)
128  set (SZIP_LIBRARIES ${SZIP_LIBRARY})
129  set (SZIP_INCLUDE_DIRS ${SZIP_INCLUDE_DIR})
130  if (SZIP_LIBRARY_DEBUG)
131    get_filename_component (SZIP_LIBRARY_PATH ${SZIP_LIBRARY_DEBUG} PATH)
132    set (SZIP_LIB_DIR  ${SZIP_LIBRARY_PATH})
133  elseif ()
134    get_filename_component (SZIP_LIBRARY_PATH ${SZIP_LIBRARY_RELEASE} PATH)
135    set (SZIP_LIB_DIR  ${SZIP_LIBRARY_PATH})
136  endif ()
137else ()
138  set (SZIP_FOUND 0)
139  set (SZIP_LIBRARIES)
140  set (SZIP_INCLUDE_DIRS)
141endif ()
142
143# Report the results.
144if (NOT SZIP_FOUND)
145  set (SZIP_DIR_MESSAGE
146      "SZip was not found. Make sure SZIP_LIBRARY and SZIP_INCLUDE_DIR are set or set the SZIP_INSTALL environment variable."
147  )
148  if (NOT SZIP_FIND_QUIETLY)
149    message (STATUS "${SZIP_DIR_MESSAGE}")
150  else ()
151    if (SZIP_FIND_REQUIRED)
152      message (FATAL_ERROR "SZip was NOT found and is Required by this project")
153    endif ()
154  endif ()
155endif ()
156
157if (SZIP_FOUND)
158  include (CheckSymbolExists)
159  #############################################
160  # Find out if SZIP was build using dll's
161  #############################################
162  # Save required variable
163  set (CMAKE_REQUIRED_INCLUDES_SAVE ${CMAKE_REQUIRED_INCLUDES})
164  set (CMAKE_REQUIRED_FLAGS_SAVE    ${CMAKE_REQUIRED_FLAGS})
165  # Add SZIP_INCLUDE_DIR to CMAKE_REQUIRED_INCLUDES
166  set (CMAKE_REQUIRED_INCLUDES "${CMAKE_REQUIRED_INCLUDES};${SZIP_INCLUDE_DIRS}")
167
168  # Restore CMAKE_REQUIRED_INCLUDES and CMAKE_REQUIRED_FLAGS variables
169  set (CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES_SAVE})
170  set (CMAKE_REQUIRED_FLAGS    ${CMAKE_REQUIRED_FLAGS_SAVE})
171  #
172  #############################################
173endif ()
174
175if (FIND_SZIP_DEBUG)
176  message (STATUS "SZIP_INCLUDE_DIR: ${SZIP_INCLUDE_DIR}")
177  message (STATUS "SZIP_INCLUDE_DIRS: ${SZIP_INCLUDE_DIRS}")
178  message (STATUS "SZIP_LIBRARY_DEBUG: ${SZIP_LIBRARY_DEBUG}")
179  message (STATUS "SZIP_LIBRARY_RELEASE: ${SZIP_LIBRARY_RELEASE}")
180  message (STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
181endif ()
182