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