Mercurial > hg > orthanc
annotate Resources/CMake/DownloadPackage.cmake @ 364:37b066ee2988
trying to support more platforms
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 31 Jan 2013 16:51:42 +0100 |
parents | b00a6c68d529 |
children | 5f6d75cd4b46 |
rev | line source |
---|---|
2 | 1 macro(GetUrlFilename TargetVariable Url) |
2 string(REGEX REPLACE "^.*/" "" ${TargetVariable} "${Url}") | |
3 endmacro() | |
4 | |
5 | |
6 macro(GetUrlExtension TargetVariable Url) | |
7 #string(REGEX REPLACE "^.*/[^.]*\\." "" TMP "${Url}") | |
8 string(REGEX REPLACE "^.*\\." "" TMP "${Url}") | |
9 string(TOLOWER "${TMP}" "${TargetVariable}") | |
10 endmacro() | |
11 | |
12 | |
13 macro(DownloadPackage Url TargetDirectory PreloadedVariable UncompressArguments) | |
14 if (NOT IS_DIRECTORY "${TargetDirectory}") | |
15 GetUrlFilename(TMP_FILENAME "${Url}") | |
16 if ("${PreloadedVariable}" STREQUAL "") | |
17 set(TMP_PATH "${CMAKE_SOURCE_DIR}/ThirdPartyDownloads/${TMP_FILENAME}") | |
18 if (NOT EXISTS "${TMP_PATH}") | |
19 message("Downloading ${Url}") | |
20 file(DOWNLOAD "${Url}" "${TMP_PATH}" SHOW_PROGRESS) | |
21 else() | |
113 | 22 message("Using local copy of ${Url}") |
2 | 23 endif() |
24 else() | |
25 message("Using preloaded archive ${PreloadedVariable} for ${Url}") | |
26 set(TMP_PATH "${PreloadedVariable}") | |
27 endif() | |
28 | |
29 GetUrlExtension(TMP_EXTENSION "${Url}") | |
30 #message(${TMP_EXTENSION}) | |
113 | 31 message("Uncompressing ${TMP_FILENAME}") |
2 | 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 | 34 # How to silently extract files using 7-zip |
35 # http://superuser.com/questions/331148/7zip-command-line-extract-silently-quietly | |
36 | |
2 | 37 FIND_PROGRAM(ZIP_EXECUTABLE 7z PATHS "$ENV{ProgramFiles}/7-Zip") |
38 | |
39 if (("${TMP_EXTENSION}" STREQUAL "gz") OR ("${TMP_EXTENSION}" STREQUAL "tgz")) | |
40 execute_process( | |
75 | 41 COMMAND ${ZIP_EXECUTABLE} e -y ${TMP_PATH} |
2 | 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 | 44 OUTPUT_QUIET |
2 | 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 | 51 set(ARGS ${UncompressArguments}) |
52 SEPARATE_ARGUMENTS(ARGS) | |
53 list(LENGTH ARGS TMP_LENGTH) | |
54 | |
55 if ("${TMP_EXTENSION}" STREQUAL "tgz") | |
56 string(REGEX REPLACE ".tgz$" ".tar" TMP_FILENAME2 "${TMP_FILENAME}") | |
57 else() | |
58 string(REGEX REPLACE ".gz$" "" TMP_FILENAME2 "${TMP_FILENAME}") | |
59 endif() | |
60 | |
61 if (TMP_LENGTH EQUAL 0) | |
62 execute_process( | |
75 | 63 COMMAND ${ZIP_EXECUTABLE} x -y ${TMP_FILENAME2} |
2 | 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 | 66 OUTPUT_QUIET |
2 | 67 ) |
68 else() | |
69 foreach(SUBDIR ${ARGS}) | |
70 execute_process( | |
75 | 71 COMMAND ${ZIP_EXECUTABLE} x -y "-i!${SUBDIR}" "${TMP_FILENAME2}" |
2 | 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 | 74 OUTPUT_QUIET |
2 | 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 | 80 endforeach() |
81 endif() | |
82 elseif ("${TMP_EXTENSION}" STREQUAL "zip") | |
83 execute_process( | |
75 | 84 COMMAND ${ZIP_EXECUTABLE} x -y ${TMP_PATH} |
2 | 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 | 87 OUTPUT_QUIET |
2 | 88 ) |
89 else() | |
90 message(FATAL_ERROR "Support your platform here") | |
91 endif() | |
364
37b066ee2988
trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
92 |
2 | 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 | 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 | 121 |
122 if (NOT IS_DIRECTORY "${TargetDirectory}") | |
123 message(FATAL_ERROR "The package was not uncompressed at the proper location. Check the CMake instructions.") | |
124 endif() | |
125 endif() | |
126 endmacro() | |
127 |