ci.cmake 5 KB
Newer Older
Guillaume Pasero's avatar
Guillaume Pasero committed
1
2
3
4
5

# This script is a prototype for the future CI, it may evolve rapidly in a near future
set(REMOTE_MODULE_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR})
set (ENV{LANG} "C") # Only ascii output

Guillaume Pasero's avatar
Guillaume Pasero committed
6
7
8
# Get project name
file(STRINGS "${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt" _project_match REGEX "^project *\\(")
string(REGEX REPLACE "^project *\\( *([a-zA-Z0-9]+)" "\\1" otb-module ${_project_match})
Guillaume Pasero's avatar
Guillaume Pasero committed
9

Guillaume Pasero's avatar
Guillaume Pasero committed
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# Build Configuration : Release, Debug..
if(ci_build_type)
  set (CTEST_BUILD_CONFIGURATION ${ci_build_type})
else()
  set (CTEST_BUILD_CONFIGURATION "Release")
endif()

set (CTEST_CMAKE_GENERATOR "Ninja")

# detect short sha
if(NOT DEFINED ENV{TRAVIS_COMMIT})
  execute_process(COMMAND git log -1 --pretty=format:%h
                  WORKING_DIRECTORY ${REMOTE_MODULE_SOURCE_DIR}
                  OUTPUT_VARIABLE ci_short_sha)
else()
  set(ci_short_sha "$ENV{TRAVIS_COMMIT}")
endif()

set(CTEST_BUILD_NAME "$ENV{TRAVIS_BRANCH}")
29
30
31
32
33
34
35
set(CTEST_SITE "$ENV{TRAVIS_OS_NAME}")
if("${CTEST_SITE}" STREQUAL "linux")
  set(CTEST_SITE "${CTEST_SITE}-$ENV{TRAVIS_DIST}")
elseif("${CTEST_SITE}" STREQUAL "osx")
  set(CTEST_SITE "${CTEST_SITE}-$ENV{TRAVIS_OSX_IMAGE}")
endif()
set(CTEST_SITE "${CTEST_SITE}-$ENV{TRAVIS_COMPILER}")
Guillaume Pasero's avatar
Guillaume Pasero committed
36

Guillaume Pasero's avatar
Guillaume Pasero committed
37
38
39
set(CTEST_PROJECT_NAME "${otb-module}")
set(CTEST_DROP_METHOD "https")
set(CTEST_DROP_SITE "cdash.orfeo-toolbox.org")
40
set(CTEST_DROP_LOCATION "/submit.php?project=${otb-module}")
Guillaume Pasero's avatar
Guillaume Pasero committed
41
set(CTEST_DROP_SITE_CDASH TRUE)
Guillaume Pasero's avatar
Guillaume Pasero committed
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64

# Detect "skip testing"
if(DEFINED ENV{CI_SKIP_TESTING})
  set(ci_skip_testing 1)
endif()

# Directory variable
set (CTEST_SOURCE_DIRECTORY "${REMOTE_MODULE_SOURCE_DIR}")
if(BUILD_DIR)
  set (CTEST_BINARY_DIRECTORY "${BUILD_DIR}")
else()
  set (CTEST_BINARY_DIRECTORY "${REMOTE_MODULE_SOURCE_DIR}/build/")
endif()
if(INSTALL_DIR)
  set (CTEST_INSTALL_DIRECTORY "${INSTALL_DIR}")
else()
  set (CTEST_INSTALL_DIRECTORY "${REMOTE_MODULE_SOURCE_DIR}/install/")
endif()
set (PROJECT_SOURCE_DIR "${REMOTE_MODULE_SOURCE_DIR}")

# Ctest command value
set (CMAKE_COMMAND "cmake")

65
66
67
68
69
70
71
# Set the CONFIGURE_OPTIONS variable
set (all_options
"BUILD_SHARED_LIBS:BOOL=ON
BUILD_TESTING:BOOL=ON
OTB_BUILD_MODULE_AS_STANDALONE:BOOL=ON
CMAKE_PREFIX_PATH:PATH=${REMOTE_MODULE_SOURCE_DIR}/xdk
CMAKE_INSTALL_PREFIX:PATH=${CTEST_INSTALL_DIRECTORY}
72
73
74
75
76
77
78
79
80
81
82
83
84
85
CMAKE_BUILD_TYPE=${CTEST_BUILD_CONFIGURATION}")

if(UNIX AND NOT APPLE)
set(all_options
"${all_options}
OpenGL_GL_PREFERENCE=GLVND")
endif()

if(APPLE)
set(all_options
"${all_options}
CMAKE_MACOSX_RPATH=TRUE")
endif()

86
87
88
89
string (REPLACE "\n" ";" rm_options ${all_options})
foreach(item ${rm_options})
  set( CONFIGURE_OPTIONS "${CONFIGURE_OPTIONS}-D${item};")
endforeach(item)
Guillaume Pasero's avatar
Guillaume Pasero committed
90
91
92
93
94
95
96
97
98

# Sources are already checked out : do nothing for update
set(CTEST_GIT_UPDATE_CUSTOM "${CMAKE_COMMAND}" "-E" "echo" "No update")

# Look for a GIT command-line client.
find_program(CTEST_GIT_COMMAND NAMES git git.cmd)

# End of configuration

99
ctest_start (Experimental)
Guillaume Pasero's avatar
Guillaume Pasero committed
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174

ctest_update()

# --------------------------- Configure ----------------------------------------
ctest_configure(BUILD "${CTEST_BINARY_DIRECTORY}"
    SOURCE "${REMOTE_MODULE_SOURCE_DIR}"
    OPTIONS "${CONFIGURE_OPTIONS}"
    RETURN_VALUE _configure_rv
    CAPTURE_CMAKE_ERROR _configure_error
    )
# Configure log
file ( WRITE 
  "${REMOTE_MODULE_SOURCE_DIR}/log/configure_return_value_log.txt" "${_configure_rv}")
file ( WRITE 
  "${REMOTE_MODULE_SOURCE_DIR}/log/configure_cmake_error_log.txt" "${_configure_error}")

if ( NOT _configure_rv EQUAL 0 )
  # stop processing here
  ctest_submit()
  message( FATAL_ERROR "An error occurs during ctest_configure.")
endif()

# ------------------------------ Build -----------------------------------------
if(ci_skip_install)
  message(STATUS "Skip install")
  if (ci_build_target)
    message(STATUS "Building target: ${ci_build_target}")
    set(CTEST_BUILD_TARGET ${ci_build_target})
  else()
    set(CTEST_BUILD_TARGET)
  endif()
else()
  set(CTEST_BUILD_TARGET install)
endif()

ctest_build(BUILD "${CTEST_BINARY_DIRECTORY}"
            RETURN_VALUE _build_rv
            CAPTURE_CMAKE_ERROR _build_error
            )
# Build log
file ( WRITE 
  "${REMOTE_MODULE_SOURCE_DIR}/log/build_return_value_log.txt" "${_build_rv}")
file ( WRITE 
  "${REMOTE_MODULE_SOURCE_DIR}/log/build_cmake_error_log.txt" "${_build_error}")

if ( NOT _build_rv EQUAL 0 )
  message( SEND_ERROR "An error occurs during ctest_build.")
endif()

# ----------------------------- Test -------------------------------------------
if(ci_skip_testing)
  message(STATUS "Skip testing")
  set(_test_rv 0)
else()
  ctest_test(PARALLEL_LEVEL 2
             RETURN_VALUE _test_rv
             CAPTURE_CMAKE_ERROR _test_error
             )
  # Test log
  file ( WRITE 
    "${REMOTE_MODULE_SOURCE_DIR}/log/test_return_value_log.txt" "${_test_rv}")
  file ( WRITE 
    "${REMOTE_MODULE_SOURCE_DIR}/log/test_cmake_error_log.txt" "${_test_error}")
endif()

if ( NOT _test_rv EQUAL 0 )
  message( SEND_ERROR "An error occurs during ctest_test.")
endif()

# ----------------------------- Submit -----------------------------------------
if(ci_skip_submit)
  message(STATUS "Skip submit")
else()
  ctest_submit()
endif()