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