summaryrefslogtreecommitdiffstats
path: root/Utilities/Release/release_cmake.cmake
blob: ec1fbb3b34a1a0c8fc7eb0a11ec57437f8411ab5 (plain)
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
set(CVSROOT ":pserver:anonymous@www.cmake.org:/cvsroot/CMake")
get_filename_component(SCRIPT_PATH "${CMAKE_CURRENT_LIST_FILE}" PATH)

if(DEFINED EXTRA_COPY)
  set(HAS_EXTRA_COPY 1)
endif(DEFINED EXTRA_COPY)
if(NOT DEFINED CMAKE_RELEASE_DIRECTORY)
  set(CMAKE_RELEASE_DIRECTORY "~/CMakeReleaseDirectory")
endif(NOT DEFINED CMAKE_RELEASE_DIRECTORY)
if(NOT DEFINED MAKE_COMMAND)
  message(FATAL_ERROR "MAKE_COMMAND must be set")
endif(NOT DEFINED MAKE_COMMAND)
if(NOT DEFINED MAKE)
  set(MAKE "${MAKE_COMMAND}")
endif(NOT DEFINED MAKE)
if(NOT DEFINED RUN_SHELL)
  set(RUN_SHELL "/bin/sh")
endif(NOT DEFINED RUN_SHELL)
if(NOT DEFINED INSTALLER_SUFFIX)
  set(INSTALLER_SUFFIX "*.sh")
endif(NOT DEFINED INSTALLER_SUFFIX)
if(NOT DEFINED PROCESSORS)
  set(PROCESSORS 1)
endif(NOT DEFINED PROCESSORS)
if(NOT DEFINED CMAKE_VERSION)
  message(FATAL_ERROR "CMAKE_VERSION not defined")
endif(NOT DEFINED CMAKE_VERSION)
if(NOT DEFINED CVS_COMMAND)
  set(CVS_COMMAND cvs)
endif(NOT DEFINED CVS_COMMAND)

if("${CMAKE_VERSION}" STREQUAL "CVS")
  set( CMAKE_CHECKOUT "${CVS_COMMAND} -q -z3 -d ${CVSROOT} export -D now ")
  set( CMAKE_VERSION "CurrentCVS")
else("${CMAKE_VERSION}" STREQUAL "CVS")
  set( CMAKE_CHECKOUT "${CVS_COMMAND} -q -z3 -d ${CVSROOT} export -r ${CMAKE_VERSION} ")
endif("${CMAKE_VERSION}" STREQUAL "CVS")

if(NOT HOST)
  message(FATAL_ERROR "HOST must be specified with -DHOST=host")
endif(NOT HOST)
if(NOT DEFINED MAKE)
  message(FATAL_ERROR "MAKE must be specified with -DMAKE=\"make -j2\"")
endif(NOT DEFINED MAKE)
  
message("Creating CMake release ${CMAKE_VERSION} on ${HOST} with parallel = ${PROCESSORS}")

# define a macro to run a remote command
macro(remote_command comment command)
  message("${comment}")
  if(${ARGC} GREATER 2)
    message("ssh ${HOST} ${EXTRA_HOP} ${command}")
    execute_process(COMMAND ssh ${HOST} ${EXTRA_HOP} ${command} RESULT_VARIABLE result INPUT_FILE ${ARGV2})
  else(${ARGC} GREATER 2)
    message("ssh ${HOST} ${EXTRA_HOP} ${command}") 
    execute_process(COMMAND ssh ${HOST} ${EXTRA_HOP} ${command} RESULT_VARIABLE result) 
  endif(${ARGC} GREATER 2)
  if(${result} GREATER 0)
    message(FATAL_ERROR "Error running command: ${command}, return value = ${result}")
  endif(${result} GREATER 0)
endmacro(remote_command)

# set this so configure file will work from script mode
set(CMAKE_BACKWARDS_COMPATIBILITY 2.4)
# create the script specific for the given host
configure_file(${SCRIPT_PATH}/release_cmake.sh.in
  release_cmake-${HOST}.sh @ONLY)
# remove any old version of the script
remote_command("remove old release_cmake-${HOST}.sh from server"
  "rm -f release_cmake-${HOST}.sh")
# copy the script to the remote host via cat with the 
# script as input for the execute_process this will translate
# the file from dos to unix
remote_command("Copy release_cmake-${HOST}.sh to sever"
  "cat > release_cmake-${HOST}.sh" release_cmake-${HOST}.sh)

# now run the script on the remote machine
remote_command("Run release script" "${RUN_SHELL} release_cmake-${HOST}.sh")

message("copy the .gz file back from the machine")
message("scp ${HOST}:${CMAKE_RELEASE_DIRECTORY}/${CMAKE_VERSION}-build/*.gz .")
execute_process(COMMAND scp ${HOST}:${CMAKE_RELEASE_DIRECTORY}/${CMAKE_VERSION}-build/*.gz .
  RESULT_VARIABLE result) 

message("copy the ${INSTALLER_SUFFIX} file back from the machine")
message("scp ${HOST}:${CMAKE_RELEASE_DIRECTORY}/${CMAKE_VERSION}-build/${INSTALLER_SUFFIX} .")
execute_process(COMMAND scp ${HOST}:${CMAKE_RELEASE_DIRECTORY}/${CMAKE_VERSION}-build/${INSTALLER_SUFFIX} .
  RESULT_VARIABLE result)