FindNiftiCLib.cmake
Go to the documentation of this file.
1 ##############################################################################
2 # @file FindNiftiCLib.cmake
3 # @brief Find nifticlib package.
4 #
5 # @par Input variables:
6 # <table border="0">
7 # <tr>
8 # @tp @b NiftiCLib_DIR @endtp
9 # <td>The nifticlib package files are searched under the specified root
10 # directory. If they are not found there, the default search paths
11 # are considered. This variable can also be set as environment variable.</td>
12 # </tr>
13 # <tr>
14 # @tp @b NIFTICLIB_DIR @endtp
15 # <td>Alternative environment variable for @p NiftiCLib_DIR.</td>
16 # </tr>
17 # <tr>
18 # @tp @b NiftiCLib_USE_STATIC_LIB @endtp
19 # <td>Forces this module to search for the static library. Otherwise,
20 # the shared library is preferred.</td>
21 # </tr>
22 # </table>
23 #
24 # @par Output variables:
25 # <table border="0">
26 # <tr>
27 # @tp @b NiftiCLib_FOUND @endtp
28 # <td>Whether the nifticlib package was found and the following CMake
29 # variables are valid.</td>
30 # </tr>
31 # <tr>
32 # @tp @b NiftiCLib_INCLUDE_DIR @endtp
33 # <td>Cached include directory/ies.</td>
34 # </tr>
35 # <tr>
36 # @tp @b NiftiCLib_INCLUDE_DIRS @endtp
37 # <td>Alias for @p NiftiCLib_INCLUDE_DIR (not cached).</td>
38 # </tr>
39 # <tr>
40 # @tp @b NiftiCLib_INCLUDES @endtp
41 # <td>Alias for @p NiftiCLib_INCLUDE_DIR (not cached).</td>
42 # </tr>
43 # <tr>
44 # @tp @b NiftiCLib_LIBRARY @endtp
45 # <td>Path of @c niftiio library.</td>
46 # </tr>
47 # <tr>
48 # @tp @b NiftiCLib_LIB @endtp
49 # <td>Alias for @p NiftiCLib_LIBRARY (not cached).</td>
50 # </tr>
51 # <tr>
52 # @tp @b NiftiCLib_LIBRARIES @endtp
53 # <td>Path of @c niftiio library and prerequisite libraries.</td>
54 # </tr>
55 # </table>
56 #
57 # @par Imported targets:
58 # <table border="0">
59 # <tr>
60 # @tp @b niftiio @endtp
61 # <td>The library target of the @c nifticlib library.</td>
62 # </tr>
63 # </table>
64 #
65 # @ingroup CMakeFindModules
66 ##############################################################################
67 
68 #=============================================================================
69 # Copyright 2011-2012 University of Pennsylvania
70 # Copyright 2013-2016 Andreas Schuh <andreas.schuh.84@gmail.com>
71 #
72 # Distributed under the OSI-approved BSD License (the "License");
73 # see accompanying file Copyright.txt for details.
74 #
75 # This software is distributed WITHOUT ANY WARRANTY; without even the
76 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
77 # See the License for more information.
78 #=============================================================================
79 # (To distribute this file outside of CMake, substitute the full
80 # License text for the above reference.)
81 
82 # ----------------------------------------------------------------------------
83 # initialize search
84 if (NOT NiftiCLib_DIR)
85  if (NOT "$ENV{NIFTICLIB_DIR}" STREQUAL "")
86  set (NiftiCLib_DIR "$ENV{NIFTICLIB_DIR}" CACHE PATH "Installation prefix for NiftiCLib." FORCE)
87  else ()
88  set (NiftiCLib_DIR "$ENV{NiftiCLib_DIR}" CACHE PATH "Installation prefix for NiftiCLib." FORCE)
89  endif ()
90 endif ()
91 
93 
94 if (NiftiCLib_USE_STATIC_LIB)
95  if (WIN32)
97  else ()
99  endif()
100 else ()
101  if (WIN32)
102  set (CMAKE_FIND_LIBRARY_SUFFIXES .dll .lib)
103  elseif(APPLE)
104  set (CMAKE_FIND_LIBRARY_SUFFIXES .dylib .a)
105  else ()
106  set (CMAKE_FIND_LIBRARY_SUFFIXES .so .a)
107  endif()
108 endif ()
109 
110 # ----------------------------------------------------------------------------
111 # find paths/files
112 if (NiftiCLib_DIR)
113 
114  find_path (
115  NiftiCLib_INCLUDE_DIR
116  NAMES nifti/nifti1_io.h
117  HINTS ${NiftiCLib_DIR}
118  PATH_SUFFIXES "include"
119  DOC "path to directory containing nifti1_io.h file."
120  NO_DEFAULT_PATH
121  )
122 
123  find_library (
124  NiftiCLib_LIBRARY
125  NAMES niftiio
126  HINTS ${NiftiCLib_DIR}
127  PATH_SUFFIXES lib
128  DOC "Path of niftiio library"
129  NO_DEFAULT_PATH
130  )
131 
132  find_library (
133  NiftiCLib_znz_LIBRARY
134  NAMES znz
135  HINTS ENV LD_LIBRARY_PATH
136  DOC "Path of znz library"
137  )
138 
139 else ()
140 
141  find_path (
142  NiftiCLib_INCLUDE_DIR
143  NAMES nifti/nifti1_io.h
144  HINTS ENV C_INCLUDE_PATH ENV CXX_INCLUDE_PATH
145  DOC "path to directory containing nifti1_io.h file."
146  )
147 
148  find_library (
149  NiftiCLib_LIBRARY
150  NAMES niftiio
151  HINTS ENV LD_LIBRARY_PATH
152  DOC "Path of niftiio library"
153  )
154 
155  find_library (
156  NiftiCLib_znz_LIBRARY
157  NAMES znz
158  HINTS ENV LD_LIBRARY_PATH
159  DOC "Path of znz library"
160  )
161 
162 endif ()
163 
164 mark_as_advanced (NiftiCLib_INCLUDE_DIR)
165 mark_as_advanced (NiftiCLib_LIBRARY)
166 mark_as_advanced (NiftiCLib_znz_LIBRARY)
167 
168 # ----------------------------------------------------------------------------
169 # prerequisites
170 if (NiftiCLib_USE_STATIC_LIB OR NiftiCLib_znz_LIBRARY MATCHES "\\.a$")
171  find_package (ZLIB REQUIRED)
172 endif ()
173 
174 set (NiftiCLib_LIBRARIES "${ZLIB_LIBRARIES}")
175 if (NiftiCLib_znz_LIBRARY)
176  list (APPEND NiftiCLib_LIBRARIES "${NiftiCLib_znz_LIBRARY}")
177 endif ()
178 if (NiftiCLib_LIBRARY)
179  list (APPEND NiftiCLib_LIBRARIES "${NiftiCLib_LIBRARY}")
180 endif ()
181 
182 # ----------------------------------------------------------------------------
183 # import targets
184 if (NiftiCLib_znz_LIBRARY)
185  if (NiftiCLib_USE_STATIC_LIB OR NiftiCLib_znz_LIBRARY MATCHES "\\.a$")
186  add_library (niftiznz STATIC IMPORTED)
187  else ()
188  add_library (niftiznz SHARED IMPORTED)
189  endif ()
190  set_target_properties (
191  niftiznz
192  PROPERTIES
193  IMPORTED_LINK_INTERFACE_LANGUAGES "CXX"
194  IMPORTED_LOCATION "${NiftiCLib_znz_LIBRARY}"
195  IMPORTED_LINK_INTERFACE_LIBRARIES "${ZLIB_LIBRARIES}"
196  )
197 endif ()
198 
199 if (NiftiCLib_LIBRARY)
200  if (NiftiCLib_USE_STATIC_LIB OR NiftiCLib_LIBRARY MATCHES "\\.a$")
201  add_library (niftiio STATIC IMPORTED)
202  else ()
203  add_library (niftiio SHARED IMPORTED)
204  endif ()
205  set_target_properties (
206  niftiio
207  PROPERTIES
208  IMPORTED_LINK_INTERFACE_LANGUAGES "CXX"
209  IMPORTED_LOCATION "${NiftiCLib_LIBRARY}"
210  )
211  if (TARGET niftiznz)
212  set_target_properties (niftiio PROPERTIES IMPORTED_LINK_INTERFACE_LIBRARIES niftiznz)
213  endif ()
214 endif ()
215 
216 # ----------------------------------------------------------------------------
217 # aliases / backwards compatibility
218 if (NiftiCLib_INCLUDE_DIR)
219  set (NiftiCLib_INCLUDE_DIRS "${NiftiCLib_INCLUDE_DIR}")
220  if (NOT NiftiCLib_INCLUDE_DIR MATCHES "/nifti/?$")
221  list (APPEND NiftiCLib_INCLUDE_DIRS "${NiftiCLib_INCLUDE_DIR}/nifti")
222  endif ()
223  set (NiftiCLib_INCLUDES "${NiftiCLib_INCLUDE_DIRS}")
224 endif ()
225 
226 if (NiftiCLib_LIBRARY)
227  set (NiftiCLib_LIB "${NiftiCLib_LIBRARY}")
228 endif ()
229 
230 # ----------------------------------------------------------------------------
231 # reset CMake variables
232 set (CMAKE_FIND_LIBRARY_SUFFIXES ${NiftiCLib_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES})
233 
234 # ----------------------------------------------------------------------------
235 # handle the QUIETLY and REQUIRED arguments and set *_FOUND to TRUE
236 # if all listed variables are found or TRUE
237 include (FindPackageHandleStandardArgs)
238 
239 find_package_handle_standard_args (
240  NiftiCLib
241  REQUIRED_VARS
242  NiftiCLib_INCLUDE_DIR
243  NiftiCLib_LIBRARY
244  NiftiCLib_znz_LIBRARY
245 )
246 
247 set (NiftiCLib_FOUND ${NIFTICLIB_FOUND})
248 
249 # ----------------------------------------------------------------------------
250 # set NiftiCLib_DIR
251 if (NOT NiftiCLib_DIR AND NiftiCLib_FOUND)
252  string (REGEX REPLACE "include(/nifti)?/?" "" NiftiCLib_PREFIX "${NiftiCLib_INCLUDE_DIR}")
253  set (NiftiCLib_DIR "${NiftiCLib_PREFIX}" CACHE PATH "Installation prefix for NiftiCLib." FORCE)
254  unset (NiftiCLib_PREFIX)
255 endif ()
cmake NiftiCLib_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES
cmake NiftiCLib_INCLUDE_DIRS
cmake NiftiCLib_LIBRARIES
cmake NiftiCLib_DIR
cmake CXX
macro find_package()
Overloaded find_package() command.
cmake CMAKE_FIND_LIBRARY_SUFFIXES