HPCW 3.0
Loading...
Searching...
No Matches
FindSZIP.cmake
Go to the documentation of this file.
1# Copyright (c) 2006 - 2016 Kitware, Inc.
2# Copyright (c) 2019 - 2024 David Guibert
3# All rights reserved.
4#
5# SPDX-License-Identifier: Apache-2.0
6
7# .rst: FindSZIP
8# ---------
9#
10# Find SZIP, a compression library developed by HDF5.
11#
12# Once done this will define
13#
14# :: SZIP_FOUND - System has SZIP SZIP_INCLUDE_DIRS - The SZIP include
15# directories to use SZIP_LIBRARIES - Link these to use SZIP SZIP_VERSION - The
16# version of SZIP found ::
17#
18# The following imported target is also created:
19#
20# :: SZIP::SZIP ::
21#
22# The following variable can be set to guide the search for SZIP libraries and
23# includes: SZIP_ROOT_DIR - Search order preference is SZIP_ROOT_DIR followed by
24# ENV{SZIP_INSTALL}. If SZIP_ROOT_DIR is specified then it is searched
25# exclusively, ignoring default search paths.
26
27# =============================================================================
28# Copyright 2006-2016 Kitware, Inc.
29#
30# Distributed under the OSI-approved BSD License (the "License"); see
31# accompanying file Copyright.txt for details.
32#
33# This software is distributed WITHOUT ANY WARRANTY; without even the implied
34# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35# License for more information.
36# =============================================================================
37# (To distribute this file outside of CMake, substitute the full License text
38# for the above reference.)
39
40function(_SZIP_get_version)
41 set(scratch_dir ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/szip)
42 set(test_file ${scratch_dir}/cmake_szip_version.c)
43 file(
44 WRITE ${test_file}
45 "#include <stdlib.h>\n" "#include <szlib.h>\n" "int main(void) {\n"
46 " char const* info_ver = \"INFO\" \":\" SZLIB_VERSION;\n" " return 0;\n"
47 "}")
48 try_compile(
49 szip_version_test ${scratch_dir}
50 ${test_file}
51 CMAKE_FLAGS -DINCLUDE_DIRECTORIES=${SZIP_INCLUDE_DIR}
52 COPY_FILE ${scratch_dir}/cmake_szip_version)
53 if(szip_version_test)
54 file(STRINGS ${scratch_dir}/cmake_szip_version INFO_VER
55 REGEX "^INFO:([0-9]+(\\.[0-9]+(\\.[0-9]+)?)?)$")
56 string(REGEX MATCH "^INFO:([0-9]+(\\.[0-9]+(\\.[0-9]+)?)?)$" INFO_VER
57 "${INFO_VER}")
58 set(SZIP_VERSION
59 ${CMAKE_MATCH_1}
60 PARENT_SCOPE)
61 endif()
62endfunction()
63
64# If the root dir is explicitly specified, then ONLY look there
65message("SZIP_ROOT_DIR: ${SZIP_ROOT_DIR}")
66message("ENV{SZIP_INSTALL}: $ENV{SZIP_INSTALL}")
67if(SZIP_ROOT_DIR)
68 set(SZIP_SEARCH_OPTS PATHS ${SZIP_ROOT_DIR} NO_DEFAULT_PATH)
69elseif(NOT ("$ENV{SZIP_INSTALL}" STREQUAL ""))
70 message("DEBUG: ENV{SZIP_INSTALL}")
71 set(SZIP_SEARCH_OPTS HINTS ENV SZIP_INSTALL)
72endif()
73
74# Find the main header
75find_path(
76 SZIP_INCLUDE_DIR
77 NAMES szlib.h ${SZIP_SEARCH_OPTS}
78 PATH_SUFFIXES include include/szip Include Include/szip)
79mark_as_advanced(SZIP_INCLUDE_DIR)
80
81# Find the release library
82set(SZIP_LIBRARY_RELEASE_NAMES sz szip)
83if(WIN32)
84 list(APPEND SZIP_LIBRARY_RELEASE_NAMES libsz libszip)
85endif()
86find_library(
87 SZIP_LIBRARY_RELEASE
88 NAMES ${SZIP_LIBRARY_RELEASE_NAMES} ${SZIP_SEARCH_OPTS}
89 PATH_SUFFIXES lib Lib)
90
91# Find the debug library
92set(SZIP_LIBRARY_DEBUG_NAMES sz_d szip_d)
93if(WIN32)
94 list(APPEND SZIP_LIBARY_DEBUG_NAMES libsz_d libszip_d)
95endif()
96find_library(
97 SZIP_LIBRARY_DEBUG
98 NAMES ${SZIP_LIBRARY_DEBUG_NAMES} ${SZIP_SEARCH_OPTS}
99 PATH_SUFFIXES lib Lib)
100
101include(SelectLibraryConfigurations)
102select_library_configurations(SZIP)
103
104if(SZIP_INCLUDE_DIR)
105 _szip_get_version()
106endif()
107
108include(FindPackageHandleStandardArgs)
109find_package_handle_standard_args(
110 SZIP
111 REQUIRED_VARS SZIP_LIBRARY SZIP_INCLUDE_DIR
112 VERSION_VAR SZIP_VERSION)
113
114# Set up the appropriate import target
115if(SZIP_FOUND)
116 set(SZIP_LIBRARIES ${SZIP_LIBRARY})
117 set(SZIP_INCLUDE_DIRS ${SZIP_INCLUDE_DIR})
118 if(NOT TARGET SZIP::SZIP)
119 add_library(SZIP::SZIP UNKNOWN IMPORTED)
120 set_target_properties(SZIP::SZIP PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
121 ${SZIP_INCLUDE_DIR})
122 if(SZIP_VERSION)
123 set_target_properties(SZIP::SZIP PROPERTIES VERSION ${SZIP_VERSION})
124 endif()
125 if(SZIP_LIBRARY_RELEASE)
126 set_target_properties(SZIP::SZIP PROPERTIES IMPORTED_LOCATION_RELEASE
127 ${SZIP_LIBRARY_RELEASE})
128 endif()
129 if(SZIP_LIBRARY_DEBUG)
130 set_target_properties(SZIP::SZIP PROPERTIES IMPORTED_LOCATION_DEBUG
131 ${SZIP_LIBRARY_DEBUG})
132 endif()
133 endif()
134endif()