annotate Resources/CMake/DownloadPackage.cmake @ 114:b4f1191768eb

fix
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 04 Oct 2012 14:35:53 +0200
parents b00a6c68d529
children 37b066ee2988
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
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
13 macro(DownloadPackage Url TargetDirectory PreloadedVariable UncompressArguments)
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
14 if (NOT IS_DIRECTORY "${TargetDirectory}")
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
15 GetUrlFilename(TMP_FILENAME "${Url}")
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
16 if ("${PreloadedVariable}" STREQUAL "")
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
17 set(TMP_PATH "${CMAKE_SOURCE_DIR}/ThirdPartyDownloads/${TMP_FILENAME}")
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
18 if (NOT EXISTS "${TMP_PATH}")
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
19 message("Downloading ${Url}")
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
20 file(DOWNLOAD "${Url}" "${TMP_PATH}" SHOW_PROGRESS)
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
21 else()
113
b00a6c68d529 clearer messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
22 message("Using local copy of ${Url}")
2
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
23 endif()
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
24 else()
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
25 message("Using preloaded archive ${PreloadedVariable} for ${Url}")
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
26 set(TMP_PATH "${PreloadedVariable}")
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
27 endif()
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
28
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
29 GetUrlExtension(TMP_EXTENSION "${Url}")
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
30 #message(${TMP_EXTENSION})
113
b00a6c68d529 clearer messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
31 message("Uncompressing ${TMP_FILENAME}")
2
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
32
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
33 if ("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Linux")
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
34 if ("${TMP_EXTENSION}" STREQUAL "zip")
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
35 execute_process(
74
09718f2fc5cb silent unzip
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 21
diff changeset
36 COMMAND sh -c "unzip -q ${TMP_PATH} ${UncompressArguments}"
2
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
37 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
21
29bfa3095207 check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
38 RESULT_VARIABLE Failure
29bfa3095207 check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
39 )
2
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
40 elseif (("${TMP_EXTENSION}" STREQUAL "gz") OR ("${TMP_EXTENSION}" STREQUAL "tgz"))
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
41 #message("tar xvfz ${TMP_PATH} ${UncompressArguments}")
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
42 execute_process(
74
09718f2fc5cb silent unzip
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 21
diff changeset
43 COMMAND sh -c "tar xfz ${TMP_PATH} ${UncompressArguments}"
2
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
44 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
21
29bfa3095207 check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
45 RESULT_VARIABLE Failure
2
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
46 )
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
47 elseif ("${TMP_EXTENSION}" STREQUAL "bz2")
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
48 execute_process(
74
09718f2fc5cb silent unzip
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 21
diff changeset
49 COMMAND sh -c "tar xfj ${TMP_PATH} ${UncompressArguments}"
2
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
50 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
21
29bfa3095207 check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
51 RESULT_VARIABLE Failure
2
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
52 )
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
53 else()
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
54 message(FATAL_ERROR "Unknown package format.")
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 elseif ("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows")
77
b8dfde8d64e8 new dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 75
diff changeset
58 # How to silently extract files using 7-zip
b8dfde8d64e8 new dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 75
diff changeset
59 # 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
60
2
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
61 FIND_PROGRAM(ZIP_EXECUTABLE 7z PATHS "$ENV{ProgramFiles}/7-Zip")
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
62
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
63 if (("${TMP_EXTENSION}" STREQUAL "gz") OR ("${TMP_EXTENSION}" STREQUAL "tgz"))
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
64 execute_process(
75
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
65 COMMAND ${ZIP_EXECUTABLE} e -y ${TMP_PATH}
2
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
66 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
21
29bfa3095207 check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
67 RESULT_VARIABLE Failure
74
09718f2fc5cb silent unzip
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 21
diff changeset
68 OUTPUT_QUIET
2
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
69 )
21
29bfa3095207 check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
70
29bfa3095207 check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
71 if (Failure)
29bfa3095207 check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
72 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
73 endif()
29bfa3095207 check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
74
2
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
75 set(ARGS ${UncompressArguments})
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
76 SEPARATE_ARGUMENTS(ARGS)
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
77 list(LENGTH ARGS TMP_LENGTH)
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
78
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
79 if ("${TMP_EXTENSION}" STREQUAL "tgz")
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
80 string(REGEX REPLACE ".tgz$" ".tar" TMP_FILENAME2 "${TMP_FILENAME}")
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
81 else()
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
82 string(REGEX REPLACE ".gz$" "" TMP_FILENAME2 "${TMP_FILENAME}")
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
83 endif()
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
84
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
85 if (TMP_LENGTH EQUAL 0)
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
86 execute_process(
75
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
87 COMMAND ${ZIP_EXECUTABLE} x -y ${TMP_FILENAME2}
2
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
88 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
21
29bfa3095207 check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
89 RESULT_VARIABLE Failure
74
09718f2fc5cb silent unzip
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 21
diff changeset
90 OUTPUT_QUIET
2
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
91 )
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
92 else()
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
93 foreach(SUBDIR ${ARGS})
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
94 execute_process(
75
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
95 COMMAND ${ZIP_EXECUTABLE} x -y "-i!${SUBDIR}" "${TMP_FILENAME2}"
2
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
96 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
21
29bfa3095207 check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
97 RESULT_VARIABLE Failure
74
09718f2fc5cb silent unzip
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 21
diff changeset
98 OUTPUT_QUIET
2
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
99 )
21
29bfa3095207 check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
100
29bfa3095207 check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
101 if (Failure)
29bfa3095207 check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
102 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
103 endif()
2
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
104 endforeach()
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
105 endif()
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
106 elseif ("${TMP_EXTENSION}" STREQUAL "zip")
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
107 execute_process(
75
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
108 COMMAND ${ZIP_EXECUTABLE} x -y ${TMP_PATH}
2
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
109 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
21
29bfa3095207 check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
110 RESULT_VARIABLE Failure
74
09718f2fc5cb silent unzip
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 21
diff changeset
111 OUTPUT_QUIET
2
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
112 )
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
113 else()
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
114 message(FATAL_ERROR "Support your platform here")
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
115 endif()
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
116 else()
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
117 message(FATAL_ERROR "Support your platform here")
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
118 endif()
21
29bfa3095207 check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
119
29bfa3095207 check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
120 if (Failure)
29bfa3095207 check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
121 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
122 endif()
2
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
123
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
124 if (NOT IS_DIRECTORY "${TargetDirectory}")
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
125 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
126 endif()
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
127 endif()
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
128 endmacro()
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
129