main_ci.cmake 4.98 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#
# Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES)
#
# This file is part of Orfeo Toolbox
#
#     https://www.orfeo-toolbox.org/
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

21
22
include( "${CMAKE_CURRENT_LIST_DIR}/macros.cmake" )

23
# This script is a prototype for the future CI, it may evolve rapidly in a near future
Antoine Regimbeau's avatar
Antoine Regimbeau committed
24
get_filename_component(OTB_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR} DIRECTORY)
Antoine Regimbeau's avatar
Antoine Regimbeau committed
25
set (ENV{LANG} "C") # Only ascii output
Antoine Regimbeau's avatar
Antoine Regimbeau committed
26

27
# Build Configuration : Release, Debug..
28
set (CTEST_BUILD_CONFIGURATION "Release")
Guillaume Pasero's avatar
Guillaume Pasero committed
29
set (CTEST_CMAKE_GENERATOR "Ninja")
Antoine Regimbeau's avatar
Antoine Regimbeau committed
30

31
32
33
34
35
36
37
38
39
# detect short sha
if(NOT DEFINED ENV{CI_COMMIT_SHORT_SHA})
  execute_process(COMMAND git log -1 --pretty=format:%h
                  WORKING_DIRECTORY ${OTB_SOURCE_DIR}
                  OUTPUT_VARIABLE ci_short_sha)
else()
  set(ci_short_sha "$ENV{CI_COMMIT_SHORT_SHA}")
endif()

40
# Find the build name and CI profile
41
set_dash_build_name()
Guillaume Pasero's avatar
Guillaume Pasero committed
42

43
44
45
46
47
48
# set pipelines to enable documentation
set(ci_cookbook_profiles mr develop release)
set(ci_doxygen_profiles mr develop release)
list(FIND ci_cookbook_profiles ${ci_profile} ci_do_cookbook)
list(FIND ci_doxygen_profiles ${ci_profile} ci_do_doxygen)

49
50
51
52
53
54
# Detect site
if(NOT DEFINED IMAGE_NAME)
  if(DEFINED ENV{IMAGE_NAME})
    set(IMAGE_NAME $ENV{IMAGE_NAME})
  endif()
endif()
55
set (CTEST_SITE "${IMAGE_NAME}")
56

57
58
59
60
61
# Detect "skip testing"
if(DEFINED ENV{CI_SKIP_TESTING})
  set(ci_skip_testing 1)
endif()

62
# Directory variable
Antoine Regimbeau's avatar
Antoine Regimbeau committed
63
set (CTEST_SOURCE_DIRECTORY "${OTB_SOURCE_DIR}")
64
65
66
67
68
69
70
71
72
73
if(BUILD_DIR)
  set (CTEST_BINARY_DIRECTORY "${BUILD_DIR}")
else()
  set (CTEST_BINARY_DIRECTORY "${OTB_SOURCE_DIR}/build/")
endif()
if(INSTALL_DIR)
  set (CTEST_INSTALL_DIRECTORY "${INSTALL_DIR}")
else()
  set (CTEST_INSTALL_DIRECTORY "${OTB_SOURCE_DIR}/install/")
endif()
74
set (PROJECT_SOURCE_DIR "${OTB_SOURCE_DIR}")
75
76
77

# Ctest command value
set (CMAKE_COMMAND "cmake")
Antoine Regimbeau's avatar
Antoine Regimbeau committed
78

79
message(STATUS "CI profile : ${ci_profile}")
80

Antoine Regimbeau's avatar
Antoine Regimbeau committed
81
#The following file set the CONFIGURE_OPTIONS variable
82
set (ENABLE_DOXYGEN OFF)
83
set (CONFIGURE_OPTIONS  "")
Antoine Regimbeau's avatar
Antoine Regimbeau committed
84
include ( "${CMAKE_CURRENT_LIST_DIR}/configure_options.cmake" )
Antoine Regimbeau's avatar
Antoine Regimbeau committed
85

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

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

92
93
94
# End of configuration


95
ctest_start (Experimental TRACK CI_Build)
96

97
98
ctest_update()

Guillaume Pasero's avatar
Guillaume Pasero committed
99
# --------------------------- Configure ----------------------------------------
100
101
102
ctest_configure(BUILD "${CTEST_BINARY_DIRECTORY}"
    SOURCE "${OTB_SOURCE_DIR}"
    OPTIONS "${CONFIGURE_OPTIONS}"
103
    RETURN_VALUE _configure_rv
Antoine Regimbeau's avatar
Antoine Regimbeau committed
104
105
    CAPTURE_CMAKE_ERROR _configure_error
    )
106
107
108
109
110
# Configure log
file ( WRITE 
  "${OTB_SOURCE_DIR}/log/configure_return_value_log.txt" "${_configure_rv}")
file ( WRITE 
  "${OTB_SOURCE_DIR}/log/configure_cmake_error_log.txt" "${_configure_error}")
111

112
if ( NOT _configure_rv EQUAL 0 )
113
  # stop processing here
114
115
  ctest_submit()
  message( FATAL_ERROR "An error occurs during ctest_configure.")
116
117
endif()

Guillaume Pasero's avatar
Guillaume Pasero committed
118
# ------------------------------ Build -----------------------------------------
Guillaume Pasero's avatar
Guillaume Pasero committed
119
120
121
122
123
124
125
if(ci_skip_install)
  message(STATUS "Skip install")
  set(CTEST_BUILD_TARGET)
else()
  set(CTEST_BUILD_TARGET install)
endif()

Antoine Regimbeau's avatar
Antoine Regimbeau committed
126
127
128
129
ctest_build(BUILD "${CTEST_BINARY_DIRECTORY}"
            RETURN_VALUE _build_rv
            CAPTURE_CMAKE_ERROR _build_error
            )
130

131
132
133
134
135
136
# Build log
file ( WRITE 
  "${OTB_SOURCE_DIR}/log/build_return_value_log.txt" "${_build_rv}")
file ( WRITE 
  "${OTB_SOURCE_DIR}/log/build_cmake_error_log.txt" "${_build_error}")

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

Guillaume Pasero's avatar
Guillaume Pasero committed
141
# ----------------------------- Test -------------------------------------------
142
143
144
145
146
147
148
149
if(ci_skip_testing)
  message(STATUS "Skip testing")
  set(_test_rv 0)
else()
  ctest_test(PARALLEL_LEVEL 8
             RETURN_VALUE _test_rv
             CAPTURE_CMAKE_ERROR _test_error
             )
150
151
152
153
154
  # Test log
  file ( WRITE 
    "${OTB_SOURCE_DIR}/log/test_return_value_log.txt" "${_test_rv}")
  file ( WRITE 
    "${OTB_SOURCE_DIR}/log/test_cmake_error_log.txt" "${_test_error}")
155
endif()
Antoine Regimbeau's avatar
Antoine Regimbeau committed
156

Guillaume Pasero's avatar
Guillaume Pasero committed
157
158
159
if ( NOT _test_rv EQUAL 0 )
  message( SEND_ERROR "An error occurs during ctest_test.")
endif()
Antoine Regimbeau's avatar
Antoine Regimbeau committed
160

Guillaume Pasero's avatar
Guillaume Pasero committed
161
# ----------------------------- Submit -----------------------------------------
Guillaume Pasero's avatar
Guillaume Pasero committed
162
ctest_submit()
163

Guillaume Pasero's avatar
Guillaume Pasero committed
164
# ---------------------------- Doxygen -----------------------------------------
165
166
167
168
169
170
171
if(ENABLE_DOXYGEN)
  ctest_build(BUILD "${CTEST_BINARY_DIRECTORY}"
              TARGET Documentation
              RETURN_VALUE _doxy_rv
              CAPTURE_CMAKE_ERROR _doxy_error
              )
endif()