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