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