comparison Resources/DownloadOrthancFramework.cmake @ 2884:497a637366b4 db-changes

integration mainline->db-changes
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 12 Oct 2018 15:18:10 +0200
parents f3a2d109e361
children 9abcfd97a76b
comparison
equal deleted inserted replaced
1762:2b91363cc1d1 2884:497a637366b4
1 # Orthanc - A Lightweight, RESTful DICOM Store
2 # Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
3 # Department, University Hospital of Liege, Belgium
4 # Copyright (C) 2017-2018 Osimis S.A., Belgium
5 #
6 # This program is free software: you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License as
8 # published by the Free Software Foundation, either version 3 of the
9 # License, or (at your option) any later version.
10 #
11 # In addition, as a special exception, the copyright holders of this
12 # program give permission to link the code of its release with the
13 # OpenSSL project's "OpenSSL" library (or with modified versions of it
14 # that use the same license as the "OpenSSL" library), and distribute
15 # the linked executables. You must obey the GNU General Public License
16 # in all respects for all of the code used other than "OpenSSL". If you
17 # modify file(s) with this exception, you may extend this exception to
18 # your version of the file(s), but you are not obligated to do so. If
19 # you do not wish to do so, delete this exception statement from your
20 # version. If you delete this exception statement from all source files
21 # in the program, then also delete it here.
22 #
23 # This program is distributed in the hope that it will be useful, but
24 # WITHOUT ANY WARRANTY; without even the implied warranty of
25 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
26 # General Public License for more details.
27 #
28 # You should have received a copy of the GNU General Public License
29 # along with this program. If not, see <http://www.gnu.org/licenses/>.
30
31
32
33 ##
34 ## Check whether the parent script sets the mandatory variables
35 ##
36
37 if (NOT DEFINED ORTHANC_FRAMEWORK_SOURCE OR
38 (NOT ORTHANC_FRAMEWORK_SOURCE STREQUAL "hg" AND
39 NOT ORTHANC_FRAMEWORK_SOURCE STREQUAL "web" AND
40 NOT ORTHANC_FRAMEWORK_SOURCE STREQUAL "archive" AND
41 NOT ORTHANC_FRAMEWORK_SOURCE STREQUAL "path"))
42 message(FATAL_ERROR "The variable ORTHANC_FRAMEWORK_SOURCE must be set to \"hg\", \"web\", \"archive\" or \"path\"")
43 endif()
44
45
46 ##
47 ## Detection of the requested version
48 ##
49
50 if (ORTHANC_FRAMEWORK_SOURCE STREQUAL "hg" OR
51 ORTHANC_FRAMEWORK_SOURCE STREQUAL "archive" OR
52 ORTHANC_FRAMEWORK_SOURCE STREQUAL "web")
53 if (NOT DEFINED ORTHANC_FRAMEWORK_VERSION)
54 message(FATAL_ERROR "The variable ORTHANC_FRAMEWORK_VERSION must be set")
55 endif()
56
57 if (DEFINED ORTHANC_FRAMEWORK_MAJOR OR
58 DEFINED ORTHANC_FRAMEWORK_MINOR OR
59 DEFINED ORTHANC_FRAMEWORK_REVISION OR
60 DEFINED ORTHANC_FRAMEWORK_MD5)
61 message(FATAL_ERROR "Some internal variable has been set")
62 endif()
63
64 set(ORTHANC_FRAMEWORK_MD5 "")
65
66 if (NOT DEFINED ORTHANC_FRAMEWORK_BRANCH)
67 if (ORTHANC_FRAMEWORK_VERSION STREQUAL "mainline")
68 set(ORTHANC_FRAMEWORK_BRANCH "default")
69
70 else()
71 set(ORTHANC_FRAMEWORK_BRANCH "Orthanc-${ORTHANC_FRAMEWORK_VERSION}")
72
73 set(RE "^([0-9]+)\\.([0-9]+)\\.([0-9]+)$")
74 string(REGEX REPLACE ${RE} "\\1" ORTHANC_FRAMEWORK_MAJOR ${ORTHANC_FRAMEWORK_VERSION})
75 string(REGEX REPLACE ${RE} "\\2" ORTHANC_FRAMEWORK_MINOR ${ORTHANC_FRAMEWORK_VERSION})
76 string(REGEX REPLACE ${RE} "\\3" ORTHANC_FRAMEWORK_REVISION ${ORTHANC_FRAMEWORK_VERSION})
77
78 if (NOT ORTHANC_FRAMEWORK_MAJOR MATCHES "^[0-9]+$" OR
79 NOT ORTHANC_FRAMEWORK_MINOR MATCHES "^[0-9]+$" OR
80 NOT ORTHANC_FRAMEWORK_REVISION MATCHES "^[0-9]+$")
81 message("Bad version of the Orthanc framework: ${ORTHANC_FRAMEWORK_VERSION}")
82 endif()
83
84 if (ORTHANC_FRAMEWORK_VERSION STREQUAL "1.3.1")
85 set(ORTHANC_FRAMEWORK_MD5 "dac95bd6cf86fb19deaf4e612961f378")
86 elseif (ORTHANC_FRAMEWORK_VERSION STREQUAL "1.3.2")
87 set(ORTHANC_FRAMEWORK_MD5 "d0ccdf68e855d8224331f13774992750")
88 elseif (ORTHANC_FRAMEWORK_VERSION STREQUAL "1.4.0")
89 set(ORTHANC_FRAMEWORK_MD5 "81e15f34d97ac32bbd7d26e85698835a")
90 elseif (ORTHANC_FRAMEWORK_VERSION STREQUAL "1.4.2")
91 set(ORTHANC_FRAMEWORK_MD5 "d1ee84927dcf668e60eb5868d24b9394")
92 endif()
93 endif()
94 endif()
95 endif()
96
97
98
99 ##
100 ## Detection of the third-party software
101 ##
102
103 if (ORTHANC_FRAMEWORK_SOURCE STREQUAL "hg")
104 find_program(ORTHANC_FRAMEWORK_HG hg)
105
106 if (${ORTHANC_FRAMEWORK_HG} MATCHES "ORTHANC_FRAMEWORK_HG-NOTFOUND")
107 message(FATAL_ERROR "Please install Mercurial")
108 endif()
109 endif()
110
111
112 if (ORTHANC_FRAMEWORK_SOURCE STREQUAL "archive" OR
113 ORTHANC_FRAMEWORK_SOURCE STREQUAL "web")
114 if ("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows")
115 find_program(ORTHANC_FRAMEWORK_7ZIP 7z
116 PATHS
117 "$ENV{ProgramFiles}/7-Zip"
118 "$ENV{ProgramW6432}/7-Zip"
119 )
120
121 if (${ORTHANC_FRAMEWORK_7ZIP} MATCHES "ORTHANC_FRAMEWORK_7ZIP-NOTFOUND")
122 message(FATAL_ERROR "Please install the '7-zip' software (http://www.7-zip.org/)")
123 endif()
124
125 else()
126 find_program(ORTHANC_FRAMEWORK_TAR tar)
127 if (${ORTHANC_FRAMEWORK_TAR} MATCHES "ORTHANC_FRAMEWORK_TAR-NOTFOUND")
128 message(FATAL_ERROR "Please install the 'tar' package")
129 endif()
130 endif()
131 endif()
132
133
134
135 ##
136 ## Case of the Orthanc framework specified as a path on the filesystem
137 ##
138
139 if (ORTHANC_FRAMEWORK_SOURCE STREQUAL "path")
140 if (NOT DEFINED ORTHANC_FRAMEWORK_ROOT)
141 message(FATAL_ERROR "The variable ORTHANC_FRAMEWORK_ROOT must provide the path to the sources of Orthanc")
142 endif()
143
144 if (NOT EXISTS ${ORTHANC_FRAMEWORK_ROOT})
145 message(FATAL_ERROR "Non-existing directory: ${ORTHANC_FRAMEWORK_ROOT}")
146 endif()
147
148 if (NOT EXISTS ${ORTHANC_FRAMEWORK_ROOT}/Resources/CMake/OrthancFrameworkParameters.cmake)
149 message(FATAL_ERROR "Directory not containing the source code of Orthanc: ${ORTHANC_FRAMEWORK_ROOT}")
150 endif()
151
152 set(ORTHANC_ROOT ${ORTHANC_FRAMEWORK_ROOT})
153 endif()
154
155
156
157 ##
158 ## Case of the Orthanc framework cloned using Mercurial
159 ##
160
161 if (ORTHANC_FRAMEWORK_SOURCE STREQUAL "hg")
162 if (NOT STATIC_BUILD AND NOT ALLOW_DOWNLOADS)
163 message(FATAL_ERROR "CMake is not allowed to download from Internet. Please set the ALLOW_DOWNLOADS option to ON")
164 endif()
165
166 set(ORTHANC_ROOT ${CMAKE_BINARY_DIR}/orthanc)
167
168 if (EXISTS ${ORTHANC_ROOT})
169 message("Updating the Orthanc source repository using Mercurial")
170 execute_process(
171 COMMAND ${ORTHANC_FRAMEWORK_HG} pull
172 WORKING_DIRECTORY ${ORTHANC_ROOT}
173 RESULT_VARIABLE Failure
174 )
175 else()
176 message("Forking the Orthanc source repository using Mercurial")
177 execute_process(
178 COMMAND ${ORTHANC_FRAMEWORK_HG} clone "https://bitbucket.org/sjodogne/orthanc"
179 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
180 RESULT_VARIABLE Failure
181 )
182 endif()
183
184 if (Failure OR NOT EXISTS ${ORTHANC_ROOT})
185 message(FATAL_ERROR "Cannot fork the Orthanc repository")
186 endif()
187
188 message("Setting branch of the Orthanc repository to: ${ORTHANC_FRAMEWORK_BRANCH}")
189
190 execute_process(
191 COMMAND ${ORTHANC_FRAMEWORK_HG} update -c ${ORTHANC_FRAMEWORK_BRANCH}
192 WORKING_DIRECTORY ${ORTHANC_ROOT}
193 RESULT_VARIABLE Failure
194 )
195
196 if (Failure)
197 message(FATAL_ERROR "Error while running Mercurial")
198 endif()
199 endif()
200
201
202
203 ##
204 ## Case of the Orthanc framework provided as a source archive on the
205 ## filesystem
206 ##
207
208 if (ORTHANC_FRAMEWORK_SOURCE STREQUAL "archive")
209 if (NOT DEFINED ORTHANC_FRAMEWORK_ARCHIVE)
210 message(FATAL_ERROR "The variable ORTHANC_FRAMEWORK_ARCHIVE must provide the path to the sources of Orthanc")
211 endif()
212 endif()
213
214
215
216 ##
217 ## Case of the Orthanc framework downloaded from the Web
218 ##
219
220 if (ORTHANC_FRAMEWORK_SOURCE STREQUAL "web")
221 if (DEFINED ORTHANC_FRAMEWORK_URL)
222 string(REGEX REPLACE "^.*/" "" ORTHANC_FRAMEMORK_FILENAME "${ORTHANC_FRAMEWORK_URL}")
223 else()
224 # Default case: Download from the official Web site
225 set(ORTHANC_FRAMEMORK_FILENAME Orthanc-${ORTHANC_FRAMEWORK_VERSION}.tar.gz)
226 #set(ORTHANC_FRAMEWORK_URL "http://www.orthanc-server.com/downloads/get.php?path=/orthanc/${ORTHANC_FRAMEMORK_FILENAME}")
227 set(ORTHANC_FRAMEWORK_URL "http://www.orthanc-server.com/downloads/third-party/orthanc-framework/${ORTHANC_FRAMEMORK_FILENAME}")
228 endif()
229
230 set(ORTHANC_FRAMEWORK_ARCHIVE "${CMAKE_SOURCE_DIR}/ThirdPartyDownloads/${ORTHANC_FRAMEMORK_FILENAME}")
231
232 if (NOT EXISTS "${ORTHANC_FRAMEWORK_ARCHIVE}")
233 if (NOT STATIC_BUILD AND NOT ALLOW_DOWNLOADS)
234 message(FATAL_ERROR "CMake is not allowed to download from Internet. Please set the ALLOW_DOWNLOADS option to ON")
235 endif()
236
237 message("Downloading: ${ORTHANC_FRAMEWORK_URL}")
238
239 file(DOWNLOAD
240 "${ORTHANC_FRAMEWORK_URL}" "${ORTHANC_FRAMEWORK_ARCHIVE}"
241 SHOW_PROGRESS EXPECTED_MD5 "${ORTHANC_FRAMEWORK_MD5}"
242 TIMEOUT 60
243 INACTIVITY_TIMEOUT 60
244 )
245 else()
246 message("Using local copy of: ${ORTHANC_FRAMEWORK_URL}")
247 endif()
248 endif()
249
250
251
252
253 ##
254 ## Uncompressing the Orthanc framework, if it was retrieved from a
255 ## source archive on the filesystem, or from the official Web site
256 ##
257
258 if (ORTHANC_FRAMEWORK_SOURCE STREQUAL "archive" OR
259 ORTHANC_FRAMEWORK_SOURCE STREQUAL "web")
260
261 if (NOT DEFINED ORTHANC_FRAMEWORK_ARCHIVE OR
262 NOT DEFINED ORTHANC_FRAMEWORK_VERSION OR
263 NOT DEFINED ORTHANC_FRAMEWORK_MD5)
264 message(FATAL_ERROR "Internal error")
265 endif()
266
267 if (ORTHANC_FRAMEWORK_MD5 STREQUAL "")
268 message(FATAL_ERROR "Unknown release of Orthanc: ${ORTHANC_FRAMEWORK_VERSION}")
269 endif()
270
271 file(MD5 ${ORTHANC_FRAMEWORK_ARCHIVE} ActualMD5)
272
273 if (NOT "${ActualMD5}" STREQUAL "${ORTHANC_FRAMEWORK_MD5}")
274 message(FATAL_ERROR "The MD5 hash of the Orthanc archive is invalid: ${ORTHANC_FRAMEWORK_ARCHIVE}")
275 endif()
276
277 set(ORTHANC_ROOT "${CMAKE_BINARY_DIR}/Orthanc-${ORTHANC_FRAMEWORK_VERSION}")
278
279 if (NOT IS_DIRECTORY "${ORTHANC_ROOT}")
280 if (NOT ORTHANC_FRAMEWORK_ARCHIVE MATCHES ".tar.gz$")
281 message(FATAL_ERROR "Archive should have the \".tar.gz\" extension: ${ORTHANC_FRAMEWORK_ARCHIVE}")
282 endif()
283
284 message("Uncompressing: ${ORTHANC_FRAMEWORK_ARCHIVE}")
285
286 if ("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows")
287 # How to silently extract files using 7-zip
288 # http://superuser.com/questions/331148/7zip-command-line-extract-silently-quietly
289
290 execute_process(
291 COMMAND ${ORTHANC_FRAMEWORK_7ZIP} e -y ${ORTHANC_FRAMEWORK_ARCHIVE}
292 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
293 RESULT_VARIABLE Failure
294 OUTPUT_QUIET
295 )
296
297 if (Failure)
298 message(FATAL_ERROR "Error while running the uncompression tool")
299 endif()
300
301 get_filename_component(TMP_FILENAME "${ORTHANC_FRAMEWORK_ARCHIVE}" NAME)
302 string(REGEX REPLACE ".gz$" "" TMP_FILENAME2 "${TMP_FILENAME}")
303
304 execute_process(
305 COMMAND ${ORTHANC_FRAMEWORK_7ZIP} x -y ${TMP_FILENAME2}
306 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
307 RESULT_VARIABLE Failure
308 OUTPUT_QUIET
309 )
310
311 else()
312 execute_process(
313 COMMAND sh -c "${ORTHANC_FRAMEWORK_TAR} xfz ${ORTHANC_FRAMEWORK_ARCHIVE}"
314 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
315 RESULT_VARIABLE Failure
316 )
317 endif()
318
319 if (Failure)
320 message(FATAL_ERROR "Error while running the uncompression tool")
321 endif()
322
323 if (NOT IS_DIRECTORY "${ORTHANC_ROOT}")
324 message(FATAL_ERROR "The Orthanc framework was not uncompressed at the proper location. Check the CMake instructions.")
325 endif()
326 endif()
327 endif()