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