annotate Resources/CMake/DownloadPackage.cmake @ 813:b640aeee11ba

fix
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 08 May 2014 15:15:55 +0200
parents ee0d5abf7958
children 929bf8c2123d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
735
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
1 macro(GetUrlFilename TargetVariable Url)
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
2 string(REGEX REPLACE "^.*/" "" ${TargetVariable} "${Url}")
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
3 endmacro()
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
4
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
5
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
6 macro(GetUrlExtension TargetVariable Url)
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
7 #string(REGEX REPLACE "^.*/[^.]*\\." "" TMP "${Url}")
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
8 string(REGEX REPLACE "^.*\\." "" TMP "${Url}")
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
9 string(TOLOWER "${TMP}" "${TargetVariable}")
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
10 endmacro()
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
11
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
12
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
13 ##
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
14 ## Check the existence of the required decompression tools
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
15 ##
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
16
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
17 if ("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows")
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
18 find_program(ZIP_EXECUTABLE 7z PATHS "$ENV{ProgramFiles}/7-Zip")
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
19 if (${ZIP_EXECUTABLE} MATCHES "ZIP_EXECUTABLE-NOTFOUND")
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
20 message(FATAL_ERROR "Please install the '7-zip' software (http://www.7-zip.org/)")
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
21 endif()
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
22
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
23 else()
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
24 find_program(UNZIP_EXECUTABLE unzip)
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
25 if (${UNZIP_EXECUTABLE} MATCHES "UNZIP_EXECUTABLE-NOTFOUND")
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
26 message(FATAL_ERROR "Please install the 'unzip' package")
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
27 endif()
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
28
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
29 find_program(TAR_EXECUTABLE tar)
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
30 if (${TAR_EXECUTABLE} MATCHES "TAR_EXECUTABLE-NOTFOUND")
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
31 message(FATAL_ERROR "Please install the 'tar' package")
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
32 endif()
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
33 endif()
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
34
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
35
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
36 macro(DownloadPackage MD5 Url TargetDirectory)
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
37 if (NOT IS_DIRECTORY "${TargetDirectory}")
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
38 GetUrlFilename(TMP_FILENAME "${Url}")
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
39
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
40 set(TMP_PATH "${CMAKE_SOURCE_DIR}/ThirdPartyDownloads/${TMP_FILENAME}")
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
41 if (NOT EXISTS "${TMP_PATH}")
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
42 message("Downloading ${Url}")
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
43
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
44 # This fixes issue 6: "I think cmake shouldn't download the
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
45 # packages which are not in the system, it should stop and let
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
46 # user know."
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
47 # https://code.google.com/p/orthanc/issues/detail?id=6
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
48 if (NOT STATIC_BUILD AND NOT ALLOW_DOWNLOADS)
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
49 message(FATAL_ERROR "CMake is not allowed to download from Internet. Please set the ALLOW_DOWNLOADS option to ON")
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
50 endif()
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
51
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
52 file(DOWNLOAD "${Url}" "${TMP_PATH}" SHOW_PROGRESS EXPECTED_MD5 "${MD5}")
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
53 else()
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
54 message("Using local copy of ${Url}")
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
55 endif()
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
56
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
57 GetUrlExtension(TMP_EXTENSION "${Url}")
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
58 #message(${TMP_EXTENSION})
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
59 message("Uncompressing ${TMP_FILENAME}")
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
60
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
61 if ("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows")
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
62 # How to silently extract files using 7-zip
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
63 # http://superuser.com/questions/331148/7zip-command-line-extract-silently-quietly
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
64
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
65 if (("${TMP_EXTENSION}" STREQUAL "gz") OR ("${TMP_EXTENSION}" STREQUAL "tgz"))
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
66 execute_process(
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
67 COMMAND ${ZIP_EXECUTABLE} e -y ${TMP_PATH}
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
68 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
69 RESULT_VARIABLE Failure
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
70 OUTPUT_QUIET
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
71 )
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
72
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
73 if (Failure)
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
74 message(FATAL_ERROR "Error while running the uncompression tool")
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
75 endif()
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
76
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
77 if ("${TMP_EXTENSION}" STREQUAL "tgz")
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
78 string(REGEX REPLACE ".tgz$" ".tar" TMP_FILENAME2 "${TMP_FILENAME}")
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
79 else()
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
80 string(REGEX REPLACE ".gz$" "" TMP_FILENAME2 "${TMP_FILENAME}")
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
81 endif()
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
82
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
83 execute_process(
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
84 COMMAND ${ZIP_EXECUTABLE} x -y ${TMP_FILENAME2}
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
85 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
86 RESULT_VARIABLE Failure
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
87 OUTPUT_QUIET
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
88 )
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
89 elseif ("${TMP_EXTENSION}" STREQUAL "zip")
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
90 execute_process(
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
91 COMMAND ${ZIP_EXECUTABLE} x -y ${TMP_PATH}
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
92 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
93 RESULT_VARIABLE Failure
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
94 OUTPUT_QUIET
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
95 )
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
96 else()
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
97 message(FATAL_ERROR "Support your platform here")
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
98 endif()
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
99
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
100 else()
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
101 if ("${TMP_EXTENSION}" STREQUAL "zip")
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
102 execute_process(
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
103 COMMAND sh -c "${UNZIP_EXECUTABLE} -q ${TMP_PATH}"
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
104 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
105 RESULT_VARIABLE Failure
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
106 )
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
107 elseif (("${TMP_EXTENSION}" STREQUAL "gz") OR ("${TMP_EXTENSION}" STREQUAL "tgz"))
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
108 #message("tar xvfz ${TMP_PATH}")
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
109 execute_process(
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
110 COMMAND sh -c "${TAR_EXECUTABLE} xfz ${TMP_PATH}"
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
111 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
112 RESULT_VARIABLE Failure
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
113 )
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
114 elseif ("${TMP_EXTENSION}" STREQUAL "bz2")
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
115 execute_process(
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
116 COMMAND sh -c "${TAR_EXECUTABLE} xfj ${TMP_PATH}"
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
117 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
118 RESULT_VARIABLE Failure
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
119 )
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
120 else()
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
121 message(FATAL_ERROR "Unknown package format.")
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
122 endif()
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
123 endif()
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
124
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
125 if (Failure)
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
126 message(FATAL_ERROR "Error while running the uncompression tool")
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
127 endif()
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
128
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
129 if (NOT IS_DIRECTORY "${TargetDirectory}")
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
130 message(FATAL_ERROR "The package was not uncompressed at the proper location. Check the CMake instructions.")
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
131 endif()
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
132 endif()
ee0d5abf7958 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 634
diff changeset
133 endmacro()