FindNiftiCLib.cmake
Go to the documentation of this file.
00001 ############################################################################## 00002 # @file FindNiftiCLib.cmake 00003 # @brief Find nifticlib package. 00004 # 00005 # @par Input variables: 00006 # <table border="0"> 00007 # <tr> 00008 # @tp @b NiftiCLib_DIR @endtp 00009 # <td>The nifticlib package files are searched under the specified root 00010 # directory. If they are not found there, the default search paths 00011 # are considered. This variable can also be set as environment variable.</td> 00012 # </tr> 00013 # <tr> 00014 # @tp @b NIFTICLIB_DIR @endtp 00015 # <td>Alternative environment variable for @p NiftiCLib_DIR.</td> 00016 # </tr> 00017 # <tr> 00018 # @tp @b NiftiCLib_USE_STATIC_LIB @endtp 00019 # <td>Forces this module to search for the static library. Otherwise, 00020 # the shared library is preferred.</td> 00021 # </tr> 00022 # </table> 00023 # 00024 # @par Output variables: 00025 # <table border="0"> 00026 # <tr> 00027 # @tp @b NiftiCLib_FOUND @endtp 00028 # <td>Whether the nifticlib package was found and the following CMake 00029 # variables are valid.</td> 00030 # </tr> 00031 # <tr> 00032 # @tp @b NiftiCLib_INCLUDE_DIR @endtp 00033 # <td>Cached include directory/ies.</td> 00034 # </tr> 00035 # <tr> 00036 # @tp @b NiftiCLib_INCLUDE_DIRS @endtp 00037 # <td>Alias for @p NiftiCLib_INCLUDE_DIR (not cached).</td> 00038 # </tr> 00039 # <tr> 00040 # @tp @b NiftiCLib_INCLUDES @endtp 00041 # <td>Alias for @p NiftiCLib_INCLUDE_DIR (not cached).</td> 00042 # </tr> 00043 # <tr> 00044 # @tp @b NiftiCLib_LIBRARY @endtp 00045 # <td>Path of @c niftiio library.</td> 00046 # </tr> 00047 # <tr> 00048 # @tp @b NiftiCLib_LIB @endtp 00049 # <td>Alias for @p NiftiCLib_LIBRARY (not cached).</td> 00050 # </tr> 00051 # <tr> 00052 # @tp @b NiftiCLib_LIBRARIES @endtp 00053 # <td>Path of @c niftiio library and prerequisite libraries.</td> 00054 # </tr> 00055 # </table> 00056 # 00057 # @par Imported targets: 00058 # <table border="0"> 00059 # <tr> 00060 # @tp @b niftiio @endtp 00061 # <td>The library target of the @c nifticlib library.</td> 00062 # </tr> 00063 # </table> 00064 # 00065 # Copyright (c) 2011, 2012 University of Pennsylvania. All rights reserved.<br /> 00066 # See https://www.cbica.upenn.edu/sbia/software/license.html or COPYING file. 00067 # 00068 # Contact: SBIA Group <sbia-software at uphs.upenn.edu> 00069 # 00070 # @ingroup CMakeFindModules 00071 ############################################################################## 00072 00073 # ---------------------------------------------------------------------------- 00074 # initialize search 00075 if (NOT NiftiCLib_DIR) 00076 if (NOT "$ENV{NIFTICLIB_DIR}" STREQUAL "") 00077 set (NiftiCLib_DIR "$ENV{NIFTICLIB_DIR}" CACHE PATH "Installation prefix for NiftiCLib." FORCE) 00078 else () 00079 set (NiftiCLib_DIR "$ENV{NiftiCLib_DIR}" CACHE PATH "Installation prefix for NiftiCLib." FORCE) 00080 endif () 00081 endif () 00082 00083 set (NiftiCLib_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES}) 00084 00085 if (NiftiCLib_USE_STATIC_LIB) 00086 if (WIN32) 00087 set (CMAKE_FIND_LIBRARY_SUFFIXES .lib) 00088 else () 00089 set (CMAKE_FIND_LIBRARY_SUFFIXES .a) 00090 endif() 00091 else () 00092 if (WIN32) 00093 set (CMAKE_FIND_LIBRARY_SUFFIXES .dll .lib) 00094 elseif(APPLE) 00095 set (CMAKE_FIND_LIBRARY_SUFFIXES .dylib .a) 00096 else () 00097 set (CMAKE_FIND_LIBRARY_SUFFIXES .so .a) 00098 endif() 00099 endif () 00100 00101 # ---------------------------------------------------------------------------- 00102 # find paths/files 00103 if (NiftiCLib_DIR) 00104 00105 find_path ( 00106 NiftiCLib_INCLUDE_DIR 00107 NAMES nifti/nifti1_io.h 00108 HINTS ${NiftiCLib_DIR} 00109 PATH_SUFFIXES "include" 00110 DOC "Path of directory containing nifti1_io.h file." 00111 NO_DEFAULT_PATH 00112 ) 00113 00114 find_library ( 00115 NiftiCLib_LIBRARY 00116 NAMES niftiio 00117 HINTS ${NiftiCLib_DIR} 00118 PATH_SUFFIXES lib 00119 DOC "Path of niftiio library" 00120 NO_DEFAULT_PATH 00121 ) 00122 00123 find_library ( 00124 NiftiCLib_znz_LIBRARY 00125 NAMES znz 00126 HINTS ENV LD_LIBRARY_PATH 00127 DOC "Path of znz library" 00128 ) 00129 00130 else () 00131 00132 find_path ( 00133 NiftiCLib_INCLUDE_DIR 00134 NAMES nifti/nifti1_io.h 00135 HINTS ENV C_INCLUDE_PATH ENV CXX_INCLUDE_PATH 00136 DOC "Path of directory containing nifti1_io.h file." 00137 ) 00138 00139 find_library ( 00140 NiftiCLib_LIBRARY 00141 NAMES niftiio 00142 HINTS ENV LD_LIBRARY_PATH 00143 DOC "Path of niftiio library" 00144 ) 00145 00146 find_library ( 00147 NiftiCLib_znz_LIBRARY 00148 NAMES znz 00149 HINTS ENV LD_LIBRARY_PATH 00150 DOC "Path of znz library" 00151 ) 00152 00153 endif () 00154 00155 mark_as_advanced (NiftiCLib_INCLUDE_DIR) 00156 mark_as_advanced (NiftiCLib_LIBRARY) 00157 mark_as_advanced (NiftiCLib_znz_LIBRARY) 00158 00159 # ---------------------------------------------------------------------------- 00160 # prerequisites 00161 if (NiftiCLib_USE_STATIC_LIB OR NiftiCLib_znz_LIBRARY MATCHES "\\.a$") 00162 find_package (ZLIB REQUIRED) 00163 endif () 00164 00165 set (NiftiCLib_LIBRARIES "${ZLIB_LIBRARIES}") 00166 if (NiftiCLib_znz_LIBRARY) 00167 list (APPEND NiftiCLib_LIBRARIES "${NiftiCLib_znz_LIBRARY}") 00168 endif () 00169 if (NiftiCLib_LIBRARY) 00170 list (APPEND NiftiCLib_LIBRARIES "${NiftiCLib_LIBRARY}") 00171 endif () 00172 00173 # ---------------------------------------------------------------------------- 00174 # import targets 00175 if (NiftiCLib_znz_LIBRARY) 00176 if (NiftiCLib_USE_STATIC_LIB OR NiftiCLib_znz_LIBRARY MATCHES "\\.a$") 00177 add_library (niftiznz STATIC IMPORTED) 00178 else () 00179 add_library (niftiznz SHARED IMPORTED) 00180 endif () 00181 set_target_properties ( 00182 niftiznz 00183 PROPERTIES 00184 IMPORTED_LINK_INTERFACE_LANGUAGES "CXX" 00185 IMPORTED_LOCATION "${NiftiCLib_znz_LIBRARY}" 00186 IMPORTED_LINK_INTERFACE_LIBRARIES "${ZLIB_LIBRARIES}" 00187 ) 00188 endif () 00189 00190 if (NiftiCLib_LIBRARY) 00191 if (NiftiCLib_USE_STATIC_LIB OR NiftiCLib_LIBRARY MATCHES "\\.a$") 00192 add_library (niftiio STATIC IMPORTED) 00193 else () 00194 add_library (niftiio SHARED IMPORTED) 00195 endif () 00196 set_target_properties ( 00197 niftiio 00198 PROPERTIES 00199 IMPORTED_LINK_INTERFACE_LANGUAGES "CXX" 00200 IMPORTED_LOCATION "${NiftiCLib_LIBRARY}" 00201 ) 00202 if (TARGET niftiznz) 00203 set_target_properties (niftiio PROPERTIES IMPORTED_LINK_INTERFACE_LIBRARIES niftiznz) 00204 endif () 00205 endif () 00206 00207 # ---------------------------------------------------------------------------- 00208 # aliases / backwards compatibility 00209 if (NiftiCLib_INCLUDE_DIR) 00210 set (NiftiCLib_INCLUDE_DIRS "${NiftiCLib_INCLUDE_DIR}") 00211 if (NOT NiftiCLib_INCLUDE_DIR MATCHES "/nifti/?$") 00212 list (APPEND NiftiCLib_INCLUDE_DIRS "${NiftiCLib_INCLUDE_DIR}/nifti") 00213 endif () 00214 set (NiftiCLib_INCLUDES "${NiftiCLib_INCLUDE_DIRS}") 00215 endif () 00216 00217 if (NiftiCLib_LIBRARY) 00218 set (NiftiCLib_LIB "${NiftiCLib_LIBRARY}") 00219 endif () 00220 00221 # ---------------------------------------------------------------------------- 00222 # reset CMake variables 00223 set (CMAKE_FIND_LIBRARY_SUFFIXES ${NiftiCLib_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES}) 00224 00225 # ---------------------------------------------------------------------------- 00226 # handle the QUIETLY and REQUIRED arguments and set *_FOUND to TRUE 00227 # if all listed variables are found or TRUE 00228 include (FindPackageHandleStandardArgs) 00229 00230 find_package_handle_standard_args ( 00231 NiftiCLib 00232 REQUIRED_VARS 00233 NiftiCLib_INCLUDE_DIR 00234 NiftiCLib_LIBRARY 00235 NiftiCLib_znz_LIBRARY 00236 ) 00237 00238 set (NiftiCLib_FOUND ${NIFTICLIB_FOUND}) 00239 00240 # ---------------------------------------------------------------------------- 00241 # set NiftiCLib_DIR 00242 if (NOT NiftiCLib_DIR AND NiftiCLib_FOUND) 00243 string (REGEX REPLACE "include(/nifti)?/?" "" NiftiCLib_PREFIX "${NiftiCLib_INCLUDE_DIR}") 00244 set (NiftiCLib_DIR "${NiftiCLib_PREFIX}" CACHE PATH "Installation prefix for NiftiCLib." FORCE) 00245 unset (NiftiCLib_PREFIX) 00246 endif ()