annotate Resources/CMake/DownloadPackage.cmake @ 553:27d32fc6209a

simplifications to cmake, use a digest of boost 1.54.0 thanks bcp
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 17 Sep 2013 15:06:16 +0200
parents 5f6d75cd4b46
children 49945044b06d
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
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
13 macro(DownloadPackage MD5 Url TargetDirectory)
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}")
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
16
27d32fc6209a simplifications to cmake, use a digest of boost 1.54.0 thanks bcp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 411
diff changeset
17 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
18 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
19 message("Downloading ${Url}")
27d32fc6209a simplifications to cmake, use a digest of boost 1.54.0 thanks bcp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 411
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()
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
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
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
25 GetUrlExtension(TMP_EXTENSION "${Url}")
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
26 #message(${TMP_EXTENSION})
113
b00a6c68d529 clearer messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
27 message("Uncompressing ${TMP_FILENAME}")
2
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
28
364
37b066ee2988 trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
29 if ("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows")
77
b8dfde8d64e8 new dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 75
diff changeset
30 # How to silently extract files using 7-zip
b8dfde8d64e8 new dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 75
diff changeset
31 # 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
32
2
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
33 FIND_PROGRAM(ZIP_EXECUTABLE 7z PATHS "$ENV{ProgramFiles}/7-Zip")
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
34
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
35 if (("${TMP_EXTENSION}" STREQUAL "gz") OR ("${TMP_EXTENSION}" STREQUAL "tgz"))
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
36 execute_process(
75
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
37 COMMAND ${ZIP_EXECUTABLE} e -y ${TMP_PATH}
2
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
38 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
21
29bfa3095207 check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
39 RESULT_VARIABLE Failure
74
09718f2fc5cb silent unzip
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 21
diff changeset
40 OUTPUT_QUIET
2
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
41 )
21
29bfa3095207 check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
42
29bfa3095207 check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
43 if (Failure)
29bfa3095207 check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
44 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
45 endif()
29bfa3095207 check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
46
2
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
47 if ("${TMP_EXTENSION}" STREQUAL "tgz")
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
48 string(REGEX REPLACE ".tgz$" ".tar" TMP_FILENAME2 "${TMP_FILENAME}")
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
49 else()
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
50 string(REGEX REPLACE ".gz$" "" TMP_FILENAME2 "${TMP_FILENAME}")
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
51 endif()
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
52
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
53 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
54 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
55 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
56 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
57 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
58 )
2
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
59 elseif ("${TMP_EXTENSION}" STREQUAL "zip")
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
60 execute_process(
75
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
61 COMMAND ${ZIP_EXECUTABLE} x -y ${TMP_PATH}
2
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
74
09718f2fc5cb silent unzip
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 21
diff changeset
64 OUTPUT_QUIET
2
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
65 )
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
66 else()
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
67 message(FATAL_ERROR "Support your platform here")
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
68 endif()
364
37b066ee2988 trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
69
2
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
70 else()
364
37b066ee2988 trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
71 if ("${TMP_EXTENSION}" STREQUAL "zip")
37b066ee2988 trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
72 execute_process(
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
73 COMMAND sh -c "unzip -q ${TMP_PATH}"
364
37b066ee2988 trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
74 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
37b066ee2988 trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
75 RESULT_VARIABLE Failure
37b066ee2988 trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
76 )
37b066ee2988 trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
77 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
78 #message("tar xvfz ${TMP_PATH}")
364
37b066ee2988 trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
79 execute_process(
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
80 COMMAND sh -c "tar xfz ${TMP_PATH}"
364
37b066ee2988 trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
81 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
37b066ee2988 trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
82 RESULT_VARIABLE Failure
37b066ee2988 trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
83 )
37b066ee2988 trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
84 elseif ("${TMP_EXTENSION}" STREQUAL "bz2")
37b066ee2988 trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
85 execute_process(
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
86 COMMAND sh -c "tar xfj ${TMP_PATH}"
364
37b066ee2988 trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
87 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
37b066ee2988 trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
88 RESULT_VARIABLE Failure
37b066ee2988 trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
89 )
37b066ee2988 trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
90 else()
37b066ee2988 trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
91 message(FATAL_ERROR "Unknown package format.")
37b066ee2988 trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
92 endif()
2
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
93 endif()
21
29bfa3095207 check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
94
29bfa3095207 check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
95 if (Failure)
29bfa3095207 check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
96 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
97 endif()
2
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
98
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
99 if (NOT IS_DIRECTORY "${TargetDirectory}")
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
100 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
101 endif()
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
102 endif()
67a6978503b7 fixing Windows build
Jodogne@Laptop
parents: 0
diff changeset
103 endmacro()