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 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
|
#!/bin/bash
# get absolute directory path to the build location:
# --build-dir, -b
build_destination="`pwd`"
# get absolute directory path to this script:
source_destination="`dirname $0`"
source_destination="`( cd "$source_destination"; pwd )`"
### DEFAULTS
# --install-dir, -i
# get absolute directory path to the install location:
install_destination="`( cd ..; pwd)`/install-QFitsView"
# --shared, --linked, -l | --static, -s
shared_build=true
# --architecture, -a
valid_architectures=("DETECT" "WINDOWS" "LINUX" "OSX")
build_architecture="DETECT"
# --option <OPTION>, -o
valid_options=("LBT=[ON|OFF]" "HAS_VTK=[ON|OFF]" "HAS_GDL=[ON|OFF]" "HAS_PYTHON=[ON|OFF]" "HAS_PLPLOT=[ON|OFF]" "HAS_PGPLOT=[ON|OFF]" "HAS_DPPGPLOT=[ON|OFF]" "HAS_PG2PLPLOT=[ON|OFF]")
custom_options=""
# --qt-path <PATH>, -q
qt_path=""
# --help, -h
function helpConfigure {
echo "Usage: configure [OPTIONS]..."
echo "Configures cmake to build the current project."
echo
echo "Mandatory arguments to long options are mandatory for short options too."
printf " %-32s %s\n" "-b, --build-dir <BUILD_DIR>" "Set build directory for cmake."
printf " %-32s %s\n" "-i, --install-dir <INSTALL_DIR>" "Set install directory for cmake."
printf " %-32s %s\n" "-l, --linked, --shared" "Use dynamic libraries."
printf " %-32s %s\n" "-s, --static" "Use as much static libraries as possible."
printf " %-32s %s\n" "-a, --architecture <ARCH>" "Select architecture to compile for [UNUSED]."
printf " %32s " ""
printf "%s, " "${valid_architectures[@]}"
printf "\n"
printf " %-32s %s\n" "-o, --option <OPTION=[ON|OFF]>" "Enable a compiler option."
printf " %32s " ""
printf "%s, " "${valid_options[@]}"
printf "\n"
printf " %-32s %s\n" "-h, --help" "Show this help manual."
printf " %-32s %s\n" "-q, --qt-path <QT_PATH>" "Select the Qt install directory."
}
### PARSING COMMAND LINE ARGUMENTS
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-b|--build-dir)
build_destination="$2"
shift
shift
;;
-i|--install-dir)
install_destination="$build_destination/$2"
shift
shift
;;
-l|--linked|--shared)
shared_build=true
shift
;;
-s|--static)
shared_build=false
shift
;;
-a|--architecture)
architecture="$2"
if [[ ! ${valid_architectures[$architecture]} ]]; then
echo "Invalid architecture: $architecture".
echo "Available options are: "
printf '%s, ' "${valid_architectures[@]}"
echo
exit 1
fi
build_architecture="$architecture"
shift
shift
;;
-o|--option)
custom_option="$2"
if [[ ! ${valid_options[$option]} ]]; then
echo "Invalid option: $custom_option".
echo "Available options are: "
printf '%s, ' "${valid_option[@]}"
echo
exit 1
fi
custom_options+="$custom_option "
shift
shift
;;
-q|--qt-path)
qt_path="$2"
shift
shift
;;
-h|--help)
helpConfigure
exit 0
;;
\?)
echo "ERROR: Invalid parameter: $key"
exit 1
;;
esac
done
if [ "$build_architecture" == "DETECT" ]; then
echo "Autodetecting operating system..."
os=$(uname)
case "$os" in
"Darwin")
build_architecture="OSX"
;;
"Linux")
build_architecture="Linux"
;;
CYGWIN*|MINGW*)
build_architecture="Windows"
;;
*)
echo "ERROR: unknown OS type $os. Exiting..."
exit 1
;;
esac
echo
fi
### OUTPUT
echo "Source location: $source_destination"
echo "Build location: $build_destination"
echo "Install location: $install_destination"
if [ "$shared_build" = true ]; then
echo "Build type: SHARED"
else
echo "Build type: STATIC"
fi
echo "Architecture: $build_architecture"
echo "Custom options: $custom_options"
### CONFIG FILE OUTPUT
config_file="$source_destination/config"
echo "source_location=$source_destination" > config_file
echo "build_destination=$build_destination" >> config_file
echo "install_destination=$install_destination" >> config_file
if [ "$shared_build" = true ]; then
echo "build_type=SHARED" >> config_file
else
echo "build_type=STATIC" >> config_file
fi
echo "build_architecture=$build_architecture" >> config_file
echo "custom_options=$custom_options" >> config_file
### CMAKE CONFIGURATION
echo
echo
if [ ! -z "$custom_options" ]; then
options=$(printf '%s %s ' '-D' "${custom_options[@]}")
fi
options+=" -D BUILD_SHARED_LIBS="
if [ "$shared_build" = true ]; then
options+="ON"
else
options+="OFF"
fi
if [ "$qt_path" ]; then
options+=" -D QT_PATH='$qt_path'"
fi
if ! cmake -DCMAKE_INSTALL_PREFIX="$install_destination" -S "$source_destination" -B "$build_destination" $options; then
echo
echo
echo "Failed to configure QFitsView."
echo
exit 1
fi
echo
echo
### FINAL INFORMATION
echo "QFitsView was successfully configured."
echo
echo "Run 'cmake --build . --parallel' to build QFitsView."
echo "After that, run 'cmake --install .' to install QFitsView to the installation directory."
echo
|