FindAFNI.cmake
Go to the documentation of this file.
1 ##############################################################################
2 # @file FindAFNI.cmake
3 # @brief Find programs of the AFNI package.
4 #
5 # @sa http://afni.nimh.nih.gov/afni/
6 #
7 # @par Input variables:
8 # <table border="0">
9 # <tr>
10 # @tp @b AFNI_DIR @endtp
11 # <td>The AFNI package files are searched under the specified root
12 # directory. If they are not found there, the default search paths
13 # are considered. This variable can also be set as environment variable.</td>
14 # </tr>
15 # <tr>
16 # @tp @b AFNI_FIND_COMPONENTS @endtp
17 # <td>List of components, i.e., AFNI programs, to look for.
18 # Specify using COMPONENTS argument of find_package() command.</td>
19 # </tr>
20 # <tr>
21 # @tp @b AFNI_FIND_OPTIONAL_COMPONENTS @endtp
22 # <td>List of optional components, i.e., AFNI programs, to look for.
23 # Specify using OPTIONAL_COMPONENTS argument of find_package() command.</td>
24 # </tr>
25 # </table>
26 #
27 # @par Output variables:
28 # <table border="0">
29 # <tr>
30 # @tp @b AFNI_FOUND @endtp
31 # <td>Whether all required programs of the AFNI package were found. If only
32 # optional programs were searched, this variable is set to @c TRUE if
33 # all named programs were found.</td>
34 # </tr>
35 # <tr>
36 # @tp @b AFNI_&lt;tool&gt;_EXECUTABLE @endtp
37 # <td>Absolute path of the corresponding found AFNI program, e.g., @c AFNI_3dcalc_EXECUTABLE.</td>
38 # </tr>
39 # </table>
40 #
41 # @ingroup CMakeFindModules
42 ##############################################################################
43 
44 #=============================================================================
45 # Copyright 2011-2012 University of Pennsylvania
46 # Copyright 2013-2016 Andreas Schuh <andreas.schuh.84@gmail.com>
47 #
48 # Distributed under the OSI-approved BSD License (the "License");
49 # see accompanying file Copyright.txt for details.
50 #
51 # This software is distributed WITHOUT ANY WARRANTY; without even the
52 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
53 # See the License for more information.
54 #=============================================================================
55 # (To distribute this file outside of CMake, substitute the full
56 # License text for the above reference.)
57 
58 # ----------------------------------------------------------------------------
59 # initialize search
60 if (NOT AFNI_DIR)
61  set (AFNI_DIR "$ENV{AFNI_DIR}" CACHE PATH "Installation prefix of AFNI." FORCE)
62 endif ()
63 
64 if (NOT AFNI_FIND_COMPONENTS AND NOT AFNI_FIND_OPTIONAL_COMPONENTS)
65  message (FATAL_ERROR "The FindAFNI.cmake module requires a list of AFNI programs to look for"
66  " specified using the COMPONENTS and/or OPTIONAL_COMPONENTS argument"
67  " of the find_package() command, e.g.:"
68  "\n"
69  "find_package(AFNI COMPONENTS 3dcalc)")
70 endif ()
71 
72 # ----------------------------------------------------------------------------
73 # private helper macro to look for a particular required or optional AFNI program
74 macro (_AFNI_find_program NAME REQUIRED)
75  if (AFNI_DIR)
76  find_program (AFNI_${NAME}_EXECUTABLE NAMES ${NAME} HINTS ${AFNI_DIR} PATH_SUFFIXES bin NO_DEFAULT_PATH)
77  else ()
78  find_program (AFNI_${NAME}_EXECUTABLE NAMES ${NAME})
79  endif ()
80  if (NOT AFNI_${NAME}_EXECUTABLE)
81  if (AFNI_FIND_COMPONENTS)
82  # looking either only for required components or for both optional and
83  # and required components; in this case, let AFNI_FOUND reflect only
84  # whether all required components were found, but ignore the optional ones;
85  # the caller can still check AFNI_<tool>_EXECUTABLE explicitly for these
86  # optional components to see whether or not a particular AFNI programs was found
87  if (REQUIRED)
88  set (AFNI_FOUND FALSE)
89  endif ()
90  else ()
91  # looking only for optional components anyway, so let AFNI_FOUND reflect
92  # if all of these optional components were found instead
93  set (AFNI_FOUND FALSE)
94  endif ()
95  if (REQUIRED)
96  list (APPEND _AFNI_MISSING_COMPONENTS ${NAME})
97  else ()
98  list (APPEND _AFNI_MISSING_OPTIONAL_COMPONENTS ${NAME})
99  endif ()
100  endif ()
101  mark_as_advanced (AFNI_${NAME}_EXECUTABLE)
102 endmacro ()
103 
104 # ----------------------------------------------------------------------------
105 # find AFNI program(s)
106 set (AFNI_FOUND TRUE)
107 
108 set (_AFNI_MISSING_COMPONENTS)
109 foreach (_AFNI_TOOL IN LISTS AFNI_FIND_COMPONENTS)
110  _AFNI_find_program (${_AFNI_TOOL} TRUE)
111 endforeach ()
112 
113 set (_AFNI_MISSING_OPTIONAL_COMPONENTS)
114 foreach (_AFNI_TOOL IN LISTS AFNI_FIND_OPTIONAL_COMPONENTS)
115  _AFNI_find_program (${_AFNI_TOOL} FALSE)
116 endforeach ()
117 
118 # ----------------------------------------------------------------------------
119 # handle the QUIETLY and REQUIRED arguments
120 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.")
121 
122 if (_AFNI_MISSING_COMPONENTS)
123  message (FATAL_ERROR "Could NOT find the following required AFNI program(s):\n${_AFNI_MISSING_COMPONENTS}\n${_AFNI_HELP_MESSAGE}")
124 elseif (_AFNI_MISSING_OPTIONAL_COMPONENTS AND NOT AFNI_FIND_QUIETLY)
125  message (WARNING "Could NOT find the following optional AFNI program(s):\n${_AFNI_MISSING_OPTIONAL_COMPONENTS}\n${_AFNI_HELP_MESSAGE}")
126 endif ()
127 
128 # ----------------------------------------------------------------------------
129 # set AFNI_DIR
130 if (NOT AFNI_DIR)
131  foreach (_AFNI_TOOL IN LISTS AFNI_FIND_COMPONENTS AFNI_FIND_OPTIONAL_COMPONENTS)
132  if (AFNI_${_AFNI_TOOL}_EXECUTABLE)
133  get_filename_component (AFNI_DIR "${AFNI_${_AFNI_TOOL}_EXECUTABLE}" PATH)
134  string (REGEX REPLACE "/bin/?" "" AFNI_DIR "${AFNI_DIR}")
135  set (AFNI_DIR "${AFNI_DIR}" CACHE PATH "Installation prefix of AFNI." FORCE)
136  break ()
137  endif ()
138  endforeach ()
139 endif ()
140 
141 
142 unset (_AFNI_TOOL)
143 unset (_AFNI_HELP_MESSAGE)
144 unset (_AFNI_MISSING_COMPONENTS)
145 unset (_AFNI_MISSING_OPTIONAL_COMPONENTS)
cmake AFNI_FOUND
Definition: FindAFNI.cmake:106
cmake _AFNI_HELP_MESSAGE
Definition: FindAFNI.cmake:120
cmake NAME
cmake AFNI_DIR
Definition: FindAFNI.cmake:44