annotate Resources/CMake/DownloadPackage.cmake @ 514:a3d9acf37161 laaw

build script
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 18 Jul 2013 12:45:40 +0200
parents 5f6d75cd4b46
children 27d32fc6209a
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
411
5f6d75cd4b46 md5 of third party downlaods
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 364
diff changeset
13 macro(DownloadPackage MD5 Url TargetDirectory PreloadedVariable UncompressArguments)
2
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}")
411
5f6d75cd4b46 md5 of third party downlaods
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 364
diff changeset
20 file(DOWNLOAD "${Url}" "${TMP_PATH}" SHOW_PROGRESS EXPECTED_MD5 "${MD5}")
2
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
364
37b066ee2988 trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
33 if ("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows")
77
b8dfde8d64e8 new dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 75
diff changeset
34 # How to silently extract files using 7-zip
b8dfde8d64e8 new dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 75
diff changeset
35 # 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
36
2
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
37 FIND_PROGRAM(ZIP_EXECUTABLE 7z PATHS "$ENV{ProgramFiles}/7-Zip")
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
38
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
39 if (("${TMP_EXTENSION}" STREQUAL "gz") OR ("${TMP_EXTENSION}" STREQUAL "tgz"))
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
40 execute_process(
75
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
41 COMMAND ${ZIP_EXECUTABLE} e -y ${TMP_PATH}
2
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
42 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
21
29bfa3095207 check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
43 RESULT_VARIABLE Failure
74
09718f2fc5cb silent unzip
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 21
diff changeset
44 OUTPUT_QUIET
2
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
45 )
21
29bfa3095207 check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
46
29bfa3095207 check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
47 if (Failure)
29bfa3095207 check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
48 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
49 endif()
29bfa3095207 check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
50
2
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
51 set(ARGS ${UncompressArguments})
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
52 SEPARATE_ARGUMENTS(ARGS)
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
53 list(LENGTH ARGS TMP_LENGTH)
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
54
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
55 if ("${TMP_EXTENSION}" STREQUAL "tgz")
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
56 string(REGEX REPLACE ".tgz$" ".tar" TMP_FILENAME2 "${TMP_FILENAME}")
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
57 else()
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
58 string(REGEX REPLACE ".gz$" "" TMP_FILENAME2 "${TMP_FILENAME}")
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
59 endif()
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
60
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
61 if (TMP_LENGTH EQUAL 0)
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
62 execute_process(
75
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
63 COMMAND ${ZIP_EXECUTABLE} x -y ${TMP_FILENAME2}
2
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
64 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
21
29bfa3095207 check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
65 RESULT_VARIABLE Failure
74
09718f2fc5cb silent unzip
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 21
diff changeset
66 OUTPUT_QUIET
2
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
67 )
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
68 else()
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
69 foreach(SUBDIR ${ARGS})
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
70 execute_process(
75
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
71 COMMAND ${ZIP_EXECUTABLE} x -y "-i!${SUBDIR}" "${TMP_FILENAME2}"
2
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
72 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
21
29bfa3095207 check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
73 RESULT_VARIABLE Failure
74
09718f2fc5cb silent unzip
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 21
diff changeset
74 OUTPUT_QUIET
2
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
75 )
21
29bfa3095207 check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
76
29bfa3095207 check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
77 if (Failure)
29bfa3095207 check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
78 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
79 endif()
2
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
80 endforeach()
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
81 endif()
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
82 elseif ("${TMP_EXTENSION}" STREQUAL "zip")
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
83 execute_process(
75
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
84 COMMAND ${ZIP_EXECUTABLE} x -y ${TMP_PATH}
2
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
85 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
21
29bfa3095207 check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
86 RESULT_VARIABLE Failure
74
09718f2fc5cb silent unzip
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 21
diff changeset
87 OUTPUT_QUIET
2
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()
364
37b066ee2988 trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
92
2
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
93 else()
364
37b066ee2988 trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
94 if ("${TMP_EXTENSION}" STREQUAL "zip")
37b066ee2988 trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
95 execute_process(
37b066ee2988 trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
96 COMMAND sh -c "unzip -q ${TMP_PATH} ${UncompressArguments}"
37b066ee2988 trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
97 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
37b066ee2988 trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
98 RESULT_VARIABLE Failure
37b066ee2988 trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
99 )
37b066ee2988 trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
100 elseif (("${TMP_EXTENSION}" STREQUAL "gz") OR ("${TMP_EXTENSION}" STREQUAL "tgz"))
37b066ee2988 trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
101 #message("tar xvfz ${TMP_PATH} ${UncompressArguments}")
37b066ee2988 trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
102 execute_process(
37b066ee2988 trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
103 COMMAND sh -c "tar xfz ${TMP_PATH} ${UncompressArguments}"
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 "bz2")
37b066ee2988 trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
108 execute_process(
37b066ee2988 trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
109 COMMAND sh -c "tar xfj ${TMP_PATH} ${UncompressArguments}"
37b066ee2988 trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
110 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
37b066ee2988 trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
111 RESULT_VARIABLE Failure
37b066ee2988 trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
112 )
37b066ee2988 trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
113 else()
37b066ee2988 trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
114 message(FATAL_ERROR "Unknown package format.")
37b066ee2988 trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
115 endif()
2
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
116 endif()
21
29bfa3095207 check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
117
29bfa3095207 check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
118 if (Failure)
29bfa3095207 check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
119 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
120 endif()
2
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
121
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
122 if (NOT IS_DIRECTORY "${TargetDirectory}")
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
123 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
124 endif()
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
125 endif()
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
126 endmacro()
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
127