1
|
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-2020 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 set(ORTHANC_FRAMEWORK_MAJOR 999)
|
|
70 set(ORTHANC_FRAMEWORK_MINOR 999)
|
|
71 set(ORTHANC_FRAMEWORK_REVISION 999)
|
|
72
|
|
73 else()
|
|
74 set(ORTHANC_FRAMEWORK_BRANCH "Orthanc-${ORTHANC_FRAMEWORK_VERSION}")
|
|
75
|
|
76 set(RE "^([0-9]+)\\.([0-9]+)\\.([0-9]+)$")
|
|
77 string(REGEX REPLACE ${RE} "\\1" ORTHANC_FRAMEWORK_MAJOR ${ORTHANC_FRAMEWORK_VERSION})
|
|
78 string(REGEX REPLACE ${RE} "\\2" ORTHANC_FRAMEWORK_MINOR ${ORTHANC_FRAMEWORK_VERSION})
|
|
79 string(REGEX REPLACE ${RE} "\\3" ORTHANC_FRAMEWORK_REVISION ${ORTHANC_FRAMEWORK_VERSION})
|
|
80
|
|
81 if (NOT ORTHANC_FRAMEWORK_MAJOR MATCHES "^[0-9]+$" OR
|
|
82 NOT ORTHANC_FRAMEWORK_MINOR MATCHES "^[0-9]+$" OR
|
|
83 NOT ORTHANC_FRAMEWORK_REVISION MATCHES "^[0-9]+$")
|
|
84 message("Bad version of the Orthanc framework: ${ORTHANC_FRAMEWORK_VERSION}")
|
|
85 endif()
|
|
86
|
|
87 if (ORTHANC_FRAMEWORK_VERSION STREQUAL "1.3.1")
|
|
88 set(ORTHANC_FRAMEWORK_MD5 "dac95bd6cf86fb19deaf4e612961f378")
|
|
89 elseif (ORTHANC_FRAMEWORK_VERSION STREQUAL "1.3.2")
|
|
90 set(ORTHANC_FRAMEWORK_MD5 "d0ccdf68e855d8224331f13774992750")
|
|
91 elseif (ORTHANC_FRAMEWORK_VERSION STREQUAL "1.4.0")
|
|
92 set(ORTHANC_FRAMEWORK_MD5 "81e15f34d97ac32bbd7d26e85698835a")
|
|
93 elseif (ORTHANC_FRAMEWORK_VERSION STREQUAL "1.4.1")
|
|
94 set(ORTHANC_FRAMEWORK_MD5 "9b6f6114264b17ed421b574cd6476127")
|
|
95 elseif (ORTHANC_FRAMEWORK_VERSION STREQUAL "1.4.2")
|
|
96 set(ORTHANC_FRAMEWORK_MD5 "d1ee84927dcf668e60eb5868d24b9394")
|
|
97 elseif (ORTHANC_FRAMEWORK_VERSION STREQUAL "1.5.0")
|
|
98 set(ORTHANC_FRAMEWORK_MD5 "4429d8d9dea4ff6648df80ec3c64d79e")
|
|
99 elseif (ORTHANC_FRAMEWORK_VERSION STREQUAL "1.5.1")
|
|
100 set(ORTHANC_FRAMEWORK_MD5 "099671538865e5da96208b37494d6718")
|
|
101 elseif (ORTHANC_FRAMEWORK_VERSION STREQUAL "1.5.2")
|
|
102 set(ORTHANC_FRAMEWORK_MD5 "8867050f3e9a1ce6157c1ea7a9433b1b")
|
|
103 elseif (ORTHANC_FRAMEWORK_VERSION STREQUAL "1.5.3")
|
|
104 set(ORTHANC_FRAMEWORK_MD5 "bf2f5ed1adb8b0fc5f10d278e68e1dfe")
|
|
105 elseif (ORTHANC_FRAMEWORK_VERSION STREQUAL "1.5.4")
|
|
106 set(ORTHANC_FRAMEWORK_MD5 "404baef5d4c43e7c5d9410edda8ef5a5")
|
|
107 elseif (ORTHANC_FRAMEWORK_VERSION STREQUAL "1.5.5")
|
|
108 set(ORTHANC_FRAMEWORK_MD5 "cfc437e0687ae4bd725fd93dc1f08bc4")
|
|
109 elseif (ORTHANC_FRAMEWORK_VERSION STREQUAL "1.5.6")
|
|
110 set(ORTHANC_FRAMEWORK_MD5 "3c29de1e289b5472342947168f0105c0")
|
|
111 elseif (ORTHANC_FRAMEWORK_VERSION STREQUAL "1.5.7")
|
|
112 set(ORTHANC_FRAMEWORK_MD5 "e1b76f01116d9b5d4ac8cc39980560e3")
|
|
113 elseif (ORTHANC_FRAMEWORK_VERSION STREQUAL "1.5.8")
|
|
114 set(ORTHANC_FRAMEWORK_MD5 "82323e8c49a667f658a3639ea4dbc336")
|
|
115 elseif (ORTHANC_FRAMEWORK_VERSION STREQUAL "1.6.0")
|
|
116 set(ORTHANC_FRAMEWORK_MD5 "eab428d6e53f61e847fa360bb17ebe25")
|
|
117 elseif (ORTHANC_FRAMEWORK_VERSION STREQUAL "1.6.1")
|
|
118 set(ORTHANC_FRAMEWORK_MD5 "3971f5de96ba71dc9d3f3690afeaa7c0")
|
|
119 elseif (ORTHANC_FRAMEWORK_VERSION STREQUAL "1.7.0")
|
|
120 set(ORTHANC_FRAMEWORK_MD5 "ce5f689e852b01d3672bd3d2f952a5ef")
|
|
121
|
|
122 # Below this point are development snapshots that were used to
|
|
123 # release some plugin, before an official release of the Orthanc
|
|
124 # framework was available. Here is the command to be used to
|
|
125 # generate a proper archive:
|
|
126 #
|
|
127 # $ hg archive /tmp/Orthanc-`hg id -i | sed 's/\+//'`.tar.gz
|
|
128 #
|
|
129 elseif (ORTHANC_FRAMEWORK_VERSION STREQUAL "ae0e3fd609df")
|
|
130 # DICOMweb 1.1 (framework pre-1.6.0)
|
|
131 set(ORTHANC_FRAMEWORK_MD5 "7e09e9b530a2f527854f0b782d7e0645")
|
|
132 endif()
|
|
133 endif()
|
|
134 endif()
|
|
135 else()
|
|
136 message("Using the Orthanc framework from a path of the filesystem. Assuming mainline version.")
|
|
137 set(ORTHANC_FRAMEWORK_MAJOR 999)
|
|
138 set(ORTHANC_FRAMEWORK_MINOR 999)
|
|
139 set(ORTHANC_FRAMEWORK_REVISION 999)
|
|
140 endif()
|
|
141
|
|
142
|
|
143
|
|
144 ##
|
|
145 ## Detection of the third-party software
|
|
146 ##
|
|
147
|
|
148 if (ORTHANC_FRAMEWORK_SOURCE STREQUAL "hg")
|
|
149 find_program(ORTHANC_FRAMEWORK_HG hg)
|
|
150
|
|
151 if (${ORTHANC_FRAMEWORK_HG} MATCHES "ORTHANC_FRAMEWORK_HG-NOTFOUND")
|
|
152 message(FATAL_ERROR "Please install Mercurial")
|
|
153 endif()
|
|
154 endif()
|
|
155
|
|
156
|
|
157 if (ORTHANC_FRAMEWORK_SOURCE STREQUAL "archive" OR
|
|
158 ORTHANC_FRAMEWORK_SOURCE STREQUAL "web")
|
|
159 if ("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows")
|
|
160 find_program(ORTHANC_FRAMEWORK_7ZIP 7z
|
|
161 PATHS
|
|
162 "$ENV{ProgramFiles}/7-Zip"
|
|
163 "$ENV{ProgramW6432}/7-Zip"
|
|
164 )
|
|
165
|
|
166 if (${ORTHANC_FRAMEWORK_7ZIP} MATCHES "ORTHANC_FRAMEWORK_7ZIP-NOTFOUND")
|
|
167 message(FATAL_ERROR "Please install the '7-zip' software (http://www.7-zip.org/)")
|
|
168 endif()
|
|
169
|
|
170 else()
|
|
171 find_program(ORTHANC_FRAMEWORK_TAR tar)
|
|
172 if (${ORTHANC_FRAMEWORK_TAR} MATCHES "ORTHANC_FRAMEWORK_TAR-NOTFOUND")
|
|
173 message(FATAL_ERROR "Please install the 'tar' package")
|
|
174 endif()
|
|
175 endif()
|
|
176 endif()
|
|
177
|
|
178
|
|
179
|
|
180 ##
|
|
181 ## Case of the Orthanc framework specified as a path on the filesystem
|
|
182 ##
|
|
183
|
|
184 if (ORTHANC_FRAMEWORK_SOURCE STREQUAL "path")
|
|
185 if (NOT DEFINED ORTHANC_FRAMEWORK_ROOT)
|
|
186 message(FATAL_ERROR "The variable ORTHANC_FRAMEWORK_ROOT must provide the path to the sources of Orthanc")
|
|
187 endif()
|
|
188
|
|
189 if (NOT EXISTS ${ORTHANC_FRAMEWORK_ROOT})
|
|
190 message(FATAL_ERROR "Non-existing directory: ${ORTHANC_FRAMEWORK_ROOT}")
|
|
191 endif()
|
|
192
|
|
193 if (NOT EXISTS ${ORTHANC_FRAMEWORK_ROOT}/Resources/CMake/OrthancFrameworkParameters.cmake)
|
|
194 message(FATAL_ERROR "Directory not containing the source code of Orthanc: ${ORTHANC_FRAMEWORK_ROOT}")
|
|
195 endif()
|
|
196
|
|
197 set(ORTHANC_ROOT ${ORTHANC_FRAMEWORK_ROOT})
|
|
198 endif()
|
|
199
|
|
200
|
|
201
|
|
202 ##
|
|
203 ## Case of the Orthanc framework cloned using Mercurial
|
|
204 ##
|
|
205
|
|
206 if (ORTHANC_FRAMEWORK_SOURCE STREQUAL "hg")
|
|
207 if (NOT STATIC_BUILD AND NOT ALLOW_DOWNLOADS)
|
|
208 message(FATAL_ERROR "CMake is not allowed to download from Internet. Please set the ALLOW_DOWNLOADS option to ON")
|
|
209 endif()
|
|
210
|
|
211 set(ORTHANC_ROOT ${CMAKE_BINARY_DIR}/orthanc)
|
|
212
|
|
213 if (EXISTS ${ORTHANC_ROOT})
|
|
214 message("Updating the Orthanc source repository using Mercurial")
|
|
215 execute_process(
|
|
216 COMMAND ${ORTHANC_FRAMEWORK_HG} pull
|
|
217 WORKING_DIRECTORY ${ORTHANC_ROOT}
|
|
218 RESULT_VARIABLE Failure
|
|
219 )
|
|
220 else()
|
|
221 message("Forking the Orthanc source repository using Mercurial")
|
|
222 execute_process(
|
|
223 COMMAND ${ORTHANC_FRAMEWORK_HG} clone "https://hg.orthanc-server.com/orthanc/"
|
|
224 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
|
|
225 RESULT_VARIABLE Failure
|
|
226 )
|
|
227 endif()
|
|
228
|
|
229 if (Failure OR NOT EXISTS ${ORTHANC_ROOT})
|
|
230 message(FATAL_ERROR "Cannot fork the Orthanc repository")
|
|
231 endif()
|
|
232
|
|
233 message("Setting branch of the Orthanc repository to: ${ORTHANC_FRAMEWORK_BRANCH}")
|
|
234
|
|
235 execute_process(
|
|
236 COMMAND ${ORTHANC_FRAMEWORK_HG} update -c ${ORTHANC_FRAMEWORK_BRANCH}
|
|
237 WORKING_DIRECTORY ${ORTHANC_ROOT}
|
|
238 RESULT_VARIABLE Failure
|
|
239 )
|
|
240
|
|
241 if (Failure)
|
|
242 message(FATAL_ERROR "Error while running Mercurial")
|
|
243 endif()
|
|
244 endif()
|
|
245
|
|
246
|
|
247
|
|
248 ##
|
|
249 ## Case of the Orthanc framework provided as a source archive on the
|
|
250 ## filesystem
|
|
251 ##
|
|
252
|
|
253 if (ORTHANC_FRAMEWORK_SOURCE STREQUAL "archive")
|
|
254 if (NOT DEFINED ORTHANC_FRAMEWORK_ARCHIVE)
|
|
255 message(FATAL_ERROR "The variable ORTHANC_FRAMEWORK_ARCHIVE must provide the path to the sources of Orthanc")
|
|
256 endif()
|
|
257 endif()
|
|
258
|
|
259
|
|
260
|
|
261 ##
|
|
262 ## Case of the Orthanc framework downloaded from the Web
|
|
263 ##
|
|
264
|
|
265 if (ORTHANC_FRAMEWORK_SOURCE STREQUAL "web")
|
|
266 if (DEFINED ORTHANC_FRAMEWORK_URL)
|
|
267 string(REGEX REPLACE "^.*/" "" ORTHANC_FRAMEMORK_FILENAME "${ORTHANC_FRAMEWORK_URL}")
|
|
268 else()
|
|
269 # Default case: Download from the official Web site
|
|
270 set(ORTHANC_FRAMEMORK_FILENAME Orthanc-${ORTHANC_FRAMEWORK_VERSION}.tar.gz)
|
|
271 set(ORTHANC_FRAMEWORK_URL "http://orthanc.osimis.io/ThirdPartyDownloads/orthanc-framework/${ORTHANC_FRAMEMORK_FILENAME}")
|
|
272 endif()
|
|
273
|
|
274 set(ORTHANC_FRAMEWORK_ARCHIVE "${CMAKE_SOURCE_DIR}/ThirdPartyDownloads/${ORTHANC_FRAMEMORK_FILENAME}")
|
|
275
|
|
276 if (NOT EXISTS "${ORTHANC_FRAMEWORK_ARCHIVE}")
|
|
277 if (NOT STATIC_BUILD AND NOT ALLOW_DOWNLOADS)
|
|
278 message(FATAL_ERROR "CMake is not allowed to download from Internet. Please set the ALLOW_DOWNLOADS option to ON")
|
|
279 endif()
|
|
280
|
|
281 message("Downloading: ${ORTHANC_FRAMEWORK_URL}")
|
|
282
|
|
283 file(DOWNLOAD
|
|
284 "${ORTHANC_FRAMEWORK_URL}" "${ORTHANC_FRAMEWORK_ARCHIVE}"
|
|
285 SHOW_PROGRESS EXPECTED_MD5 "${ORTHANC_FRAMEWORK_MD5}"
|
|
286 TIMEOUT 60
|
|
287 INACTIVITY_TIMEOUT 60
|
|
288 )
|
|
289 else()
|
|
290 message("Using local copy of: ${ORTHANC_FRAMEWORK_URL}")
|
|
291 endif()
|
|
292 endif()
|
|
293
|
|
294
|
|
295
|
|
296
|
|
297 ##
|
|
298 ## Uncompressing the Orthanc framework, if it was retrieved from a
|
|
299 ## source archive on the filesystem, or from the official Web site
|
|
300 ##
|
|
301
|
|
302 if (ORTHANC_FRAMEWORK_SOURCE STREQUAL "archive" OR
|
|
303 ORTHANC_FRAMEWORK_SOURCE STREQUAL "web")
|
|
304
|
|
305 if (NOT DEFINED ORTHANC_FRAMEWORK_ARCHIVE OR
|
|
306 NOT DEFINED ORTHANC_FRAMEWORK_VERSION OR
|
|
307 NOT DEFINED ORTHANC_FRAMEWORK_MD5)
|
|
308 message(FATAL_ERROR "Internal error")
|
|
309 endif()
|
|
310
|
|
311 if (ORTHANC_FRAMEWORK_MD5 STREQUAL "")
|
|
312 message(FATAL_ERROR "Unknown release of Orthanc: ${ORTHANC_FRAMEWORK_VERSION}")
|
|
313 endif()
|
|
314
|
|
315 file(MD5 ${ORTHANC_FRAMEWORK_ARCHIVE} ActualMD5)
|
|
316
|
|
317 if (NOT "${ActualMD5}" STREQUAL "${ORTHANC_FRAMEWORK_MD5}")
|
|
318 message(FATAL_ERROR "The MD5 hash of the Orthanc archive is invalid: ${ORTHANC_FRAMEWORK_ARCHIVE}")
|
|
319 endif()
|
|
320
|
|
321 set(ORTHANC_ROOT "${CMAKE_BINARY_DIR}/Orthanc-${ORTHANC_FRAMEWORK_VERSION}")
|
|
322
|
|
323 if (NOT IS_DIRECTORY "${ORTHANC_ROOT}")
|
|
324 if (NOT ORTHANC_FRAMEWORK_ARCHIVE MATCHES ".tar.gz$")
|
|
325 message(FATAL_ERROR "Archive should have the \".tar.gz\" extension: ${ORTHANC_FRAMEWORK_ARCHIVE}")
|
|
326 endif()
|
|
327
|
|
328 message("Uncompressing: ${ORTHANC_FRAMEWORK_ARCHIVE}")
|
|
329
|
|
330 if ("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows")
|
|
331 # How to silently extract files using 7-zip
|
|
332 # http://superuser.com/questions/331148/7zip-command-line-extract-silently-quietly
|
|
333
|
|
334 execute_process(
|
|
335 COMMAND ${ORTHANC_FRAMEWORK_7ZIP} e -y ${ORTHANC_FRAMEWORK_ARCHIVE}
|
|
336 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
|
|
337 RESULT_VARIABLE Failure
|
|
338 OUTPUT_QUIET
|
|
339 )
|
|
340
|
|
341 if (Failure)
|
|
342 message(FATAL_ERROR "Error while running the uncompression tool")
|
|
343 endif()
|
|
344
|
|
345 get_filename_component(TMP_FILENAME "${ORTHANC_FRAMEWORK_ARCHIVE}" NAME)
|
|
346 string(REGEX REPLACE ".gz$" "" TMP_FILENAME2 "${TMP_FILENAME}")
|
|
347
|
|
348 execute_process(
|
|
349 COMMAND ${ORTHANC_FRAMEWORK_7ZIP} x -y ${TMP_FILENAME2}
|
|
350 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
|
|
351 RESULT_VARIABLE Failure
|
|
352 OUTPUT_QUIET
|
|
353 )
|
|
354
|
|
355 else()
|
|
356 execute_process(
|
|
357 COMMAND sh -c "${ORTHANC_FRAMEWORK_TAR} xfz ${ORTHANC_FRAMEWORK_ARCHIVE}"
|
|
358 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
|
|
359 RESULT_VARIABLE Failure
|
|
360 )
|
|
361 endif()
|
|
362
|
|
363 if (Failure)
|
|
364 message(FATAL_ERROR "Error while running the uncompression tool")
|
|
365 endif()
|
|
366
|
|
367 if (NOT IS_DIRECTORY "${ORTHANC_ROOT}")
|
|
368 message(FATAL_ERROR "The Orthanc framework was not uncompressed at the proper location. Check the CMake instructions.")
|
|
369 endif()
|
|
370 endif()
|
|
371 endif()
|
|
372
|