2012-12-13 03:37:20 +08:00
#! /bin/sh
# Build and Test HDF5 using cmake.
# Author: Allen Byrne
# Albert Cheng
# Creation Date: Nov 2012
2014-01-02 02:31:36 +08:00
# Modified:
# Changed to use the quick steps described in INSTALL_CMake.txt. (AKC 2014/1/1)
2012-12-13 03:37:20 +08:00
2014-01-02 02:31:36 +08:00
# Copyright: The HDF Group, 2012-14
2012-12-13 03:37:20 +08:00
2014-01-02 02:31:36 +08:00
# Debug Print: remove the comment hash if you want DPRINT to do echo
2012-12-13 03:37:20 +08:00
DPRINT=:
#DPRINT=echo
2014-01-08 03:31:02 +08:00
# use the ctest scripting method if --script is given
if [ "$1" != "--script" ]; then
2014-01-02 02:31:36 +08:00
# variable names
# The "extra" number is the step number and easier to see all logfiles in
# the sorted order of steps
progname=`basename $0` # program name
configlog="#${progname}_1config.log"
makelog="#${progname}_2build.log"
testlog="#${progname}_3test.log"
packlog="#${progname}_4pack.log"
installlog="#${progname}_5install.log"
exit_code=0
2014-12-10 08:51:29 +08:00
# This command should be in the source directory's bin/
# and should have invoked as "$srcdir/bin/$progname" or
# "bin/$progname". So, by striping bin/$program from $0,
# we can find $srcdir.
if [ $0 == bin/$progname ]; then
srcdir="." # current directory
else
# $0 is $srdir/bin/$progname
srcdir=`echo $0 | sed -e s%/bin/$progname\$%%`
fi
# Sanity check
if [ ! -r $srcdir/bin/$progname ]; then
echo "encountered error while trying to find srcdir($srdir)"
exit 1
fi
2014-10-09 20:42:21 +08:00
# Cmake build options
2014-12-10 08:51:29 +08:00
cacheinit=$srcdir/config/cmake/cacheinit.cmake
2014-12-10 06:03:39 +08:00
build_cpp_lib=-DHDF5_BUILD_CPP_LIB:BOOL=OFF # C++ interface default off
build_fortran=-DHDF5_BUILD_FORTRAN:BOOL=OFF # Fortran interface default off
2014-10-09 20:42:21 +08:00
build_hl_lib=-DHDF5_BUILD_HL_LIB:BOOL=ON # High Level interface default on
build_testing=-DBUILD_TESTING:BOOL=ON # Build tests default on
build_tools=-DHDF5_BUILD_TOOLS:BOOL=ON # Build tools default on
2014-01-02 02:31:36 +08:00
#=============
# Function definitions
#=============
2014-12-10 06:03:39 +08:00
# Show user brief help page
HELP_BRIEF()
{
cat << EOF
Usage: $progname [options]
--help: shows details help page
EOF
}
# Show user detail help page
2014-01-02 02:31:36 +08:00
HELP()
{
2014-12-10 06:03:39 +08:00
cat << EOF
Usage: $progname [<options>]
where options are:
--enable-fortran | --disable-fortran:
enable or disable fortran API. Default is off.
--enable-cxx | --disable-cxx:
enable or disable c++ API. Default is off.
--enable-hl | --disable-hl:
enable or disable high level API. Default is on.
--enable-tools | --disable-tools:
enable or disable building tools. Default is on.
--enable-testing | --disable-testing:
enable or disable building tests. Default is on.
--help: shows details help page
EOF
2014-01-02 02:31:36 +08:00
}
# Display a time stamp
TIMESTAMP()
{
echo "=====" "`date`" "====="
}
# Do one step bracketed with time stamps
# The '< /dev/null' is needed to prevent some applications like MPI
# jobs blocked for reading when they read stdin unnecessary.
# $1 is banner message to be displayed.
# $2 is command to run
# $3 is logfile name for saving output from the command
STEP()
{
banner="$1"
command="$2"
logfile="$3"
echo "$banner" with output saved in $logfile
(TIMESTAMP; nerror=0 ;
echo "eval $command"
eval $command || nerror=1 ;
TIMESTAMP; exit $nerror) < /dev/null >> "$logfile" 2>&1
if [ $? -ne 0 ]; then
echo "error in '$banner'. $progname aborted."
exit 1
fi
}
#==========
# main
#==========
# Show a start time stamp
TIMESTAMP
2014-12-10 06:03:39 +08:00
# Parse Cmake configure options
# --enable-XXX or --disable-XXX will enable or disable feature XXX.
# XXX can be:
# fortran Fortran interface
# cxx C++ interface
# hl Highlevel interface
# testing Build tests
# tools Build tools
while [ $# -gt 0 ]; do
case "$1" in
--enable-fortran)
build_fortran=-DHDF5_BUILD_FORTRAN:BOOL=ON
;;
--disable-fortran)
build_fortran=-DHDF5_BUILD_FORTRAN:BOOL=OFF
;;
--enable-cxx)
build_cpp_lib=-DHDF5_BUILD_CPP_LIB:BOOL=ON
;;
--disable-cxx)
build_cpp_lib=-DHDF5_BUILD_CPP_LIB:BOOL=OFF
;;
--enable-hl)
build_hl_lib=-DHDF5_BUILD_HL_LIB:BOOL=ON
;;
--disable-hl)
build_hl_lib=-DHDF5_BUILD_HL_LIB:BOOL=OFF
;;
--enable-tools)
build_tools=-DHDF5_BUILD_TOOLS:BOOL=ON
;;
--disable-tools)
build_tools=-DHDF5_BUILD_TOOLS:BOOL=OFF
;;
--enable-testing)
build_testing=-DBUILD_TESTING:BOOL=ON
;;
--disable-testing)
build_testing=-DBUILD_TESTING:BOOL=OFF
;;
--help)
# print the detail help page and exit
HELP
exit 0
;;
*)
echo "Unknown options"
HELP
;;
esac
shift
done
# Always display the brief help page
HELP_BRIEF
2014-01-02 02:31:36 +08:00
# Verify there is a valid hdf5 source directory present
if [ ! -d $srcdir ]; then
echo $srcdir not found. Aborted.
exit 1
fi
# figure out version information
vers=bin/h5vers
if [ ! -x $srcdir/$vers ]; then
echo $srcdir/$vers not found or not executable. Aborted.
exit 1
fi
version=`cd $srcdir; $vers`
if [ $? != 0 ]; then
echo $vers failed. Aborted.
exit 1
fi
echo Running Cmake for HDF5-${version} ...
# 4. Configure the C library, tools and tests with this command:
2014-10-09 20:42:21 +08:00
STEP "Configure..." "cmake \
$build_cpp_lib \
$build_fortran \
$build_hl_lib \
$build_testing \
$build_tools \
2014-12-10 08:51:29 +08:00
$srcdir" $configlog
2014-01-02 02:31:36 +08:00
2014-04-03 02:35:01 +08:00
# 5. Build the C library, tools and tests with this command:
2014-01-02 02:31:36 +08:00
STEP "Build the library, tools and tests, ..." "cmake --build . --config Release" $makelog
2014-04-03 02:35:01 +08:00
# 6. Test the C library and tools with this command:
2014-01-02 02:31:36 +08:00
STEP "Test the library and tools..." "ctest . -C Release" $testlog
2014-04-03 02:35:01 +08:00
# 7. Create an install image with this command:
2014-01-02 02:31:36 +08:00
STEP "Create an install image..." "cpack -C Release CPackConfig.cmake" $packlog
2014-04-03 02:35:01 +08:00
# 8. Install with this command:
2014-01-02 02:31:36 +08:00
STEP "Install..." "./HDF5-${version}-Linux.sh --skip-license" $installlog
# save the last exit code
exit_code=$?
# Show a closing time stamp
TIMESTAMP
exit $exit_code
else
# ---------------
# older version
# ---------------
2012-12-13 03:37:20 +08:00
# variable names
progname=`basename $0` # program name
cminfile="cmakemin.$$" # Cmake minimum file
cfgfile=$progname.$$ # configure file
2013-10-03 05:38:25 +08:00
ctest_log=ctest.log # output of ctest script
install_log=install.log # output of installation
2012-12-13 03:37:20 +08:00
$DPRINT $cfgfile
# Remove temporary generated files if exit 0
trap "rm -f $cminfile $cfgfile" 0
2013-01-24 07:22:39 +08:00
#=============
# Function definitions
#=============
TIMESTAMP()
{
echo "=====" "`date`" "====="
}
2012-12-13 03:37:20 +08:00
#==========
# main
#==========
2013-01-24 07:22:39 +08:00
# Show a start time stamp
TIMESTAMP
# Explain what and where log files are.
cat <<EOF
2013-10-03 05:38:25 +08:00
$ctest_log: output of ctest script.
$install_log: output of installation
2013-01-24 07:22:39 +08:00
Log files will be stored in Testing/Temporary:
LastConfigure_<timestamp>.log: output of configure
LastBuild_<timestamp>.log: output of build
LastTest_<timestamp>.log: output of testing
LastTestsFailed_<timestamp>.log: list of failed tests
EOF
2012-12-13 03:37:20 +08:00
# First generate the two needed input files, the $cimnfile and $cfgfile.
# Then use ctest to use the two input files.
#==========
# create the configure file
#==========
# Create the cmake minimum required file to be used by the following
# configure file. Though not absolute needed, it is better to generate
# this file before the configure file. Quote the EOF to preven substitution
# in the text.
#==========
#==========
cat > $cfgfile <<'EOF'
2015-02-19 00:56:22 +08:00
cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR)
2012-12-13 03:37:20 +08:00
########################################################
# This dashboard is maintained by The HDF Group
# For any comments please contact cdashhelp@hdfgroup.org
#
########################################################
set (CTEST_DASHBOARD_ROOT ${CTEST_SCRIPT_DIRECTORY})
set (CTEST_SOURCE_DIRECTORY "../hdf5")
set (CTEST_BINARY_DIRECTORY ".")
set (CTEST_CMAKE_GENERATOR "Unix Makefiles")
set (CTEST_BUILD_CONFIGURATION "Release")
2013-03-26 03:22:10 +08:00
set (CTEST_MAX_N 8)
2012-12-13 03:37:20 +08:00
# -- CDash variables
2013-01-24 07:22:39 +08:00
set (LOCAL_NO_SUBMIT TRUE) # No CDash submit.
2012-12-13 03:37:20 +08:00
set (MODEL "Experimental")
set (CDASH_LOCAL TRUE)
2013-08-14 01:50:56 +08:00
set (SITE_BUILDNAME_SUFFIX "cmakehdf5")
2012-12-13 03:37:20 +08:00
# -- URL set for internal check, default is to not update
set (LOCAL_SKIP_UPDATE TRUE)
2014-10-28 02:30:50 +08:00
set (REPOSITORY_URL "http://svn.${hdfgroup_url}/hdf5/branches/hdf5_1_8")
2012-12-13 03:37:20 +08:00
# -- Standard build options
2014-04-03 02:35:01 +08:00
set (ADD_BUILD_OPTIONS "-DCMAKE_INSTALL_PREFIX:PATH=${CTEST_BINARY_DIRECTORY} -DHDF5_ALLOW_EXTERNAL_SUPPORT:STRING=\"SVN\" -DHDF5_PACKAGE_EXTLIBS:BOOL=ON")
2012-12-13 03:37:20 +08:00
2013-01-04 05:44:43 +08:00
# Use multiple CPU cores to build
2013-02-19 04:56:21 +08:00
include(ProcessorCount)
ProcessorCount(N)
if(NOT N EQUAL 0)
2013-03-26 03:22:10 +08:00
if(N GREATER ${CTEST_MAX_N})
set(N ${CTEST_MAX_N})
endif(N GREATER ${CTEST_MAX_N})
2013-02-19 04:56:21 +08:00
set(CTEST_BUILD_FLAGS -j${N})
set(ctest_test_args ${ctest_test_args} PARALLEL_LEVEL ${N})
endif()
2013-01-04 05:44:43 +08:00
2012-12-13 03:37:20 +08:00
# -----------------------------------------------------------
# -- Get environment
# -----------------------------------------------------------
## -- set hostname
## --------------------------
find_program (HOSTNAME_CMD NAMES hostname)
exec_program (${HOSTNAME_CMD} ARGS OUTPUT_VARIABLE HOSTNAME)
set (CTEST_SITE "${HOSTNAME}${CTEST_SITE_EXT}")
find_program (UNAME NAMES uname)
macro (getuname name flag)
exec_program ("${UNAME}" ARGS "${flag}" OUTPUT_VARIABLE "${name}")
endmacro (getuname)
getuname (osname -s)
getuname (osrel -r)
getuname (cpu -m)
if (SITE_BUILDNAME_SUFFIX)
2012-12-20 23:39:37 +08:00
set (CTEST_BUILD_NAME "${osname}-${osrel}-${cpu}-${SITE_BUILDNAME_SUFFIX}")
2012-12-13 03:37:20 +08:00
else (SITE_BUILDNAME_SUFFIX)
2012-12-20 23:39:37 +08:00
set (CTEST_BUILD_NAME "${osname}-${osrel}-${cpu}")
2012-12-13 03:37:20 +08:00
endif (SITE_BUILDNAME_SUFFIX)
# -----------------------------------------------------------
set (BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DSITE:STRING=${CTEST_SITE} -DBUILDNAME:STRING=${CTEST_BUILD_NAME}")
2013-01-03 01:01:06 +08:00
#-----------------------------------------------------------------------------
# MAC machines need special option
#-----------------------------------------------------------------------------
if (APPLE)
2013-01-04 05:44:43 +08:00
# Compiler choice
execute_process(COMMAND xcrun --find cc OUTPUT_VARIABLE XCODE_CC OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND xcrun --find c++ OUTPUT_VARIABLE XCODE_CXX OUTPUT_STRIP_TRAILING_WHITESPACE)
SET(ENV{CC} "${XCODE_CC}")
SET(ENV{CXX} "${XCODE_CXX}")
# Shared fortran is not supported, build static
set (BUILD_OPTIONS "${BUILD_OPTIONS} -DBUILD_SHARED_LIBS:BOOL=OFF -DCMAKE_ANSI_CFLAGS:STRING=-fPIC")
2013-01-03 01:01:06 +08:00
set (BUILD_OPTIONS "${BUILD_OPTIONS} -DCTEST_USE_LAUNCHERS:BOOL=ON -DCMAKE_BUILD_WITH_INSTALL_RPATH:BOOL=OFF")
endif (APPLE)
2012-12-13 03:37:20 +08:00
# -----------------------------------------------------------
find_package (Subversion)
2013-01-03 02:12:29 +08:00
set (CTEST_UPDATE_COMMAND "${Subversion_SVN_EXECUTABLE}")
2012-12-13 03:37:20 +08:00
# -- Only clean build folder if LOCAL_CLEAR_BUILD is set
if (LOCAL_CLEAR_BUILD)
set (CTEST_START_WITH_EMPTY_BINARY_DIRECTORY TRUE)
ctest_empty_binary_directory (${CTEST_BINARY_DIRECTORY})
endif (LOCAL_CLEAR_BUILD)
#-----------------------------------------------------------------------------
# Send the main script as a note.
list (APPEND CTEST_NOTES_FILES
"${CMAKE_CURRENT_LIST_FILE}"
"${CTEST_SOURCE_DIRECTORY}/config/cmake/cacheinit.cmake"
)
# Check for required variables.
foreach (req
CTEST_CMAKE_GENERATOR
CTEST_SITE
CTEST_BUILD_NAME
)
if (NOT DEFINED ${req})
message(FATAL_ERROR "The containing script must set ${req}")
endif (NOT DEFINED ${req})
endforeach (req)
2013-01-03 02:12:29 +08:00
## -- set output to english
set($ENV{LC_MESSAGES} "en_EN")
#-----------------------------------------------------------------------------
# Initialize the CTEST commands
#------------------------------
2014-03-12 05:14:57 +08:00
set (CTEST_CMAKE_COMMAND "\"${CMAKE_COMMAND}\"")
set (CTEST_CONFIGURE_COMMAND
2013-01-03 02:12:29 +08:00
"${CTEST_CMAKE_COMMAND} -C \"${CTEST_SOURCE_DIRECTORY}/config/cmake/cacheinit.cmake\" -DCMAKE_BUILD_TYPE:STRING=${CTEST_BUILD_CONFIGURATION} ${BUILD_OPTIONS} \"-G${CTEST_CMAKE_GENERATOR}\" \"${CTEST_SOURCE_DIRECTORY}\"")
2012-12-13 03:37:20 +08:00
# Print summary information.
foreach (v
CTEST_SITE
CTEST_BUILD_NAME
CTEST_SOURCE_DIRECTORY
CTEST_BINARY_DIRECTORY
CTEST_CMAKE_GENERATOR
CTEST_BUILD_CONFIGURATION
CTEST_CONFIGURE_COMMAND
CTEST_SCRIPT_DIRECTORY
)
set (vars "${vars} ${v}=[${${v}}]\n")
endforeach (v)
message ("Dashboard script configuration:\n${vars}\n")
2013-01-03 02:12:29 +08:00
CTEST_START (${MODEL} TRACK ${MODEL})
2012-12-13 03:37:20 +08:00
if (NOT LOCAL_SKIP_UPDATE)
CTEST_UPDATE (SOURCE "${CTEST_SOURCE_DIRECTORY}")
endif (NOT LOCAL_SKIP_UPDATE)
2013-03-26 03:22:10 +08:00
CTEST_CONFIGURE (BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res)
if(NOT res STREQUAL "0")
message (FATAL_ERROR "Configure FAILED")
endif()
2013-01-04 05:44:43 +08:00
message ("Configure DONE")
2012-12-13 03:37:20 +08:00
CTEST_READ_CUSTOM_FILES ("${CTEST_BINARY_DIRECTORY}")
if (NOT LOCAL_NO_SUBMIT)
CTEST_SUBMIT (PARTS Update Configure Notes)
endif (NOT LOCAL_NO_SUBMIT)
2013-03-26 03:22:10 +08:00
CTEST_BUILD (BUILD "${CTEST_BINARY_DIRECTORY}" APPEND RETURN_VALUE res)
2012-12-13 03:37:20 +08:00
if (NOT LOCAL_NO_SUBMIT)
CTEST_SUBMIT (PARTS Build)
endif (NOT LOCAL_NO_SUBMIT)
2013-03-26 03:22:10 +08:00
if(NOT res STREQUAL "0")
message (FATAL_ERROR "Build FAILED")
endif()
2013-01-04 05:44:43 +08:00
message ("build DONE")
2012-12-13 03:37:20 +08:00
if (NOT LOCAL_SKIP_TEST)
2013-03-26 03:22:10 +08:00
CTEST_TEST (BUILD "${CTEST_BINARY_DIRECTORY}" APPEND ${ctest_test_args} RETURN_VALUE res)
2012-12-13 03:37:20 +08:00
if (NOT LOCAL_NO_SUBMIT)
CTEST_SUBMIT (PARTS Test)
endif (NOT LOCAL_NO_SUBMIT)
2013-03-26 03:22:10 +08:00
if(NOT res STREQUAL "0")
message (FATAL_ERROR "Test FAILED")
endif()
2013-01-04 05:44:43 +08:00
message ("test DONE")
2012-12-13 03:37:20 +08:00
endif (NOT LOCAL_SKIP_TEST)
2013-10-03 04:42:58 +08:00
if(NOT LOCAL_MEMCHECK_TEST)
##-----------------------------------------------
## Package the product
##-----------------------------------------------
execute_process(COMMAND cpack -C ${CTEST_BUILD_CONFIGURATION} -V
WORKING_DIRECTORY ${CTEST_BINARY_DIRECTORY}
RESULT_VARIABLE cpackResult
OUTPUT_VARIABLE cpackLog
ERROR_VARIABLE cpackLog.err
)
file(WRITE ${CTEST_BINARY_DIRECTORY}/cpack.log "${cpackLog.err}" "${cpackLog}")
endif(NOT LOCAL_MEMCHECK_TEST)
#-----------------------------------------------------------------------------
2012-12-13 03:37:20 +08:00
message ("DONE")
EOF
# Run ctest
2013-10-03 05:38:25 +08:00
ctest -S $cfgfile -C Release -V -O $ctest_log
exit_code=$?
if [ $exit_code = 0 ]; then
echo CTest script completed without error
else
echo Error encountered CTest script
fi
2013-10-03 05:51:01 +08:00
# Using HDF5-*.sh because actual name is unavailable
install_sh=HDF5-*.sh
echo installing with $install_sh ...
./$install_sh --skip-license > $install_log
2012-12-28 05:04:50 +08:00
exit_code=$?
if [ $exit_code = 0 ]; then
echo Complete without error
else
2013-01-03 01:01:06 +08:00
echo Error encountered
2012-12-28 05:04:50 +08:00
fi
2013-01-24 07:22:39 +08:00
TIMESTAMP
2012-12-28 05:04:50 +08:00
exit $exit_code
2014-01-02 02:31:36 +08:00
fi