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