annotate Resources/CMake/DownloadPackage.cmake @ 49:e1a3ae0dadf3

renaming of resources
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 05 Sep 2012 15:38:08 +0200
parents 29bfa3095207
children 09718f2fc5cb
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()
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
22 message("Already downloaded ${Url}")
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})
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
31
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
32 if ("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Linux")
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
33 if ("${TMP_EXTENSION}" STREQUAL "zip")
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
34 execute_process(
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
35 COMMAND sh -c "unzip ${TMP_PATH} ${UncompressArguments}"
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
36 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
21
29bfa3095207 check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
37 RESULT_VARIABLE Failure
29bfa3095207 check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
38 )
2
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
39 elseif (("${TMP_EXTENSION}" STREQUAL "gz") OR ("${TMP_EXTENSION}" STREQUAL "tgz"))
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
40 #message("tar xvfz ${TMP_PATH} ${UncompressArguments}")
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
41 execute_process(
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
42 COMMAND sh -c "tar xvfz ${TMP_PATH} ${UncompressArguments}"
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
43 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
21
29bfa3095207 check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
44 RESULT_VARIABLE Failure
2
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
45 )
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
46 elseif ("${TMP_EXTENSION}" STREQUAL "bz2")
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
47 execute_process(
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
48 COMMAND sh -c "tar xvfj ${TMP_PATH} ${UncompressArguments}"
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
49 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
21
29bfa3095207 check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
50 RESULT_VARIABLE Failure
2
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
51 )
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
52 else()
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
53 message(FATAL_ERROR "Unknown package format.")
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
54 endif()
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
55
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
56 elseif ("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows")
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
57 FIND_PROGRAM(ZIP_EXECUTABLE 7z PATHS "$ENV{ProgramFiles}/7-Zip")
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
58
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
59 if (("${TMP_EXTENSION}" STREQUAL "gz") OR ("${TMP_EXTENSION}" STREQUAL "tgz"))
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
60 execute_process(
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
61 COMMAND ${ZIP_EXECUTABLE} e ${TMP_PATH}
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
62 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
21
29bfa3095207 check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
63 RESULT_VARIABLE Failure
2
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
64 )
21
29bfa3095207 check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
65
29bfa3095207 check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
66 if (Failure)
29bfa3095207 check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
67 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
68 endif()
29bfa3095207 check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
69
2
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
70 set(ARGS ${UncompressArguments})
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
71 SEPARATE_ARGUMENTS(ARGS)
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
72 list(LENGTH ARGS TMP_LENGTH)
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
73
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
74 if ("${TMP_EXTENSION}" STREQUAL "tgz")
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
75 string(REGEX REPLACE ".tgz$" ".tar" TMP_FILENAME2 "${TMP_FILENAME}")
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
76 else()
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
77 string(REGEX REPLACE ".gz$" "" TMP_FILENAME2 "${TMP_FILENAME}")
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
78 endif()
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
79
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
80 if (TMP_LENGTH EQUAL 0)
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
81 execute_process(
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
82 COMMAND ${ZIP_EXECUTABLE} x ${TMP_FILENAME2}
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
83 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
21
29bfa3095207 check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
84 RESULT_VARIABLE Failure
2
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
85 )
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
86 else()
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
87 foreach(SUBDIR ${ARGS})
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
88 execute_process(
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
89 COMMAND ${ZIP_EXECUTABLE} x "-i!${SUBDIR}" "${TMP_FILENAME2}"
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
90 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
21
29bfa3095207 check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
91 RESULT_VARIABLE Failure
2
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
92 )
21
29bfa3095207 check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
93
29bfa3095207 check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
94 if (Failure)
29bfa3095207 check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
95 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
96 endif()
2
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
97 endforeach()
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
98 endif()
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
99 elseif ("${TMP_EXTENSION}" STREQUAL "zip")
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
100 execute_process(
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
101 COMMAND ${ZIP_EXECUTABLE} x ${TMP_PATH}
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
102 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
21
29bfa3095207 check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
103 RESULT_VARIABLE Failure
2
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
104 )
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
105 else()
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
106 message(FATAL_ERROR "Support your platform here")
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
107 endif()
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
108 else()
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
109 message(FATAL_ERROR "Support your platform here")
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
110 endif()
21
29bfa3095207 check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
111
29bfa3095207 check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
112 if (Failure)
29bfa3095207 check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
113 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
114 endif()
2
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
115
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
116 if (NOT IS_DIRECTORY "${TargetDirectory}")
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
117 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
118 endif()
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
119 endif()
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
120 endmacro()
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
121