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