-
Notifications
You must be signed in to change notification settings - Fork 0
/
ci.cmake
213 lines (183 loc) · 6.63 KB
/
ci.cmake
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
90
91
92
93
94
95
96
97
98
99
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# 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
# 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})
# 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_PROJECT_NAME "${otb-module}")
set(CTEST_DROP_METHOD "https")
set(CTEST_DROP_SITE "cdash.orfeo-toolbox.org")
set(CTEST_DROP_LOCATION "/submit.php?project=OTB")
set(CTEST_DROP_SITE_CDASH TRUE)
set(CTEST_BUILD_NAME "${CTEST_PROJECT_NAME} ($ENV{TRAVIS_BRANCH})")
set(CTEST_SITE "$ENV{TRAVIS_OS_NAME}")
set(compiler_name "$ENV{TRAVIS_COMPILER}")
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}")
elseif("${CTEST_SITE}" STREQUAL "windows")
set(CTEST_SITE "${CTEST_SITE}-server1803")
set(compiler_name "vc140")
endif()
set(CTEST_SITE "${CTEST_SITE}-${compiler_name}")
# 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")
# 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}
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()
string (REPLACE "\n" ";" rm_options ${all_options})
foreach(item ${rm_options})
set( CONFIGURE_OPTIONS "${CONFIGURE_OPTIONS}-D${item};")
endforeach(item)
# 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)
# Add bin dir to PATH for testing on Windows
if(WIN32)
file(TO_NATIVE_PATH "${CTEST_BINARY_DIRECTORY}/bin" RM_BUILD_BIN_DIR_NATIVE)
set(ENV{PATH} "$ENV{PATH};${RM_BUILD_BIN_DIR_NATIVE}" )
endif()
# Get Data from OTB :
# - Use this flag to get the full data
set(RM_GET_FULL_DATA OFF)
# - Or give a list of patterns
set(RM_DATA_PATTERNS)
set(RM_DATA_REF develop)
if (RM_GET_FULL_DATA OR RM_DATA_PATTERNS)
message(STATUS "Retrieve data files from OTB")
execute_process(COMMAND git clone -b ${RM_DATA_REF} --depth 1 -n https://gitlab.orfeo-toolbox.org/orfeotoolbox/otb.git
WORKING_DIRECTORY ${REMOTE_MODULE_SOURCE_DIR})
if(RM_GET_FULL_DATA)
message(STATUS " Get full data")
else()
string(REPLACE ";" "," lfs_includes "${RM_DATA_PATTERNS}")
message(STATUS " Get paths: ${RM_DATA_PATTERNS}")
execute_process(COMMAND git config lfs.fetchinclude "${lfs_includes}"
WORKING_DIRECTORY ${REMOTE_MODULE_SOURCE_DIR}/otb)
endif()
execute_process(COMMAND git lfs fetch
WORKING_DIRECTORY ${REMOTE_MODULE_SOURCE_DIR}/otb)
execute_process(COMMAND git reset HEAD *
WORKING_DIRECTORY ${REMOTE_MODULE_SOURCE_DIR}/otb
OUTPUT_QUIET)
execute_process(COMMAND git checkout -- Data/*
WORKING_DIRECTORY ${REMOTE_MODULE_SOURCE_DIR}/otb)
set( CONFIGURE_OPTIONS "${CONFIGURE_OPTIONS}-DOTB_DATA_ROOT:PATH=${REMOTE_MODULE_SOURCE_DIR}/otb/Data;")
endif()
# End of configuration
ctest_start (Experimental TRACK RemoteModules)
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()