comparison Resources/Orthanc/DownloadOrthancFramework.cmake @ 0:520cba9a0d42

initial commit
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 13 Jun 2019 14:57:22 +0200
parents
children 2514880d4f0b
comparison
equal deleted inserted replaced
-1:000000000000 0:520cba9a0d42
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-2019 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 set(ORTHANC_FRAMEWORK_MAJOR 999)
70 set(ORTHANC_FRAMEWORK_MINOR 999)
71 set(ORTHANC_FRAMEWORK_REVISION 999)
72
73 else()
74 set(ORTHANC_FRAMEWORK_BRANCH "Orthanc-${ORTHANC_FRAMEWORK_VERSION}")
75
76 set(RE "^([0-9]+)\\.([0-9]+)\\.([0-9]+)$")
77 string(REGEX REPLACE ${RE} "\\1" ORTHANC_FRAMEWORK_MAJOR ${ORTHANC_FRAMEWORK_VERSION})
78 string(REGEX REPLACE ${RE} "\\2" ORTHANC_FRAMEWORK_MINOR ${ORTHANC_FRAMEWORK_VERSION})
79 string(REGEX REPLACE ${RE} "\\3" ORTHANC_FRAMEWORK_REVISION ${ORTHANC_FRAMEWORK_VERSION})
80
81 if (NOT ORTHANC_FRAMEWORK_MAJOR MATCHES "^[0-9]+$" OR
82 NOT ORTHANC_FRAMEWORK_MINOR MATCHES "^[0-9]+$" OR
83 NOT ORTHANC_FRAMEWORK_REVISION MATCHES "^[0-9]+$")
84 message("Bad version of the Orthanc framework: ${ORTHANC_FRAMEWORK_VERSION}")
85 endif()
86
87 if (ORTHANC_FRAMEWORK_VERSION STREQUAL "1.3.1")
88 set(ORTHANC_FRAMEWORK_MD5 "dac95bd6cf86fb19deaf4e612961f378")
89 elseif (ORTHANC_FRAMEWORK_VERSION STREQUAL "1.3.2")
90 set(ORTHANC_FRAMEWORK_MD5 "d0ccdf68e855d8224331f13774992750")
91 elseif (ORTHANC_FRAMEWORK_VERSION STREQUAL "1.4.0")
92 set(ORTHANC_FRAMEWORK_MD5 "81e15f34d97ac32bbd7d26e85698835a")
93 elseif (ORTHANC_FRAMEWORK_VERSION STREQUAL "1.4.1")
94 set(ORTHANC_FRAMEWORK_MD5 "9b6f6114264b17ed421b574cd6476127")
95 elseif (ORTHANC_FRAMEWORK_VERSION STREQUAL "1.4.2")
96 set(ORTHANC_FRAMEWORK_MD5 "d1ee84927dcf668e60eb5868d24b9394")
97 elseif (ORTHANC_FRAMEWORK_VERSION STREQUAL "1.5.0")
98 set(ORTHANC_FRAMEWORK_MD5 "4429d8d9dea4ff6648df80ec3c64d79e")
99 elseif (ORTHANC_FRAMEWORK_VERSION STREQUAL "1.5.1")
100 set(ORTHANC_FRAMEWORK_MD5 "099671538865e5da96208b37494d6718")
101 elseif (ORTHANC_FRAMEWORK_VERSION STREQUAL "1.5.2")
102 set(ORTHANC_FRAMEWORK_MD5 "8867050f3e9a1ce6157c1ea7a9433b1b")
103 elseif (ORTHANC_FRAMEWORK_VERSION STREQUAL "1.5.3")
104 set(ORTHANC_FRAMEWORK_MD5 "bf2f5ed1adb8b0fc5f10d278e68e1dfe")
105 elseif (ORTHANC_FRAMEWORK_VERSION STREQUAL "1.5.4")
106 set(ORTHANC_FRAMEWORK_MD5 "404baef5d4c43e7c5d9410edda8ef5a5")
107 elseif (ORTHANC_FRAMEWORK_VERSION STREQUAL "1.5.5")
108 set(ORTHANC_FRAMEWORK_MD5 "cfc437e0687ae4bd725fd93dc1f08bc4")
109 elseif (ORTHANC_FRAMEWORK_VERSION STREQUAL "1.5.6")
110 set(ORTHANC_FRAMEWORK_MD5 "3c29de1e289b5472342947168f0105c0")
111 endif()
112 endif()
113 endif()
114 else()
115 message("Using the Orthanc framework from a path of the filesystem. Assuming mainline version.")
116 set(ORTHANC_FRAMEWORK_MAJOR 999)
117 set(ORTHANC_FRAMEWORK_MINOR 999)
118 set(ORTHANC_FRAMEWORK_REVISION 999)
119 endif()
120
121
122
123 ##
124 ## Detection of the third-party software
125 ##
126
127 if (ORTHANC_FRAMEWORK_SOURCE STREQUAL "hg")
128 find_program(ORTHANC_FRAMEWORK_HG hg)
129
130 if (${ORTHANC_FRAMEWORK_HG} MATCHES "ORTHANC_FRAMEWORK_HG-NOTFOUND")
131 message(FATAL_ERROR "Please install Mercurial")
132 endif()
133 endif()
134
135
136 if (ORTHANC_FRAMEWORK_SOURCE STREQUAL "archive" OR
137 ORTHANC_FRAMEWORK_SOURCE STREQUAL "web")
138 if ("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows")
139 find_program(ORTHANC_FRAMEWORK_7ZIP 7z
140 PATHS
141 "$ENV{ProgramFiles}/7-Zip"
142 "$ENV{ProgramW6432}/7-Zip"
143 )
144
145 if (${ORTHANC_FRAMEWORK_7ZIP} MATCHES "ORTHANC_FRAMEWORK_7ZIP-NOTFOUND")
146 message(FATAL_ERROR "Please install the '7-zip' software (http://www.7-zip.org/)")
147 endif()
148
149 else()
150 find_program(ORTHANC_FRAMEWORK_TAR tar)
151 if (${ORTHANC_FRAMEWORK_TAR} MATCHES "ORTHANC_FRAMEWORK_TAR-NOTFOUND")
152 message(FATAL_ERROR "Please install the 'tar' package")
153 endif()
154 endif()
155 endif()
156
157
158
159 ##
160 ## Case of the Orthanc framework specified as a path on the filesystem
161 ##
162
163 if (ORTHANC_FRAMEWORK_SOURCE STREQUAL "path")
164 if (NOT DEFINED ORTHANC_FRAMEWORK_ROOT)
165 message(FATAL_ERROR "The variable ORTHANC_FRAMEWORK_ROOT must provide the path to the sources of Orthanc")
166 endif()
167
168 if (NOT EXISTS ${ORTHANC_FRAMEWORK_ROOT})
169 message(FATAL_ERROR "Non-existing directory: ${ORTHANC_FRAMEWORK_ROOT}")
170 endif()
171
172 if (NOT EXISTS ${ORTHANC_FRAMEWORK_ROOT}/Resources/CMake/OrthancFrameworkParameters.cmake)
173 message(FATAL_ERROR "Directory not containing the source code of Orthanc: ${ORTHANC_FRAMEWORK_ROOT}")
174 endif()
175
176 set(ORTHANC_ROOT ${ORTHANC_FRAMEWORK_ROOT})
177 endif()
178
179
180
181 ##
182 ## Case of the Orthanc framework cloned using Mercurial
183 ##
184
185 if (ORTHANC_FRAMEWORK_SOURCE STREQUAL "hg")
186 if (NOT STATIC_BUILD AND NOT ALLOW_DOWNLOADS)
187 message(FATAL_ERROR "CMake is not allowed to download from Internet. Please set the ALLOW_DOWNLOADS option to ON")
188 endif()
189
190 set(ORTHANC_ROOT ${CMAKE_BINARY_DIR}/orthanc)
191
192 if (EXISTS ${ORTHANC_ROOT})
193 message("Updating the Orthanc source repository using Mercurial")
194 execute_process(
195 COMMAND ${ORTHANC_FRAMEWORK_HG} pull
196 WORKING_DIRECTORY ${ORTHANC_ROOT}
197 RESULT_VARIABLE Failure
198 )
199 else()
200 message("Forking the Orthanc source repository using Mercurial")
201 execute_process(
202 COMMAND ${ORTHANC_FRAMEWORK_HG} clone "https://bitbucket.org/sjodogne/orthanc"
203 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
204 RESULT_VARIABLE Failure
205 )
206 endif()
207
208 if (Failure OR NOT EXISTS ${ORTHANC_ROOT})
209 message(FATAL_ERROR "Cannot fork the Orthanc repository")
210 endif()
211
212 message("Setting branch of the Orthanc repository to: ${ORTHANC_FRAMEWORK_BRANCH}")
213
214 execute_process(
215 COMMAND ${ORTHANC_FRAMEWORK_HG} update -c ${ORTHANC_FRAMEWORK_BRANCH}
216 WORKING_DIRECTORY ${ORTHANC_ROOT}
217 RESULT_VARIABLE Failure
218 )
219
220 if (Failure)
221 message(FATAL_ERROR "Error while running Mercurial")
222 endif()
223 endif()
224
225
226
227 ##
228 ## Case of the Orthanc framework provided as a source archive on the
229 ## filesystem
230 ##
231
232 if (ORTHANC_FRAMEWORK_SOURCE STREQUAL "archive")
233 if (NOT DEFINED ORTHANC_FRAMEWORK_ARCHIVE)
234 message(FATAL_ERROR "The variable ORTHANC_FRAMEWORK_ARCHIVE must provide the path to the sources of Orthanc")
235 endif()
236 endif()
237
238
239
240 ##
241 ## Case of the Orthanc framework downloaded from the Web
242 ##
243
244 if (ORTHANC_FRAMEWORK_SOURCE STREQUAL "web")
245 if (DEFINED ORTHANC_FRAMEWORK_URL)
246 string(REGEX REPLACE "^.*/" "" ORTHANC_FRAMEMORK_FILENAME "${ORTHANC_FRAMEWORK_URL}")
247 else()
248 # Default case: Download from the official Web site
249 set(ORTHANC_FRAMEMORK_FILENAME Orthanc-${ORTHANC_FRAMEWORK_VERSION}.tar.gz)
250 set(ORTHANC_FRAMEWORK_URL "http://orthanc.osimis.io/ThirdPartyDownloads/orthanc-framework/${ORTHANC_FRAMEMORK_FILENAME}")
251 endif()
252
253 set(ORTHANC_FRAMEWORK_ARCHIVE "${CMAKE_SOURCE_DIR}/ThirdPartyDownloads/${ORTHANC_FRAMEMORK_FILENAME}")
254
255 if (NOT EXISTS "${ORTHANC_FRAMEWORK_ARCHIVE}")
256 if (NOT STATIC_BUILD AND NOT ALLOW_DOWNLOADS)
257 message(FATAL_ERROR "CMake is not allowed to download from Internet. Please set the ALLOW_DOWNLOADS option to ON")
258 endif()
259
260 message("Downloading: ${ORTHANC_FRAMEWORK_URL}")
261
262 file(DOWNLOAD
263 "${ORTHANC_FRAMEWORK_URL}" "${ORTHANC_FRAMEWORK_ARCHIVE}"
264 SHOW_PROGRESS EXPECTED_MD5 "${ORTHANC_FRAMEWORK_MD5}"
265 TIMEOUT 60
266 INACTIVITY_TIMEOUT 60
267 )
268 else()
269 message("Using local copy of: ${ORTHANC_FRAMEWORK_URL}")
270 endif()
271 endif()
272
273
274
275
276 ##
277 ## Uncompressing the Orthanc framework, if it was retrieved from a
278 ## source archive on the filesystem, or from the official Web site
279 ##
280
281 if (ORTHANC_FRAMEWORK_SOURCE STREQUAL "archive" OR
282 ORTHANC_FRAMEWORK_SOURCE STREQUAL "web")
283
284 if (NOT DEFINED ORTHANC_FRAMEWORK_ARCHIVE OR
285 NOT DEFINED ORTHANC_FRAMEWORK_VERSION OR
286 NOT DEFINED ORTHANC_FRAMEWORK_MD5)
287 message(FATAL_ERROR "Internal error")
288 endif()
289
290 if (ORTHANC_FRAMEWORK_MD5 STREQUAL "")
291 message(FATAL_ERROR "Unknown release of Orthanc: ${ORTHANC_FRAMEWORK_VERSION}")
292 endif()
293
294 file(MD5 ${ORTHANC_FRAMEWORK_ARCHIVE} ActualMD5)
295
296 if (NOT "${ActualMD5}" STREQUAL "${ORTHANC_FRAMEWORK_MD5}")
297 message(FATAL_ERROR "The MD5 hash of the Orthanc archive is invalid: ${ORTHANC_FRAMEWORK_ARCHIVE}")
298 endif()
299
300 set(ORTHANC_ROOT "${CMAKE_BINARY_DIR}/Orthanc-${ORTHANC_FRAMEWORK_VERSION}")
301
302 if (NOT IS_DIRECTORY "${ORTHANC_ROOT}")
303 if (NOT ORTHANC_FRAMEWORK_ARCHIVE MATCHES ".tar.gz$")
304 message(FATAL_ERROR "Archive should have the \".tar.gz\" extension: ${ORTHANC_FRAMEWORK_ARCHIVE}")
305 endif()
306
307 message("Uncompressing: ${ORTHANC_FRAMEWORK_ARCHIVE}")
308
309 if ("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows")
310 # How to silently extract files using 7-zip
311 # http://superuser.com/questions/331148/7zip-command-line-extract-silently-quietly
312
313 execute_process(
314 COMMAND ${ORTHANC_FRAMEWORK_7ZIP} e -y ${ORTHANC_FRAMEWORK_ARCHIVE}
315 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
316 RESULT_VARIABLE Failure
317 OUTPUT_QUIET
318 )
319
320 if (Failure)
321 message(FATAL_ERROR "Error while running the uncompression tool")
322 endif()
323
324 get_filename_component(TMP_FILENAME "${ORTHANC_FRAMEWORK_ARCHIVE}" NAME)
325 string(REGEX REPLACE ".gz$" "" TMP_FILENAME2 "${TMP_FILENAME}")
326
327 execute_process(
328 COMMAND ${ORTHANC_FRAMEWORK_7ZIP} x -y ${TMP_FILENAME2}
329 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
330 RESULT_VARIABLE Failure
331 OUTPUT_QUIET
332 )
333
334 else()
335 execute_process(
336 COMMAND sh -c "${ORTHANC_FRAMEWORK_TAR} xfz ${ORTHANC_FRAMEWORK_ARCHIVE}"
337 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
338 RESULT_VARIABLE Failure
339 )
340 endif()
341
342 if (Failure)
343 message(FATAL_ERROR "Error while running the uncompression tool")
344 endif()
345
346 if (NOT IS_DIRECTORY "${ORTHANC_ROOT}")
347 message(FATAL_ERROR "The Orthanc framework was not uncompressed at the proper location. Check the CMake instructions.")
348 endif()
349 endif()
350 endif()