comparison Resources/Orthanc/DownloadOrthancFramework.cmake @ 0:7cea966b6829

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