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