comparison Resources/Orthanc/DownloadOrthancFramework.cmake @ 212:5412adf19980

resort to OrthancFramework
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 01 Jun 2018 17:48:47 +0200
parents
children b04b13810540 348e00b837b9
comparison
equal deleted inserted replaced
211:64eac89a1de3 212:5412adf19980
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 elseif (ORTHANC_FRAMEWORK_VERSION STREQUAL "1.3.2")
86 set(ORTHANC_FRAMEWORK_MD5 "d0ccdf68e855d8224331f13774992750")
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 the source code 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 if (NOT STATIC_BUILD AND NOT ALLOW_DOWNLOADS)
157 message(FATAL_ERROR "CMake is not allowed to download from Internet. Please set the ALLOW_DOWNLOADS option to ON")
158 endif()
159
160 set(ORTHANC_ROOT ${CMAKE_BINARY_DIR}/orthanc)
161
162 if (EXISTS ${ORTHANC_ROOT})
163 message("Updating the Orthanc source repository using Mercurial")
164 execute_process(
165 COMMAND ${ORTHANC_FRAMEWORK_HG} pull
166 WORKING_DIRECTORY ${ORTHANC_ROOT}
167 RESULT_VARIABLE Failure
168 )
169 else()
170 message("Forking the Orthanc source repository using Mercurial")
171 execute_process(
172 COMMAND ${ORTHANC_FRAMEWORK_HG} clone "https://bitbucket.org/sjodogne/orthanc"
173 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
174 RESULT_VARIABLE Failure
175 )
176 endif()
177
178 if (Failure OR NOT EXISTS ${ORTHANC_ROOT})
179 message(FATAL_ERROR "Cannot fork the Orthanc repository")
180 endif()
181
182 message("Setting branch of the Orthanc repository to: ${ORTHANC_FRAMEWORK_BRANCH}")
183
184 execute_process(
185 COMMAND ${ORTHANC_FRAMEWORK_HG} update -c ${ORTHANC_FRAMEWORK_BRANCH}
186 WORKING_DIRECTORY ${ORTHANC_ROOT}
187 RESULT_VARIABLE Failure
188 )
189
190 if (Failure)
191 message(FATAL_ERROR "Error while running Mercurial")
192 endif()
193 endif()
194
195
196
197 ##
198 ## Case of the Orthanc framework provided as a source archive on the
199 ## filesystem
200 ##
201
202 if (ORTHANC_FRAMEWORK_SOURCE STREQUAL "archive")
203 if (NOT DEFINED ORTHANC_FRAMEWORK_ARCHIVE)
204 message(FATAL_ERROR "The variable ORTHANC_FRAMEWORK_ARCHIVE must provide the path to the sources of Orthanc")
205 endif()
206 endif()
207
208
209
210 ##
211 ## Case of the Orthanc framework downloaded from the Web
212 ##
213
214 if (ORTHANC_FRAMEWORK_SOURCE STREQUAL "web")
215 if (DEFINED ORTHANC_FRAMEWORK_URL)
216 string(REGEX REPLACE "^.*/" "" ORTHANC_FRAMEMORK_FILENAME "${ORTHANC_FRAMEWORK_URL}")
217 else()
218 # Default case: Download from the official Web site
219 set(ORTHANC_FRAMEMORK_FILENAME Orthanc-${ORTHANC_FRAMEWORK_VERSION}.tar.gz)
220 #set(ORTHANC_FRAMEWORK_URL "http://www.orthanc-server.com/downloads/get.php?path=/orthanc/${ORTHANC_FRAMEMORK_FILENAME}")
221 set(ORTHANC_FRAMEWORK_URL "http://www.orthanc-server.com/downloads/third-party/orthanc-framework/${ORTHANC_FRAMEMORK_FILENAME}")
222 endif()
223
224 set(ORTHANC_FRAMEWORK_ARCHIVE "${CMAKE_SOURCE_DIR}/ThirdPartyDownloads/${ORTHANC_FRAMEMORK_FILENAME}")
225
226 if (NOT EXISTS "${ORTHANC_FRAMEWORK_ARCHIVE}")
227 if (NOT STATIC_BUILD AND NOT ALLOW_DOWNLOADS)
228 message(FATAL_ERROR "CMake is not allowed to download from Internet. Please set the ALLOW_DOWNLOADS option to ON")
229 endif()
230
231 message("Downloading: ${ORTHANC_FRAMEWORK_URL}")
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 endif()
242 endif()
243
244
245
246
247 ##
248 ## Uncompressing the Orthanc framework, if it was retrieved from a
249 ## source archive on the filesystem, or from the official Web site
250 ##
251
252 if (ORTHANC_FRAMEWORK_SOURCE STREQUAL "archive" OR
253 ORTHANC_FRAMEWORK_SOURCE STREQUAL "web")
254
255 if (NOT DEFINED ORTHANC_FRAMEWORK_ARCHIVE OR
256 NOT DEFINED ORTHANC_FRAMEWORK_VERSION OR
257 NOT DEFINED ORTHANC_FRAMEWORK_MD5)
258 message(FATAL_ERROR "Internal error")
259 endif()
260
261 if (ORTHANC_FRAMEWORK_MD5 STREQUAL "")
262 message(FATAL_ERROR "Unknown release of Orthanc: ${ORTHANC_FRAMEWORK_VERSION}")
263 endif()
264
265 file(MD5 ${ORTHANC_FRAMEWORK_ARCHIVE} ActualMD5)
266
267 if (NOT "${ActualMD5}" STREQUAL "${ORTHANC_FRAMEWORK_MD5}")
268 message(FATAL_ERROR "The MD5 hash of the Orthanc archive is invalid: ${ORTHANC_FRAMEWORK_ARCHIVE}")
269 endif()
270
271 set(ORTHANC_ROOT "${CMAKE_BINARY_DIR}/Orthanc-${ORTHANC_FRAMEWORK_VERSION}")
272
273 if (NOT IS_DIRECTORY "${ORTHANC_ROOT}")
274 if (NOT ORTHANC_FRAMEWORK_ARCHIVE MATCHES ".tar.gz$")
275 message(FATAL_ERROR "Archive should have the \".tar.gz\" extension: ${ORTHANC_FRAMEWORK_ARCHIVE}")
276 endif()
277
278 message("Uncompressing: ${ORTHANC_FRAMEWORK_ARCHIVE}")
279
280 if ("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows")
281 # How to silently extract files using 7-zip
282 # http://superuser.com/questions/331148/7zip-command-line-extract-silently-quietly
283
284 execute_process(
285 COMMAND ${ORTHANC_FRAMEWORK_7ZIP} e -y ${ORTHANC_FRAMEWORK_ARCHIVE}
286 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
287 RESULT_VARIABLE Failure
288 OUTPUT_QUIET
289 )
290
291 if (Failure)
292 message(FATAL_ERROR "Error while running the uncompression tool")
293 endif()
294
295 get_filename_component(TMP_FILENAME "${ORTHANC_FRAMEWORK_ARCHIVE}" NAME)
296 string(REGEX REPLACE ".gz$" "" TMP_FILENAME2 "${TMP_FILENAME}")
297
298 execute_process(
299 COMMAND ${ORTHANC_FRAMEWORK_7ZIP} x -y ${TMP_FILENAME2}
300 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
301 RESULT_VARIABLE Failure
302 OUTPUT_QUIET
303 )
304
305 else()
306 execute_process(
307 COMMAND sh -c "${ORTHANC_FRAMEWORK_TAR} xfz ${ORTHANC_FRAMEWORK_ARCHIVE}"
308 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
309 RESULT_VARIABLE Failure
310 )
311 endif()
312
313 if (Failure)
314 message(FATAL_ERROR "Error while running the uncompression tool")
315 endif()
316
317 if (NOT IS_DIRECTORY "${ORTHANC_ROOT}")
318 message(FATAL_ERROR "The Orthanc framework was not uncompressed at the proper location. Check the CMake instructions.")
319 endif()
320 endif()
321 endif()