annotate Resources/CMake/DownloadPackage.cmake @ 638:92aa6df91c30

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