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