BASIS  version 1.2.3 (revision 2104)
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)
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         nifti1_io.h
00108       HINTS         ${NiftiCLib_DIR}
00109       PATH_SUFFIXES "include" "include/nifti"
00110       DOC           "Path of directory containing nifti1.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         nifti1_io.h
00135       HINTS         ENV C_INCLUDE_PATH ENV CXX_INCLUDE_PATH
00136       PATH_SUFFIXES nifti
00137       DOC           "Path of directory containing nifti1.h file."
00138   )
00139 
00140   find_library (
00141     NiftiCLib_LIBRARY
00142       NAMES niftiio
00143       HINTS ENV LD_LIBRARY_PATH
00144       DOC   "Path of niftiio library"
00145   )
00146 
00147   find_library (
00148     NiftiCLib_znz_LIBRARY
00149       NAMES znz
00150       HINTS ENV LD_LIBRARY_PATH
00151       DOC   "Path of znz library"
00152   )
00153 
00154 endif ()
00155 
00156 mark_as_advanced (NiftiCLib_INCLUDE_DIR)
00157 mark_as_advanced (NiftiCLib_LIBRARY)
00158 mark_as_advanced (NiftiCLib_znz_LIBRARY)
00159 
00160 # ----------------------------------------------------------------------------
00161 # aliases / backwards compatibility
00162 if (NiftiCLib_INCLUDE_DIR)
00163   set (NiftiCLib_INCLUDE_DIRS "${NiftiCLib_INCLUDE_DIR}")
00164   set (NiftiCLib_INCLUDES     "${NiftiCLib_INCLUDE_DIR}")
00165 endif ()
00166 
00167 if (NiftiCLib_LIBRARY)
00168   set (NiftiCLib_LIB "${NiftiCLib_LIBRARY}")
00169 endif ()
00170 
00171 if (NiftiCLib_LIBRARY)
00172   set (NiftiCLib_LIBRARIES "${NiftiCLib_LIBRARY}")
00173 endif ()
00174 if (NiftiCLib_LIBRARIES AND NiftiCLib_znz_LIBRARY)
00175   list (APPEND NiftiCLib_LIBRARIES "${NiftiCLib_znz_LIBRARY}")
00176 endif ()
00177 
00178 # ----------------------------------------------------------------------------
00179 # import targets
00180 if (NiftiCLib_LIBRARY)
00181   if (NiftiCLib_USE_STATIC_LIB)
00182     add_library (niftiio STATIC IMPORTED)
00183   else ()
00184     add_library (niftiio SHARED IMPORTED)
00185   endif ()
00186 
00187   set_target_properties (
00188     niftiio
00189     PROPERTIES
00190       IMPORTED_LINK_INTERFACE_LANGUAGES "CXX"
00191       IMPORTED_LOCATION "${NiftiCLib_LIBRARY}"
00192   )
00193 endif ()
00194 
00195 # ----------------------------------------------------------------------------
00196 # reset CMake variables
00197 set (CMAKE_FIND_LIBRARY_SUFFIXES ${NiftiCLib_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES})
00198 
00199 # ----------------------------------------------------------------------------
00200 # handle the QUIETLY and REQUIRED arguments and set *_FOUND to TRUE
00201 # if all listed variables are found or TRUE
00202 include (FindPackageHandleStandardArgs)
00203 
00204 find_package_handle_standard_args (
00205   NiftiCLib
00206   REQUIRED_VARS
00207     NiftiCLib_INCLUDE_DIR
00208     NiftiCLib_LIBRARY
00209 )
00210 
00211 set (NiftiCLib_FOUND ${NIFTICLIB_FOUND})
00212 
00213 # ----------------------------------------------------------------------------
00214 # set NiftiCLib_DIR
00215 if (NOT NiftiCLib_DIR AND NiftiCLib_FOUND)
00216   string (REGEX REPLACE "include/nifti/?" "" NiftiCLib_PREFIX "${NiftiCLib_INCLUDE_DIR}")
00217   set (NiftiCLib_DIR "${NiftiCLib_PREFIX}" CACHE PATH "Installation prefix for NiftiCLib." FORCE)
00218   unset (NiftiCLib_PREFIX)
00219 endif ()