1#
2# Copyright by The HDF Group.
3# All rights reserved.
4#
5# This file is part of HDF5.  The full HDF5 copyright notice, including
6# terms governing use, modification, and redistribution, is contained in
7# the COPYING file, which can be found at the root of the source code
8# distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases.
9# If you do not have access to either file, you may request a copy from
10# help@hdfgroup.org.
11#
12cmake_minimum_required (VERSION 3.10)
13########################################################
14# For any comments please contact cdashhelp@hdfgroup.org
15#
16########################################################
17# -----------------------------------------------------------
18# -- Get environment
19# -----------------------------------------------------------
20if (NOT SITE_OS_NAME)
21  ## machine name not provided - attempt to discover with uname
22  ## -- set hostname
23  ## --------------------------
24  find_program (HOSTNAME_CMD NAMES hostname)
25  exec_program (${HOSTNAME_CMD} ARGS OUTPUT_VARIABLE HOSTNAME)
26  set (CTEST_SITE  "${HOSTNAME}${CTEST_SITE_EXT}")
27  find_program (UNAME NAMES uname)
28  macro (getuname name flag)
29    exec_program ("${UNAME}" ARGS "${flag}" OUTPUT_VARIABLE "${name}")
30  endmacro ()
31
32  getuname (osname -s)
33  getuname (osrel  -r)
34  getuname (cpu    -m)
35  message (STATUS "Dashboard script uname output: ${osname}-${osrel}-${cpu}\n")
36
37  set (CTEST_BUILD_NAME  "${osname}-${osrel}-${cpu}")
38  if (SITE_BUILDNAME_SUFFIX)
39    set (CTEST_BUILD_NAME  "${SITE_BUILDNAME_SUFFIX}-${CTEST_BUILD_NAME}")
40  endif ()
41  set (BUILD_OPTIONS "${ADD_BUILD_OPTIONS}")
42else ()
43  ## machine name provided
44  ## --------------------------
45  if (CMAKE_HOST_UNIX)
46    set(CTEST_BUILD_NAME "${SITE_OS_NAME}-${SITE_OS_VERSION}-${SITE_OS_BITS}-${SITE_COMPILER_NAME}-${SITE_COMPILER_VERSION}")
47  else ()
48    set(CTEST_BUILD_NAME "${SITE_OS_NAME}-${SITE_OS_VERSION}-${SITE_COMPILER_NAME}")
49  endif ()
50  if (SITE_BUILDNAME_SUFFIX)
51    set(CTEST_BUILD_NAME "${CTEST_BUILD_NAME}-${SITE_BUILDNAME_SUFFIX}")
52  endif ()
53  set (BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DSITE:STRING=${CTEST_SITE} -DBUILDNAME:STRING=${CTEST_BUILD_NAME}")
54endif ()
55
56#-----------------------------------------------------------------------------
57# MAC machines need special option
58#-----------------------------------------------------------------------------
59if (APPLE)
60  # Compiler choice
61  execute_process (COMMAND xcrun --find cc OUTPUT_VARIABLE XCODE_CC OUTPUT_STRIP_TRAILING_WHITESPACE)
62  execute_process (COMMAND xcrun --find c++ OUTPUT_VARIABLE XCODE_CXX OUTPUT_STRIP_TRAILING_WHITESPACE)
63  set (ENV{CC} "${XCODE_CC}")
64  set (ENV{CXX} "${XCODE_CXX}")
65
66  set (BUILD_OPTIONS "${BUILD_OPTIONS} -DCTEST_USE_LAUNCHERS:BOOL=ON -DCMAKE_BUILD_WITH_INSTALL_RPATH:BOOL=OFF")
67endif ()
68
69#-----------------------------------------------------------------------------
70set (NEED_REPOSITORY_CHECKOUT 0)
71set (CTEST_CMAKE_COMMAND "\"${CMAKE_COMMAND}\"")
72if (CTEST_USE_TAR_SOURCE)
73  ## Uncompress source if tar or zip file provided
74  ## --------------------------
75  if (WIN32)
76    message (STATUS "extracting... [${CMAKE_EXECUTABLE_NAME} -E tar -xvf ${CTEST_DASHBOARD_ROOT}\\${CTEST_USE_TAR_SOURCE}.zip]")
77    execute_process (COMMAND ${CMAKE_EXECUTABLE_NAME} -E tar -xvf ${CTEST_DASHBOARD_ROOT}\\${CTEST_USE_TAR_SOURCE}.zip RESULT_VARIABLE rv)
78  else ()
79    message (STATUS "extracting... [${CMAKE_EXECUTABLE_NAME} -E tar -xvf ${CTEST_DASHBOARD_ROOT}/${CTEST_USE_TAR_SOURCE}.tar]")
80    execute_process (COMMAND ${CMAKE_EXECUTABLE_NAME} -E tar -xvf ${CTEST_DASHBOARD_ROOT}/${CTEST_USE_TAR_SOURCE}.tar RESULT_VARIABLE rv)
81  endif ()
82
83  if (NOT rv EQUAL 0)
84    message (STATUS "extracting... [error-(${rv}) clean up]")
85    file (REMOVE_RECURSE "${CTEST_SOURCE_DIRECTORY}")
86    message (FATAL_ERROR "error: extract of ${CTEST_USE_TAR_SOURCE} failed")
87  endif ()
88endif ()
89
90#-----------------------------------------------------------------------------
91## Clear the build directory
92## --------------------------
93set (CTEST_START_WITH_EMPTY_BINARY_DIRECTORY TRUE)
94if (EXISTS "${CTEST_BINARY_DIRECTORY}" AND IS_DIRECTORY "${CTEST_BINARY_DIRECTORY}")
95  ctest_empty_binary_directory (${CTEST_BINARY_DIRECTORY})
96else ()
97  file (MAKE_DIRECTORY "${CTEST_BINARY_DIRECTORY}")
98endif ()
99
100# Use multiple CPU cores to build
101include (ProcessorCount)
102ProcessorCount (N)
103if (NOT N EQUAL 0)
104  if (NOT WIN32)
105    set (CTEST_BUILD_FLAGS -j${N})
106  endif ()
107  set (ctest_test_args ${ctest_test_args} PARALLEL_LEVEL ${N})
108endif ()
109
110#-----------------------------------------------------------------------------
111# Initialize the CTEST commands
112#------------------------------
113set(CTEST_CONFIGURE_TOOLSET  "")
114if(CMAKE_GENERATOR_TOOLSET)
115  set(CTEST_CONFIGURE_TOOLSET  "-T${CMAKE_GENERATOR_TOOLSET}")
116endif()
117set (CTEST_CONFIGURE_COMMAND
118    "${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_CONFIGURE_TOOLSET}\" \"${CTEST_SOURCE_DIRECTORY}\""
119)
120#-----------------------------------------------------------------------------
121
122#-----------------------------------------------------------------------------
123## -- set output to english
124set ($ENV{LC_MESSAGES}  "en_EN")
125
126#-----------------------------------------------------------------------------
127  configure_file(${CTEST_SOURCE_DIRECTORY}/config/cmake/CTestCustom.cmake ${CTEST_BINARY_DIRECTORY}/CTestCustom.cmake)
128  ctest_read_custom_files ("${CTEST_BINARY_DIRECTORY}")
129#-----------------------------------------------------------------------------
130  ## NORMAL process
131  ## -- LOCAL_SUBMIT reports to CDash server
132  ## --------------------------
133  ctest_start (Experimental)
134  ctest_configure (BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res)
135  if (LOCAL_SUBMIT)
136    ctest_submit (PARTS Configure Notes)
137  endif ()
138  if (${res} LESS 0 OR ${res} GREATER 0)
139    file (APPEND ${CTEST_SCRIPT_DIRECTORY}/FailedCTest.txt "Failed Configure: ${res}\n")
140  endif ()
141
142  ctest_build (BUILD "${CTEST_BINARY_DIRECTORY}" APPEND RETURN_VALUE res NUMBER_ERRORS errval)
143  if (LOCAL_SUBMIT)
144    ctest_submit (PARTS Build)
145  endif ()
146  if (${res} LESS 0 OR ${res} GREATER 0 OR ${errval} GREATER 0)
147    file (APPEND ${CTEST_SCRIPT_DIRECTORY}/FailedCTest.txt "Failed ${errval} Build: ${res}\n")
148  endif ()
149
150  ctest_test (BUILD "${CTEST_BINARY_DIRECTORY}" APPEND ${ctest_test_args} RETURN_VALUE res)
151  if (LOCAL_SUBMIT)
152    ctest_submit (PARTS Test)
153  endif()
154  if (${res} LESS 0 OR ${res} GREATER 0)
155    file (APPEND ${CTEST_SCRIPT_DIRECTORY}/FailedCTest.txt "Failed Tests: ${res}\n")
156  endif ()
157  if (${res} LESS 0 OR ${res} GREATER 0)
158    message (FATAL_ERROR "tests FAILED")
159  endif ()
160#-----------------------------------------------------------------------------
161