| 1 |
#! /bin/sh |
| 2 |
# Build and Test HDF4 using cmake. |
| 3 |
# Author: Allen Byrne |
| 4 |
# Albert Cheng |
| 5 |
# Creation Date: Nov 2012 |
| 6 |
# Modified: |
| 7 |
# Changed to use the quick steps described in INSTALL_CMake.txt. (AKC 2014/1/7) |
| 8 |
|
| 9 |
# Copyright: The HDF Group, 2012-14 |
| 10 |
|
| 11 |
# Debug Print: remove the comment hash if you want DPRINT to do echo |
| 12 |
DPRINT=: |
| 13 |
#DPRINT=echo |
| 14 |
|
| 15 |
# use the ctest scripting method if --script is given |
| 16 |
if [ "$1" != "--script" ]; then |
| 17 |
# variable names |
| 18 |
# The "extra" number is the step number and easier to see all logfiles in |
| 19 |
# the sorted order of steps |
| 20 |
progname=`basename $0` # program name |
| 21 |
configlog="#${progname}_1config.log" |
| 22 |
makelog="#${progname}_2build.log" |
| 23 |
testlog="#${progname}_3test.log" |
| 24 |
packlog="#${progname}_4pack.log" |
| 25 |
installlog="#${progname}_5install.log" |
| 26 |
exit_code=0 |
| 27 |
|
| 28 |
# This command should be in the source directory's bin/ |
| 29 |
# and should have invoked as "$srcdir/bin/$progname" or |
| 30 |
# "bin/$progname". So, by striping bin/$program from $0, |
| 31 |
# we can find $srcdir. |
| 32 |
if [ $0 == bin/$progname ]; then |
| 33 |
srcdir="." # current directory |
| 34 |
else |
| 35 |
# $0 is $srdir/bin/$progname |
| 36 |
srcdir=`echo $0 | sed -e s%/bin/$progname\$%%` |
| 37 |
fi |
| 38 |
# Sanity check |
| 39 |
if [ ! -r $srcdir/bin/$progname ]; then |
| 40 |
echo "encountered error while trying to find srcdir($srdir)" |
| 41 |
exit 1 |
| 42 |
fi |
| 43 |
|
| 44 |
#============= |
| 45 |
# Function definitions |
| 46 |
#============= |
| 47 |
|
| 48 |
# Show user help page |
| 49 |
HELP() |
| 50 |
{ |
| 51 |
echo "Usage: $progname [--script]" |
| 52 |
echo " --script: Use the ctest scripting method of $progname" |
| 53 |
echo "" |
| 54 |
} |
| 55 |
|
| 56 |
# Display a time stamp |
| 57 |
TIMESTAMP() |
| 58 |
{ |
| 59 |
echo "=====" "`date`" "=====" |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
# Do one step bracketed with time stamps |
| 64 |
# The '< /dev/null' is needed to prevent some applications like MPI |
| 65 |
# jobs blocked for reading when they read stdin unnecessary. |
| 66 |
# $1 is banner message to be displayed. |
| 67 |
# $2 is command to run |
| 68 |
# $3 is logfile name for saving output from the command |
| 69 |
STEP() |
| 70 |
{ |
| 71 |
banner="$1" |
| 72 |
command="$2" |
| 73 |
logfile="$3" |
| 74 |
|
| 75 |
echo "$banner" with output saved in $logfile |
| 76 |
(TIMESTAMP; nerror=0 ; |
| 77 |
echo "eval $command" |
| 78 |
eval $command || nerror=1 ; |
| 79 |
TIMESTAMP; exit $nerror) < /dev/null >> "$logfile" 2>&1 |
| 80 |
if [ $? -ne 0 ]; then |
| 81 |
echo "error in '$banner'. $progname aborted." |
| 82 |
exit 1 |
| 83 |
fi |
| 84 |
} |
| 85 |
|
| 86 |
|
| 87 |
#========== |
| 88 |
# main |
| 89 |
#========== |
| 90 |
|
| 91 |
# Show a start time stamp/hdf4 |
| 92 |
TIMESTAMP |
| 93 |
|
| 94 |
# Always display the help page |
| 95 |
HELP |
| 96 |
|
| 97 |
# Verify there is a valid hdf4 source directory present |
| 98 |
if [ ! -d $srcdir ]; then |
| 99 |
echo $srcdir not found. Aborted. |
| 100 |
exit 1 |
| 101 |
fi |
| 102 |
|
| 103 |
# figure out version information |
| 104 |
vers=bin/h4vers |
| 105 |
if [ ! -x $srcdir/$vers ]; then |
| 106 |
echo $srcdir/$vers not found or not executable. Aborted. |
| 107 |
exit 1 |
| 108 |
fi |
| 109 |
version=`cd $srcdir; $vers` |
| 110 |
if [ $? != 0 ]; then |
| 111 |
echo $vers failed. Aborted. |
| 112 |
exit 1 |
| 113 |
fi |
| 114 |
echo Running Cmake for HDF4-${version} ... |
| 115 |
|
| 116 |
# 4. Configure the C library, tools and tests with this command: |
| 117 |
STEP "Configure..." "cmake -C $srcdir/config/cmake/cacheinit.cmake -G 'Unix Makefiles' -DCMAKE_INSTALL_PREFIX:PATH="$PWD" -DHDF4_ALLOW_EXTERNAL_SUPPORT:STRING="" -DHDF4_PACKAGE_EXTLIBS:BOOL=OFF -DHDF4_BUILD_TOOLS:BOOL=ON -DHDF4_BUILD_UTILS:BOOL=ON -DBUILD_TESTING:BOOL=ON $srcdir" $configlog |
| 118 |
|
| 119 |
# 5. Build the C library, tools and tests with this command: |
| 120 |
STEP "Build the library, tools and tests, ..." "cmake --build . --config Release" $makelog |
| 121 |
|
| 122 |
# 6. Test the C library and tools with this command: |
| 123 |
STEP "Test the library and tools..." "ctest . -C Release" $testlog |
| 124 |
|
| 125 |
# 7. Create an install image with this command: |
| 126 |
STEP "Create an install image..." "cpack -C Release CPackConfig.cmake" $packlog |
| 127 |
|
| 128 |
# 8. Install with this command: |
| 129 |
STEP "Install..." "./HDF-${version}-Linux.sh --skip-license" $installlog |
| 130 |
# save the last exit code |
| 131 |
exit_code=$? |
| 132 |
|
| 133 |
# Show a closing time stamp |
| 134 |
TIMESTAMP |
| 135 |
exit $exit_code |
| 136 |
|
| 137 |
else |
| 138 |
# --------------- |
| 139 |
# older version |
| 140 |
# --------------- |
| 141 |
|
| 142 |
# variable names |
| 143 |
progname=`basename $0` # program name |
| 144 |
cminfile="cmakemin.$$" # Cmake minimum file |
| 145 |
cfgfile=$progname.$$ # configure file |
| 146 |
ctest_log=ctest.log # output of ctest script |
| 147 |
install_log=install.log # output of installation |
| 148 |
$DPRINT $cfgfile |
| 149 |
|
| 150 |
# Remove temporary generated files if exit 0 |
| 151 |
trap "rm -f $cminfile $cfgfile" 0 |
| 152 |
|
| 153 |
#============= |
| 154 |
# Function definitions |
| 155 |
#============= |
| 156 |
TIMESTAMP() |
| 157 |
{ |
| 158 |
echo "=====" "`date`" "=====" |
| 159 |
} |
| 160 |
|
| 161 |
|
| 162 |
#========== |
| 163 |
# main |
| 164 |
#========== |
| 165 |
# Show a start time stamp |
| 166 |
TIMESTAMP |
| 167 |
|
| 168 |
# Explain what and where log files are. |
| 169 |
cat <<EOF |
| 170 |
$ctest_log: output of ctest script. |
| 171 |
$install_log: output of installation |
| 172 |
Log files will be stored in Testing/Temporary: |
| 173 |
LastConfigure_<timestamp>.log: output of configure |
| 174 |
LastBuild_<timestamp>.log: output of build |
| 175 |
LastTest_<timestamp>.log: output of testing |
| 176 |
LastTestsFailed_<timestamp>.log: list of failed tests |
| 177 |
|
| 178 |
EOF |
| 179 |
|
| 180 |
# First generate the two needed input files, the $cimnfile and $cfgfile. |
| 181 |
# Then use ctest to use the two input files. |
| 182 |
|
| 183 |
#========== |
| 184 |
# create the configure file |
| 185 |
#========== |
| 186 |
# Create the cmake minimum required file to be used by the following |
| 187 |
# configure file. Though not absolute needed, it is better to generate |
| 188 |
# this file before the configure file. Quote the EOF to prevent substitution |
| 189 |
# in the text. |
| 190 |
#========== |
| 191 |
#========== |
| 192 |
cat > $cfgfile <<'EOF' |
| 193 |
cmake_minimum_required(VERSION 3.18) |
| 194 |
######################################################## |
| 195 |
# This dashboard is maintained by The HDF Group |
| 196 |
# For any comments please contact [email protected] |
| 197 |
# |
| 198 |
######################################################## |
| 199 |
|
| 200 |
set (CTEST_DASHBOARD_ROOT ${CTEST_SCRIPT_DIRECTORY}) |
| 201 |
set (CTEST_SOURCE_DIRECTORY "../hdf4") |
| 202 |
set (CTEST_BINARY_DIRECTORY ".") |
| 203 |
set (CTEST_CMAKE_GENERATOR "Unix Makefiles") |
| 204 |
set (CTEST_CONFIGURATION_TYPE "Release") |
| 205 |
set (CTEST_MAX_N 8) |
| 206 |
|
| 207 |
# -- CDash variables |
| 208 |
set (LOCAL_NO_SUBMIT TRUE) # No CDash submit. |
| 209 |
set (MODEL "Experimental") |
| 210 |
set (CDASH_LOCAL TRUE) |
| 211 |
set (SITE_BUILDNAME_SUFFIX "cmakehdf4") |
| 212 |
|
| 213 |
# -- URL set for internal check, default is to not update |
| 214 |
set (LOCAL_SKIP_UPDATE TRUE) |
| 215 |
set (REPOSITORY_URL "https://github.com/HDFGroup/hdf4") |
| 216 |
# -- Standard build options |
| 217 |
set (ADD_BUILD_OPTIONS "-DCMAKE_INSTALL_PREFIX:PATH=${CTEST_BINARY_DIRECTORY} -DHDF4_ALLOW_EXTERNAL_SUPPORT:STRING=\"SVN\" -DHDF4_PACKAGE_EXTLIBS:BOOL=ON") |
| 218 |
|
| 219 |
# Use multiple CPU cores to build |
| 220 |
include(ProcessorCount) |
| 221 |
ProcessorCount(N) |
| 222 |
if(NOT N EQUAL 0) |
| 223 |
if(N GREATER ${CTEST_MAX_N}) |
| 224 |
set(N ${CTEST_MAX_N}) |
| 225 |
endif() |
| 226 |
set(CTEST_BUILD_FLAGS -j${N}) |
| 227 |
set(ctest_test_args ${ctest_test_args} PARALLEL_LEVEL ${N}) |
| 228 |
endif() |
| 229 |
|
| 230 |
# ----------------------------------------------------------- |
| 231 |
# -- Get environment |
| 232 |
# ----------------------------------------------------------- |
| 233 |
## -- set hostname |
| 234 |
## -------------------------- |
| 235 |
find_program (HOSTNAME_CMD NAMES hostname) |
| 236 |
exec_program (${HOSTNAME_CMD} ARGS OUTPUT_VARIABLE HOSTNAME) |
| 237 |
set (CTEST_SITE "${HOSTNAME}${CTEST_SITE_EXT}") |
| 238 |
find_program (UNAME NAMES uname) |
| 239 |
macro (getuname name flag) |
| 240 |
exec_program ("${UNAME}" ARGS "${flag}" OUTPUT_VARIABLE "${name}") |
| 241 |
endmacro (getuname) |
| 242 |
|
| 243 |
getuname (osname -s) |
| 244 |
getuname (osrel -r) |
| 245 |
getuname (cpu -m) |
| 246 |
|
| 247 |
if (SITE_BUILDNAME_SUFFIX) |
| 248 |
set (CTEST_BUILD_NAME "${osname}-${osrel}-${cpu}-${SITE_BUILDNAME_SUFFIX}") |
| 249 |
else () |
| 250 |
set (CTEST_BUILD_NAME "${osname}-${osrel}-${cpu}") |
| 251 |
endif () |
| 252 |
# ----------------------------------------------------------- |
| 253 |
|
| 254 |
set (BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DSITE:STRING=${CTEST_SITE} -DBUILDNAME:STRING=${CTEST_BUILD_NAME}") |
| 255 |
|
| 256 |
#----------------------------------------------------------------------------- |
| 257 |
# MAC machines need special option |
| 258 |
#----------------------------------------------------------------------------- |
| 259 |
if (APPLE) |
| 260 |
# Compiler choice |
| 261 |
execute_process(COMMAND xcrun --find cc OUTPUT_VARIABLE XCODE_CC OUTPUT_STRIP_TRAILING_WHITESPACE) |
| 262 |
SET(ENV{CC} "${XCODE_CC}") |
| 263 |
# Shared fortran is not supported, build static |
| 264 |
set (BUILD_OPTIONS "${BUILD_OPTIONS} -DBUILD_SHARED_LIBS:BOOL=OFF -DBUILD_JPEG_WITH_PIC:BOOL=ON") |
| 265 |
set (BUILD_OPTIONS "${BUILD_OPTIONS} -DCTEST_USE_LAUNCHERS:BOOL=ON -DCMAKE_BUILD_WITH_INSTALL_RPATH:BOOL=OFF") |
| 266 |
endif () |
| 267 |
|
| 268 |
|
| 269 |
# ----------------------------------------------------------- |
| 270 |
find_package (Subversion) |
| 271 |
set (CTEST_UPDATE_COMMAND "${Subversion_SVN_EXECUTABLE}") |
| 272 |
# -- Only clean build folder if LOCAL_CLEAR_BUILD is set |
| 273 |
if (LOCAL_CLEAR_BUILD) |
| 274 |
set (CTEST_START_WITH_EMPTY_BINARY_DIRECTORY TRUE) |
| 275 |
ctest_empty_binary_directory (${CTEST_BINARY_DIRECTORY}) |
| 276 |
endif () |
| 277 |
|
| 278 |
#----------------------------------------------------------------------------- |
| 279 |
# Send the main script as a note. |
| 280 |
list (APPEND CTEST_NOTES_FILES |
| 281 |
"${CMAKE_CURRENT_LIST_FILE}" |
| 282 |
"${CTEST_SOURCE_DIRECTORY}/config/cmake/cacheinit.cmake" |
| 283 |
) |
| 284 |
|
| 285 |
# Check for required variables. |
| 286 |
foreach (req |
| 287 |
CTEST_CMAKE_GENERATOR |
| 288 |
CTEST_SITE |
| 289 |
CTEST_BUILD_NAME |
| 290 |
) |
| 291 |
if (NOT DEFINED ${req}) |
| 292 |
message(FATAL_ERROR "The containing script must set ${req}") |
| 293 |
endif (}) |
| 294 |
endforeach () |
| 295 |
|
| 296 |
## -- set output to english |
| 297 |
set($ENV{LC_MESSAGES} "en_EN") |
| 298 |
|
| 299 |
#----------------------------------------------------------------------------- |
| 300 |
# Initialize the CTEST commands |
| 301 |
#------------------------------ |
| 302 |
set (CTEST_CMAKE_COMMAND "\"${CMAKE_COMMAND}\"") |
| 303 |
set (CTEST_CONFIGURE_COMMAND |
| 304 |
"${CTEST_CMAKE_COMMAND} -C \"${CTEST_SOURCE_DIRECTORY}/config/cmake/cacheinit.cmake\" -DCMAKE_BUILD_TYPE:STRING=${CTEST_CONFIGURATION_TYPE} ${BUILD_OPTIONS} \"-G${CTEST_CMAKE_GENERATOR}\" \"${CTEST_SOURCE_DIRECTORY}\"") |
| 305 |
|
| 306 |
# Print summary information. |
| 307 |
foreach (v |
| 308 |
CTEST_SITE |
| 309 |
CTEST_BUILD_NAME |
| 310 |
CTEST_SOURCE_DIRECTORY |
| 311 |
CTEST_BINARY_DIRECTORY |
| 312 |
CTEST_CMAKE_GENERATOR |
| 313 |
CTEST_CONFIGURATION_TYPE |
| 314 |
CTEST_CONFIGURE_COMMAND |
| 315 |
CTEST_SCRIPT_DIRECTORY |
| 316 |
) |
| 317 |
set (vars "${vars} ${v}=[${${v}}]\n") |
| 318 |
endforeach () |
| 319 |
message ("Dashboard script configuration:\n${vars}\n") |
| 320 |
|
| 321 |
CTEST_START (${MODEL} TRACK ${MODEL}) |
| 322 |
if (NOT LOCAL_SKIP_UPDATE) |
| 323 |
CTEST_UPDATE (SOURCE "${CTEST_SOURCE_DIRECTORY}") |
| 324 |
endif () |
| 325 |
CTEST_CONFIGURE (BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res) |
| 326 |
if(NOT res STREQUAL "0") |
| 327 |
message (FATAL_ERROR "Configure FAILED") |
| 328 |
endif() |
| 329 |
message ("Configure DONE") |
| 330 |
CTEST_READ_CUSTOM_FILES ("${CTEST_BINARY_DIRECTORY}") |
| 331 |
if (NOT LOCAL_NO_SUBMIT) |
| 332 |
CTEST_SUBMIT (PARTS Update Configure Notes) |
| 333 |
endif () |
| 334 |
CTEST_BUILD (BUILD "${CTEST_BINARY_DIRECTORY}" APPEND RETURN_VALUE res) |
| 335 |
if (NOT LOCAL_NO_SUBMIT) |
| 336 |
CTEST_SUBMIT (PARTS Build) |
| 337 |
endif () |
| 338 |
if(NOT res STREQUAL "0") |
| 339 |
message (FATAL_ERROR "Build FAILED") |
| 340 |
endif() |
| 341 |
message ("build DONE") |
| 342 |
if (NOT LOCAL_SKIP_TEST) |
| 343 |
CTEST_TEST (BUILD "${CTEST_BINARY_DIRECTORY}" APPEND ${ctest_test_args} RETURN_VALUE res) |
| 344 |
if (NOT LOCAL_NO_SUBMIT) |
| 345 |
CTEST_SUBMIT (PARTS Test) |
| 346 |
endif () |
| 347 |
if(NOT res STREQUAL "0") |
| 348 |
message (FATAL_ERROR "Test FAILED") |
| 349 |
endif() |
| 350 |
message ("test DONE") |
| 351 |
endif () |
| 352 |
if(NOT LOCAL_MEMCHECK_TEST) |
| 353 |
##----------------------------------------------- |
| 354 |
## Package the product |
| 355 |
##----------------------------------------------- |
| 356 |
execute_process(COMMAND cpack -C ${CTEST_CONFIGURATION_TYPE} -V |
| 357 |
WORKING_DIRECTORY ${CTEST_BINARY_DIRECTORY} |
| 358 |
RESULT_VARIABLE cpackResult |
| 359 |
OUTPUT_VARIABLE cpackLog |
| 360 |
ERROR_VARIABLE cpackLog.err |
| 361 |
) |
| 362 |
file(WRITE ${CTEST_BINARY_DIRECTORY}/cpack.log "${cpackLog.err}" "${cpackLog}") |
| 363 |
endif() |
| 364 |
#----------------------------------------------------------------------------- |
| 365 |
|
| 366 |
message ("DONE") |
| 367 |
EOF |
| 368 |
|
| 369 |
|
| 370 |
# Run ctest |
| 371 |
ctest -S $cfgfile -C Release -V -O $ctest_log |
| 372 |
exit_code=$? |
| 373 |
if [ $exit_code = 0 ]; then |
| 374 |
echo CTest script completed without error |
| 375 |
else |
| 376 |
echo Error encountered CTest script |
| 377 |
fi |
| 378 |
# Using HDF-*.sh because actual name is unavailable |
| 379 |
install_sh=HDF-*.sh |
| 380 |
echo installing with $install_sh ... |
| 381 |
./$install_sh --skip-license > $install_log |
| 382 |
exit_code=$? |
| 383 |
if [ $exit_code = 0 ]; then |
| 384 |
echo Complete without error |
| 385 |
else |
| 386 |
echo Error encountered |
| 387 |
fi |
| 388 |
TIMESTAMP |
| 389 |
exit $exit_code |
| 390 |
|
| 391 |
fi |
| 392 |
|