annotate Resources/CMake/DownloadPackage.cmake @ 5:01163b17a028

merge
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 19 Jul 2012 22:38:30 +0200
parents 67a6978503b7
children 29bfa3095207
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}
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
37 )
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
38 elseif (("${TMP_EXTENSION}" STREQUAL "gz") OR ("${TMP_EXTENSION}" STREQUAL "tgz"))
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
39 #message("tar xvfz ${TMP_PATH} ${UncompressArguments}")
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
40 execute_process(
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
41 COMMAND sh -c "tar xvfz ${TMP_PATH} ${UncompressArguments}"
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
42 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
43 )
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
44 elseif ("${TMP_EXTENSION}" STREQUAL "bz2")
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
45 execute_process(
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
46 COMMAND sh -c "tar xvfj ${TMP_PATH} ${UncompressArguments}"
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
47 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
48 )
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
49 else()
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
50 message(FATAL_ERROR "Unknown package format.")
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
51 endif()
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
52
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
53 elseif ("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows")
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
54 FIND_PROGRAM(ZIP_EXECUTABLE 7z PATHS "$ENV{ProgramFiles}/7-Zip")
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
55
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
56 if (("${TMP_EXTENSION}" STREQUAL "gz") OR ("${TMP_EXTENSION}" STREQUAL "tgz"))
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
57 execute_process(
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
58 COMMAND ${ZIP_EXECUTABLE} e ${TMP_PATH}
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
59 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
60 )
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
61 set(ARGS ${UncompressArguments})
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
62 SEPARATE_ARGUMENTS(ARGS)
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
63 list(LENGTH ARGS TMP_LENGTH)
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
64
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
65 if ("${TMP_EXTENSION}" STREQUAL "tgz")
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
66 string(REGEX REPLACE ".tgz$" ".tar" TMP_FILENAME2 "${TMP_FILENAME}")
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
67 else()
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
68 string(REGEX REPLACE ".gz$" "" TMP_FILENAME2 "${TMP_FILENAME}")
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
69 endif()
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
70
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
71 if (TMP_LENGTH EQUAL 0)
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
72 execute_process(
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
73 COMMAND ${ZIP_EXECUTABLE} x ${TMP_FILENAME2}
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
74 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
75 )
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
76 else()
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
77 foreach(SUBDIR ${ARGS})
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
78 execute_process(
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
79 COMMAND ${ZIP_EXECUTABLE} x "-i!${SUBDIR}" "${TMP_FILENAME2}"
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
80 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
81 )
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
82 endforeach()
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
83 endif()
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
84 elseif ("${TMP_EXTENSION}" STREQUAL "zip")
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
85 execute_process(
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
86 COMMAND ${ZIP_EXECUTABLE} x ${TMP_PATH}
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
87 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
88 )
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
89 else()
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
90 message(FATAL_ERROR "Support your platform here")
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
91 endif()
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
92 else()
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
93 message(FATAL_ERROR "Support your platform here")
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
94 endif()
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
95
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
96 if (NOT IS_DIRECTORY "${TargetDirectory}")
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
97 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
98 endif()
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
99 endif()
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
100 endmacro()
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
101