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