main_ci.cmake 5.27 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..
Guillaume Pasero's avatar
Guillaume Pasero committed
28 29 30 31 32 33
if(ci_build_type)
  set (CTEST_BUILD_CONFIGURATION ${ci_build_type})
else()
  set (CTEST_BUILD_CONFIGURATION "Release")
endif()

Guillaume Pasero's avatar
Guillaume Pasero committed
34
set (CTEST_CMAKE_GENERATOR "Ninja")
Antoine Regimbeau's avatar
Antoine Regimbeau committed
35

36 37 38 39 40 41 42 43 44
# 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()

45
# Find the build name and CI profile
46
set_dash_build_name()
Guillaume Pasero's avatar
Guillaume Pasero committed
47

48 49
# set pipelines to enable documentation
set(ci_cookbook_profiles mr develop release)
50
set(ci_doxygen_profiles develop release)
51 52 53
list(FIND ci_cookbook_profiles ${ci_profile} ci_do_cookbook)
list(FIND ci_doxygen_profiles ${ci_profile} ci_do_doxygen)

54 55 56 57 58 59
# Detect site
if(NOT DEFINED IMAGE_NAME)
  if(DEFINED ENV{IMAGE_NAME})
    set(IMAGE_NAME $ENV{IMAGE_NAME})
  endif()
endif()
60
set (CTEST_SITE "${IMAGE_NAME}")
61

62 63 64 65 66
# Detect "skip testing"
if(DEFINED ENV{CI_SKIP_TESTING})
  set(ci_skip_testing 1)
endif()

67
# Directory variable
Antoine Regimbeau's avatar
Antoine Regimbeau committed
68
set (CTEST_SOURCE_DIRECTORY "${OTB_SOURCE_DIR}")
69 70 71 72 73 74 75 76 77 78
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()
79
set (PROJECT_SOURCE_DIR "${OTB_SOURCE_DIR}")
80 81 82

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

84
message(STATUS "CI profile : ${ci_profile}")
85

86
#The following file set the CONFIGURE_OPTIONS variable
87
set (ENABLE_DOXYGEN OFF)
88
set (CONFIGURE_OPTIONS  "")
Antoine Regimbeau's avatar
Antoine Regimbeau committed
89
include ( "${CMAKE_CURRENT_LIST_DIR}/configure_options.cmake" )
90

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

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

97 98 99
# End of configuration


100
ctest_start (Experimental TRACK CI_Build)
101

102 103
ctest_update()

Guillaume Pasero's avatar
Guillaume Pasero committed
104
# --------------------------- Configure ----------------------------------------
105 106 107
ctest_configure(BUILD "${CTEST_BINARY_DIRECTORY}"
    SOURCE "${OTB_SOURCE_DIR}"
    OPTIONS "${CONFIGURE_OPTIONS}"
108
    RETURN_VALUE _configure_rv
Antoine Regimbeau's avatar
Antoine Regimbeau committed
109 110
    CAPTURE_CMAKE_ERROR _configure_error
    )
111 112 113 114 115
# 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}")
116

117
if ( NOT _configure_rv EQUAL 0 )
118
  # stop processing here
119 120
  ctest_submit()
  message( FATAL_ERROR "An error occurs during ctest_configure.")
121 122
endif()

Guillaume Pasero's avatar
Guillaume Pasero committed
123
# ------------------------------ Build -----------------------------------------
Guillaume Pasero's avatar
Guillaume Pasero committed
124 125
if(ci_skip_install)
  message(STATUS "Skip install")
Guillaume Pasero's avatar
Guillaume Pasero committed
126 127 128 129 130 131
  if (ci_build_target)
    message(STATUS "Building target: ${ci_build_target}")
    set(CTEST_BUILD_TARGET ${ci_build_target})
  else()
    set(CTEST_BUILD_TARGET)
  endif()
Guillaume Pasero's avatar
Guillaume Pasero committed
132 133 134 135
else()
  set(CTEST_BUILD_TARGET install)
endif()

Antoine Regimbeau's avatar
Antoine Regimbeau committed
136 137 138 139
ctest_build(BUILD "${CTEST_BINARY_DIRECTORY}"
            RETURN_VALUE _build_rv
            CAPTURE_CMAKE_ERROR _build_error
            )
140

141 142 143 144 145 146
# 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}")

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

Guillaume Pasero's avatar
Guillaume Pasero committed
151
# ----------------------------- Test -------------------------------------------
152 153 154 155 156 157 158 159
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
             )
160 161 162 163 164
  # 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}")
165
endif()
Antoine Regimbeau's avatar
Antoine Regimbeau committed
166

Guillaume Pasero's avatar
Guillaume Pasero committed
167 168 169
if ( NOT _test_rv EQUAL 0 )
  message( SEND_ERROR "An error occurs during ctest_test.")
endif()
Antoine Regimbeau's avatar
Antoine Regimbeau committed
170

Guillaume Pasero's avatar
Guillaume Pasero committed
171
# ----------------------------- Submit -----------------------------------------
Guillaume Pasero's avatar
Guillaume Pasero committed
172 173 174 175 176
if(ci_skip_submit)
  message(STATUS "Skip submit")
else()
  ctest_submit()
endif()
177

Guillaume Pasero's avatar
Guillaume Pasero committed
178
# ---------------------------- Doxygen -----------------------------------------
179 180 181 182 183 184 185
if(ENABLE_DOXYGEN)
  ctest_build(BUILD "${CTEST_BINARY_DIRECTORY}"
              TARGET Documentation
              RETURN_VALUE _doxy_rv
              CAPTURE_CMAKE_ERROR _doxy_error
              )
endif()