Mercurial > hg > orthanc
annotate Resources/CMake/DownloadPackage.cmake @ 1947:c1053112b323
Switch to the C++11 standard if the version of JsonCpp is 1.y.z
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 05 Apr 2016 10:11:40 +0200 |
parents | 8b6d8f9b9f71 |
children | 1d3a7c7d84c1 |
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 | |
86 if (("${TMP_EXTENSION}" STREQUAL "gz") OR ("${TMP_EXTENSION}" STREQUAL "tgz")) | |
87 execute_process( | |
88 COMMAND ${ZIP_EXECUTABLE} e -y ${TMP_PATH} | |
89 WORKING_DIRECTORY ${CMAKE_BINARY_DIR} | |
90 RESULT_VARIABLE Failure | |
91 OUTPUT_QUIET | |
92 ) | |
93 | |
94 if (Failure) | |
95 message(FATAL_ERROR "Error while running the uncompression tool") | |
96 endif() | |
97 | |
98 if ("${TMP_EXTENSION}" STREQUAL "tgz") | |
99 string(REGEX REPLACE ".tgz$" ".tar" TMP_FILENAME2 "${TMP_FILENAME}") | |
100 else() | |
101 string(REGEX REPLACE ".gz$" "" TMP_FILENAME2 "${TMP_FILENAME}") | |
102 endif() | |
103 | |
104 execute_process( | |
105 COMMAND ${ZIP_EXECUTABLE} x -y ${TMP_FILENAME2} | |
106 WORKING_DIRECTORY ${CMAKE_BINARY_DIR} | |
107 RESULT_VARIABLE Failure | |
108 OUTPUT_QUIET | |
109 ) | |
110 elseif ("${TMP_EXTENSION}" STREQUAL "zip") | |
111 execute_process( | |
112 COMMAND ${ZIP_EXECUTABLE} x -y ${TMP_PATH} | |
113 WORKING_DIRECTORY ${CMAKE_BINARY_DIR} | |
114 RESULT_VARIABLE Failure | |
115 OUTPUT_QUIET | |
116 ) | |
117 else() | |
118 message(FATAL_ERROR "Support your platform here") | |
119 endif() | |
120 | |
121 else() | |
122 if ("${TMP_EXTENSION}" STREQUAL "zip") | |
123 execute_process( | |
124 COMMAND sh -c "${UNZIP_EXECUTABLE} -q ${TMP_PATH}" | |
125 WORKING_DIRECTORY ${CMAKE_BINARY_DIR} | |
126 RESULT_VARIABLE Failure | |
127 ) | |
128 elseif (("${TMP_EXTENSION}" STREQUAL "gz") OR ("${TMP_EXTENSION}" STREQUAL "tgz")) | |
129 #message("tar xvfz ${TMP_PATH}") | |
130 execute_process( | |
131 COMMAND sh -c "${TAR_EXECUTABLE} xfz ${TMP_PATH}" | |
132 WORKING_DIRECTORY ${CMAKE_BINARY_DIR} | |
133 RESULT_VARIABLE Failure | |
134 ) | |
135 elseif ("${TMP_EXTENSION}" STREQUAL "bz2") | |
136 execute_process( | |
137 COMMAND sh -c "${TAR_EXECUTABLE} xfj ${TMP_PATH}" | |
138 WORKING_DIRECTORY ${CMAKE_BINARY_DIR} | |
139 RESULT_VARIABLE Failure | |
140 ) | |
141 else() | |
142 message(FATAL_ERROR "Unknown package format.") | |
143 endif() | |
144 endif() | |
145 | |
146 if (Failure) | |
147 message(FATAL_ERROR "Error while running the uncompression tool") | |
148 endif() | |
149 | |
150 if (NOT IS_DIRECTORY "${TargetDirectory}") | |
151 message(FATAL_ERROR "The package was not uncompressed at the proper location. Check the CMake instructions.") | |
152 endif() | |
153 endif() | |
154 endmacro() |