BASIS  r3148
FindAFNI.cmake
Go to the documentation of this file.
00001 ##############################################################################
00002 # @file  FindAFNI.cmake
00003 # @brief Find programs of the AFNI package.
00004 #
00005 # @sa http://afni.nimh.nih.gov/afni/
00006 #
00007 # @par Input variables:
00008 # <table border="0">
00009 #   <tr>
00010 #     @tp @b AFNI_DIR @endtp
00011 #     <td>The AFNI package files are searched under the specified root
00012 #         directory. If they are not found there, the default search paths
00013 #         are considered. This variable can also be set as environment variable.</td>
00014 #   </tr>
00015 #   <tr>
00016 #     @tp @b AFNI_FIND_COMPONENTS @endp
00017 #     <td>List of components, i.e., AFNI programs, to look for.
00018 #         Specify using COMPONENTS argument of find_package() command.</td>
00019 #   </tr>
00020 #   <tr>
00021 #     @tp @b AFNI_FIND_OPTIONAL_COMPONENTS @endp
00022 #     <td>List of optional components, i.e., AFNI programs, to look for.</td>
00023 #         Specify using OPTIONAL_COMPONENTS argument of find_package() command.</td>
00024 #   </tr>
00025 # </table>
00026 #
00027 # @par Output variables:
00028 # <table border="0">
00029 #   <tr>
00030 #     @tp @b AFNI_FOUND @endtp
00031 #     <td>Whether all required programs of the AFNI package were found. If only
00032 #         optional programs were searched, this variable is set to @c TRUE if
00033 #         all named programs were found.</td>
00034 #   </tr>
00035 #   <tr>
00036 #     @tp @b AFNI_&lt;tool%gt;_EXECUTABLE @endtp
00037 #     <td>Absolute path of the corresponding found AFNI program, e.g., @c AFNI_3dcalc_EXECUTABLE.</td>
00038 #   </tr>
00039 # </table>
00040 #
00041 # Copyright (c) 2012 University of Pennsylvania. All rights reserved.<br />
00042 # See https://www.cbica.upenn.edu/sbia/software/license.html or COPYING file.
00043 #
00044 # Contact: SBIA Group <sbia-software at uphs.upenn.edu>
00045 #
00046 # @ingroup CMakeFindModules
00047 ##############################################################################
00048 
00049 # ----------------------------------------------------------------------------
00050 # initialize search
00051 if (NOT AFNI_DIR)
00052   set (AFNI_DIR "$ENV{AFNI_DIR}" CACHE PATH "Installation prefix of AFNI." FORCE)
00053 endif ()
00054 
00055 if (NOT AFNI_FIND_COMPONENTS AND NOT AFNI_FIND_OPTIONAL_COMPONENTS)
00056   message (FATAL_ERROR "The FindAFNI.cmake module requires a list of AFNI programs to look for"
00057                        " specified using the COMPONENTS and/or OPTIONAL_COMPONENTS argument"
00058                        " of the find_package() command, e.g.:"
00059                        "\n"
00060                        "find_package(AFNI COMPONENTS 3dcalc)")
00061 endif ()
00062 
00063 # ----------------------------------------------------------------------------
00064 # private helper macro to look for a particular required or optional AFNI program
00065 macro (_AFNI_find_program NAME REQUIRED)
00066   if (AFNI_DIR)
00067     find_program (AFNI_${NAME}_EXECUTABLE NAMES ${NAME} HINTS ${AFNI_DIR} PATH_SUFFIXES bin NO_DEFAULT_PATH)
00068   else ()
00069     find_program (AFNI_${NAME}_EXECUTABLE NAMES ${NAME})
00070   endif ()
00071   if (NOT AFNI_${NAME}_EXECUTABLE)
00072     if (AFNI_FIND_COMPONENTS)
00073       # looking either only for required components or for both optional and
00074       # and required components; in this case, let AFNI_FOUND reflect only
00075       # whether all required components were found, but ignore the optional ones;
00076       # the caller can still check AFNI_<tool>_EXECUTABLE explicitly for these
00077       # optional components to see whether or not a particular AFNI programs was found
00078       if (REQUIRED)
00079         set (AFNI_FOUND FALSE)
00080       endif ()
00081     else ()
00082       # looking only for optional components anyway, so let AFNI_FOUND reflect
00083       # if all of these optional components were found instead
00084       set (AFNI_FOUND FALSE)
00085     endif ()
00086     if (REQUIRED)
00087       list (APPEND _AFNI_MISSING_COMPONENTS ${NAME})
00088     else ()
00089       list (APPEND _AFNI_MISSING_OPTIONAL_COMPONENTS ${NAME})
00090     endif ()
00091   endif ()
00092   mark_as_advanced (AFNI_${NAME}_EXECUTABLE)
00093 endmacro ()
00094 
00095 # ----------------------------------------------------------------------------
00096 # find AFNI program(s)
00097 set (AFNI_FOUND TRUE)
00098 
00099 set (_AFNI_MISSING_COMPONENTS)
00100 foreach (_AFNI_TOOL IN LISTS AFNI_FIND_COMPONENTS)
00101   _AFNI_find_program (${_AFNI_TOOL} TRUE)
00102 endforeach ()
00103 
00104 set (_AFNI_MISSING_OPTIONAL_COMPONENTS)
00105 foreach (_AFNI_TOOL IN LISTS AFNI_FIND_OPTIONAL_COMPONENTS)
00106   _AFNI_find_program (${_AFNI_TOOL} FALSE)
00107 endforeach ()
00108 
00109 # ----------------------------------------------------------------------------
00110 # handle the QUIETLY and REQUIRED arguments
00111 set (_AFNI_HELP_MESSAGE "Please set AFNI_DIR to the directory containing these executables or specify the location of each not found executable using the advanced AFNI_<tool>_EXECUTABLE CMake variables.")
00112 
00113 if (_AFNI_MISSING_COMPONENTS)
00114   message (FATAL_ERROR "Could NOT find the following required AFNI program(s):\n${_AFNI_MISSING_COMPONENTS}\n${_AFNI_HELP_MESSAGE}")
00115 elseif (_AFNI_MISSING_OPTIONAL_COMPONENTS AND NOT AFNI_FIND_QUIETLY)
00116   message (WARNING "Could NOT find the following optional AFNI program(s):\n${_AFNI_MISSING_OPTIONAL_COMPONENTS}\n${_AFNI_HELP_MESSAGE}")
00117 endif ()
00118 
00119 # ----------------------------------------------------------------------------
00120 # set AFNI_DIR
00121 if (NOT AFNI_DIR)
00122   foreach (_AFNI_TOOL IN LISTS AFNI_FIND_COMPONENTS AFNI_FIND_OPTIONAL_COMPONENTS)
00123     if (AFNI_${_AFNI_TOOL}_EXECUTABLE)
00124       get_filename_component (AFNI_DIR "${AFNI_${_AFNI_TOOL}_EXECUTABLE}" PATH)
00125       string (REGEX REPLACE "/bin/?" "" AFNI_DIR "${AFNI_DIR}")
00126       set (AFNI_DIR "${AFNI_DIR}" CACHE PATH "Installation prefix of AFNI." FORCE)
00127       break ()
00128     endif ()
00129   endforeach ()
00130 endif ()
00131 
00132 
00133 unset (_AFNI_TOOL)
00134 unset (_AFNI_HELP_MESSAGE)
00135 unset (_AFNI_MISSING_COMPONENTS)
00136 unset (_AFNI_MISSING_OPTIONAL_COMPONENTS)