Mercurial > hg > orthanc
annotate Resources/CMake/DownloadPackage.cmake @ 2451:a4032b162502
lsb working
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 03 Jan 2018 13:07:57 +0100 |
parents | 5d8e6fab98dd |
children | 3eda46f91834 |
rev | line source |
---|---|
735 | 1 macro(GetUrlFilename TargetVariable Url) |
2 string(REGEX REPLACE "^.*/" "" ${TargetVariable} "${Url}") | |
3 endmacro() | |
4 | |
5 | |
6 macro(GetUrlExtension TargetVariable Url) | |
7 #string(REGEX REPLACE "^.*/[^.]*\\." "" TMP "${Url}") | |
8 string(REGEX REPLACE "^.*\\." "" TMP "${Url}") | |
9 string(TOLOWER "${TMP}" "${TargetVariable}") | |
10 endmacro() | |
11 | |
12 | |
1537
fbf763bb1fa3
error detection in patches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1111
diff
changeset
|
13 |
fbf763bb1fa3
error detection in patches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1111
diff
changeset
|
14 ## |
fbf763bb1fa3
error detection in patches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1111
diff
changeset
|
15 ## Setup the patch command-line tool |
fbf763bb1fa3
error detection in patches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1111
diff
changeset
|
16 ## |
fbf763bb1fa3
error detection in patches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1111
diff
changeset
|
17 |
2130
72cb107a7346
option ORTHANC_DISABLE_PATCH
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2111
diff
changeset
|
18 if (NOT ORTHANC_DISABLE_PATCH) |
72cb107a7346
option ORTHANC_DISABLE_PATCH
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2111
diff
changeset
|
19 if ("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows") |
72cb107a7346
option ORTHANC_DISABLE_PATCH
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2111
diff
changeset
|
20 set(PATCH_EXECUTABLE ${CMAKE_CURRENT_LIST_DIR}/../ThirdParty/patch/patch.exe) |
72cb107a7346
option ORTHANC_DISABLE_PATCH
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2111
diff
changeset
|
21 if (NOT EXISTS ${PATCH_EXECUTABLE}) |
72cb107a7346
option ORTHANC_DISABLE_PATCH
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2111
diff
changeset
|
22 message(FATAL_ERROR "Unable to find the patch.exe tool that is shipped with Orthanc") |
72cb107a7346
option ORTHANC_DISABLE_PATCH
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2111
diff
changeset
|
23 endif() |
2111 | 24 |
2130
72cb107a7346
option ORTHANC_DISABLE_PATCH
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2111
diff
changeset
|
25 else () |
72cb107a7346
option ORTHANC_DISABLE_PATCH
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2111
diff
changeset
|
26 find_program(PATCH_EXECUTABLE patch) |
72cb107a7346
option ORTHANC_DISABLE_PATCH
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2111
diff
changeset
|
27 if (${PATCH_EXECUTABLE} MATCHES "PATCH_EXECUTABLE-NOTFOUND") |
72cb107a7346
option ORTHANC_DISABLE_PATCH
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2111
diff
changeset
|
28 message(FATAL_ERROR "Please install the 'patch' standard command-line tool") |
72cb107a7346
option ORTHANC_DISABLE_PATCH
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2111
diff
changeset
|
29 endif() |
1537
fbf763bb1fa3
error detection in patches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1111
diff
changeset
|
30 endif() |
fbf763bb1fa3
error detection in patches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1111
diff
changeset
|
31 endif() |
fbf763bb1fa3
error detection in patches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1111
diff
changeset
|
32 |
fbf763bb1fa3
error detection in patches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1111
diff
changeset
|
33 |
fbf763bb1fa3
error detection in patches
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1111
diff
changeset
|
34 |
735 | 35 ## |
36 ## Check the existence of the required decompression tools | |
37 ## | |
38 | |
39 if ("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows") | |
1111
929bf8c2123d
Fixes for Visual Studio 2013 64bit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
735
diff
changeset
|
40 find_program(ZIP_EXECUTABLE 7z |
929bf8c2123d
Fixes for Visual Studio 2013 64bit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
735
diff
changeset
|
41 PATHS |
929bf8c2123d
Fixes for Visual Studio 2013 64bit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
735
diff
changeset
|
42 "$ENV{ProgramFiles}/7-Zip" |
929bf8c2123d
Fixes for Visual Studio 2013 64bit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
735
diff
changeset
|
43 "$ENV{ProgramW6432}/7-Zip" |
929bf8c2123d
Fixes for Visual Studio 2013 64bit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
735
diff
changeset
|
44 ) |
929bf8c2123d
Fixes for Visual Studio 2013 64bit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
735
diff
changeset
|
45 |
735 | 46 if (${ZIP_EXECUTABLE} MATCHES "ZIP_EXECUTABLE-NOTFOUND") |
47 message(FATAL_ERROR "Please install the '7-zip' software (http://www.7-zip.org/)") | |
48 endif() | |
49 | |
50 else() | |
51 find_program(UNZIP_EXECUTABLE unzip) | |
52 if (${UNZIP_EXECUTABLE} MATCHES "UNZIP_EXECUTABLE-NOTFOUND") | |
53 message(FATAL_ERROR "Please install the 'unzip' package") | |
54 endif() | |
55 | |
56 find_program(TAR_EXECUTABLE tar) | |
57 if (${TAR_EXECUTABLE} MATCHES "TAR_EXECUTABLE-NOTFOUND") | |
58 message(FATAL_ERROR "Please install the 'tar' package") | |
59 endif() | |
60 endif() | |
61 | |
62 | |
63 macro(DownloadPackage MD5 Url TargetDirectory) | |
64 if (NOT IS_DIRECTORY "${TargetDirectory}") | |
65 GetUrlFilename(TMP_FILENAME "${Url}") | |
66 | |
67 set(TMP_PATH "${CMAKE_SOURCE_DIR}/ThirdPartyDownloads/${TMP_FILENAME}") | |
68 if (NOT EXISTS "${TMP_PATH}") | |
69 message("Downloading ${Url}") | |
70 | |
71 # This fixes issue 6: "I think cmake shouldn't download the | |
72 # packages which are not in the system, it should stop and let | |
73 # user know." | |
74 # https://code.google.com/p/orthanc/issues/detail?id=6 | |
75 if (NOT STATIC_BUILD AND NOT ALLOW_DOWNLOADS) | |
76 message(FATAL_ERROR "CMake is not allowed to download from Internet. Please set the ALLOW_DOWNLOADS option to ON") | |
77 endif() | |
78 | |
2153
47daf8022808
added download timeout for os x
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2130
diff
changeset
|
79 file(DOWNLOAD "${Url}" "${TMP_PATH}" |
47daf8022808
added download timeout for os x
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2130
diff
changeset
|
80 SHOW_PROGRESS EXPECTED_MD5 "${MD5}" |
2154
5d8e6fab98dd
increased timeout for buildbot
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2153
diff
changeset
|
81 TIMEOUT 60 INACTIVITY_TIMEOUT 60) |
735 | 82 else() |
83 message("Using local copy of ${Url}") | |
84 endif() | |
85 | |
86 GetUrlExtension(TMP_EXTENSION "${Url}") | |
87 #message(${TMP_EXTENSION}) | |
88 message("Uncompressing ${TMP_FILENAME}") | |
89 | |
90 if ("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows") | |
91 # How to silently extract files using 7-zip | |
92 # http://superuser.com/questions/331148/7zip-command-line-extract-silently-quietly | |
93 | |
2001
1d3a7c7d84c1
download of xz packages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1543
diff
changeset
|
94 if (("${TMP_EXTENSION}" STREQUAL "gz") OR |
1d3a7c7d84c1
download of xz packages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1543
diff
changeset
|
95 ("${TMP_EXTENSION}" STREQUAL "tgz") OR |
1d3a7c7d84c1
download of xz packages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1543
diff
changeset
|
96 ("${TMP_EXTENSION}" STREQUAL "xz")) |
735 | 97 execute_process( |
98 COMMAND ${ZIP_EXECUTABLE} e -y ${TMP_PATH} | |
99 WORKING_DIRECTORY ${CMAKE_BINARY_DIR} | |
100 RESULT_VARIABLE Failure | |
101 OUTPUT_QUIET | |
102 ) | |
103 | |
104 if (Failure) | |
105 message(FATAL_ERROR "Error while running the uncompression tool") | |
106 endif() | |
107 | |
108 if ("${TMP_EXTENSION}" STREQUAL "tgz") | |
109 string(REGEX REPLACE ".tgz$" ".tar" TMP_FILENAME2 "${TMP_FILENAME}") | |
2001
1d3a7c7d84c1
download of xz packages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1543
diff
changeset
|
110 elseif ("${TMP_EXTENSION}" STREQUAL "gz") |
735 | 111 string(REGEX REPLACE ".gz$" "" TMP_FILENAME2 "${TMP_FILENAME}") |
2001
1d3a7c7d84c1
download of xz packages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1543
diff
changeset
|
112 elseif ("${TMP_EXTENSION}" STREQUAL "xz") |
1d3a7c7d84c1
download of xz packages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1543
diff
changeset
|
113 string(REGEX REPLACE ".xz" "" TMP_FILENAME2 "${TMP_FILENAME}") |
735 | 114 endif() |
115 | |
116 execute_process( | |
117 COMMAND ${ZIP_EXECUTABLE} x -y ${TMP_FILENAME2} | |
118 WORKING_DIRECTORY ${CMAKE_BINARY_DIR} | |
119 RESULT_VARIABLE Failure | |
120 OUTPUT_QUIET | |
121 ) | |
122 elseif ("${TMP_EXTENSION}" STREQUAL "zip") | |
123 execute_process( | |
124 COMMAND ${ZIP_EXECUTABLE} x -y ${TMP_PATH} | |
125 WORKING_DIRECTORY ${CMAKE_BINARY_DIR} | |
126 RESULT_VARIABLE Failure | |
127 OUTPUT_QUIET | |
128 ) | |
129 else() | |
130 message(FATAL_ERROR "Support your platform here") | |
131 endif() | |
132 | |
133 else() | |
134 if ("${TMP_EXTENSION}" STREQUAL "zip") | |
135 execute_process( | |
136 COMMAND sh -c "${UNZIP_EXECUTABLE} -q ${TMP_PATH}" | |
137 WORKING_DIRECTORY ${CMAKE_BINARY_DIR} | |
138 RESULT_VARIABLE Failure | |
139 ) | |
140 elseif (("${TMP_EXTENSION}" STREQUAL "gz") OR ("${TMP_EXTENSION}" STREQUAL "tgz")) | |
141 #message("tar xvfz ${TMP_PATH}") | |
142 execute_process( | |
143 COMMAND sh -c "${TAR_EXECUTABLE} xfz ${TMP_PATH}" | |
144 WORKING_DIRECTORY ${CMAKE_BINARY_DIR} | |
145 RESULT_VARIABLE Failure | |
146 ) | |
147 elseif ("${TMP_EXTENSION}" STREQUAL "bz2") | |
148 execute_process( | |
149 COMMAND sh -c "${TAR_EXECUTABLE} xfj ${TMP_PATH}" | |
150 WORKING_DIRECTORY ${CMAKE_BINARY_DIR} | |
151 RESULT_VARIABLE Failure | |
152 ) | |
2002 | 153 elseif ("${TMP_EXTENSION}" STREQUAL "xz") |
154 execute_process( | |
155 COMMAND sh -c "${TAR_EXECUTABLE} xf ${TMP_PATH}" | |
156 WORKING_DIRECTORY ${CMAKE_BINARY_DIR} | |
157 RESULT_VARIABLE Failure | |
158 ) | |
735 | 159 else() |
160 message(FATAL_ERROR "Unknown package format.") | |
161 endif() | |
162 endif() | |
163 | |
164 if (Failure) | |
165 message(FATAL_ERROR "Error while running the uncompression tool") | |
166 endif() | |
167 | |
168 if (NOT IS_DIRECTORY "${TargetDirectory}") | |
169 message(FATAL_ERROR "The package was not uncompressed at the proper location. Check the CMake instructions.") | |
170 endif() | |
171 endif() | |
172 endmacro() |