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 AND NOT MINGW)
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 (MAX_PROC_COUNT)
105    if (N GREATER MAX_PROC_COUNT)
106      set (N ${MAX_PROC_COUNT})
107    endif ()
108  endif ()
109  if (NOT WIN32)
110    set (CTEST_BUILD_FLAGS -j${N})
111  endif ()
112  set (ctest_test_args ${ctest_test_args} PARALLEL_LEVEL ${N})
113endif ()
114
115#-----------------------------------------------------------------------------
116# Initialize the CTEST commands
117#------------------------------
118set(CTEST_CONFIGURE_TOOLSET  "")
119if(CMAKE_GENERATOR_TOOLSET)
120  set(CTEST_CONFIGURE_TOOLSET  "-T${CMAKE_GENERATOR_TOOLSET}")
121endif()
122set(CTEST_CONFIGURE_ARCHITECTURE  "")
123if(CMAKE_GENERATOR_ARCHITECTURE)
124  set(CTEST_CONFIGURE_ARCHITECTURE  "-A${CMAKE_GENERATOR_ARCHITECTURE}")
125endif()
126set (CTEST_CONFIGURE_COMMAND
127    "${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_ARCHITECTURE}\" \"${CTEST_CONFIGURE_TOOLSET}\" \"${CTEST_SOURCE_DIRECTORY}\""
128)
129#-----------------------------------------------------------------------------
130
131#-----------------------------------------------------------------------------
132## -- set output to english
133set ($ENV{LC_MESSAGES}  "en_EN")
134
135#-----------------------------------------------------------------------------
136  configure_file(${CTEST_SOURCE_DIRECTORY}/config/cmake/CTestCustom.cmake ${CTEST_BINARY_DIRECTORY}/CTestCustom.cmake)
137  ctest_read_custom_files ("${CTEST_BINARY_DIRECTORY}")
138#-----------------------------------------------------------------------------
139  ## NORMAL process
140  ## -- LOCAL_SUBMIT reports to CDash server
141  ## --------------------------
142  ctest_start (Experimental)
143  ctest_configure (BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res)
144  if (LOCAL_SUBMIT)
145    ctest_submit (PARTS Configure Notes)
146  endif ()
147  if (${res} LESS 0 OR ${res} GREATER 0)
148    file (APPEND ${CTEST_SCRIPT_DIRECTORY}/FailedCTest.txt "Failed Configure: ${res}\n")
149  endif ()
150
151  ctest_build (BUILD "${CTEST_BINARY_DIRECTORY}" APPEND RETURN_VALUE res NUMBER_ERRORS errval)
152  if (LOCAL_SUBMIT)
153    ctest_submit (PARTS Build)
154  endif ()
155  if (${res} LESS 0 OR ${res} GREATER 0 OR ${errval} GREATER 0)
156    file (APPEND ${CTEST_SCRIPT_DIRECTORY}/FailedCTest.txt "Failed ${errval} Build: ${res}\n")
157  endif ()
158
159  ctest_test (BUILD "${CTEST_BINARY_DIRECTORY}" APPEND ${ctest_test_args} RETURN_VALUE res)
160  if (LOCAL_SUBMIT)
161    ctest_submit (PARTS Test)
162  endif()
163  if (${res} LESS 0 OR ${res} GREATER 0)
164    file (APPEND ${CTEST_SCRIPT_DIRECTORY}/FailedCTest.txt "Failed Tests: ${res}\n")
165  endif ()
166  if (${res} LESS 0 OR ${res} GREATER 0)
167    message (FATAL_ERROR "tests FAILED")
168  endif ()
169#-----------------------------------------------------------------------------
170