Mercurial > hg > orthanc
annotate Resources/CMake/DownloadPackage.cmake @ 114:b4f1191768eb
fix
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 04 Oct 2012 14:35:53 +0200 |
parents | b00a6c68d529 |
children | 37b066ee2988 |
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 |
33 if ("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Linux") | |
34 if ("${TMP_EXTENSION}" STREQUAL "zip") | |
35 execute_process( | |
74 | 36 COMMAND sh -c "unzip -q ${TMP_PATH} ${UncompressArguments}" |
2 | 37 WORKING_DIRECTORY ${CMAKE_BINARY_DIR} |
21
29bfa3095207
check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
38 RESULT_VARIABLE Failure |
29bfa3095207
check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
39 ) |
2 | 40 elseif (("${TMP_EXTENSION}" STREQUAL "gz") OR ("${TMP_EXTENSION}" STREQUAL "tgz")) |
41 #message("tar xvfz ${TMP_PATH} ${UncompressArguments}") | |
42 execute_process( | |
74 | 43 COMMAND sh -c "tar xfz ${TMP_PATH} ${UncompressArguments}" |
2 | 44 WORKING_DIRECTORY ${CMAKE_BINARY_DIR} |
21
29bfa3095207
check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
45 RESULT_VARIABLE Failure |
2 | 46 ) |
47 elseif ("${TMP_EXTENSION}" STREQUAL "bz2") | |
48 execute_process( | |
74 | 49 COMMAND sh -c "tar xfj ${TMP_PATH} ${UncompressArguments}" |
2 | 50 WORKING_DIRECTORY ${CMAKE_BINARY_DIR} |
21
29bfa3095207
check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
51 RESULT_VARIABLE Failure |
2 | 52 ) |
53 else() | |
54 message(FATAL_ERROR "Unknown package format.") | |
55 endif() | |
56 | |
57 elseif ("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows") | |
77 | 58 # How to silently extract files using 7-zip |
59 # http://superuser.com/questions/331148/7zip-command-line-extract-silently-quietly | |
60 | |
2 | 61 FIND_PROGRAM(ZIP_EXECUTABLE 7z PATHS "$ENV{ProgramFiles}/7-Zip") |
62 | |
63 if (("${TMP_EXTENSION}" STREQUAL "gz") OR ("${TMP_EXTENSION}" STREQUAL "tgz")) | |
64 execute_process( | |
75 | 65 COMMAND ${ZIP_EXECUTABLE} e -y ${TMP_PATH} |
2 | 66 WORKING_DIRECTORY ${CMAKE_BINARY_DIR} |
21
29bfa3095207
check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
67 RESULT_VARIABLE Failure |
74 | 68 OUTPUT_QUIET |
2 | 69 ) |
21
29bfa3095207
check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
70 |
29bfa3095207
check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
71 if (Failure) |
29bfa3095207
check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
72 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
|
73 endif() |
29bfa3095207
check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
74 |
2 | 75 set(ARGS ${UncompressArguments}) |
76 SEPARATE_ARGUMENTS(ARGS) | |
77 list(LENGTH ARGS TMP_LENGTH) | |
78 | |
79 if ("${TMP_EXTENSION}" STREQUAL "tgz") | |
80 string(REGEX REPLACE ".tgz$" ".tar" TMP_FILENAME2 "${TMP_FILENAME}") | |
81 else() | |
82 string(REGEX REPLACE ".gz$" "" TMP_FILENAME2 "${TMP_FILENAME}") | |
83 endif() | |
84 | |
85 if (TMP_LENGTH EQUAL 0) | |
86 execute_process( | |
75 | 87 COMMAND ${ZIP_EXECUTABLE} x -y ${TMP_FILENAME2} |
2 | 88 WORKING_DIRECTORY ${CMAKE_BINARY_DIR} |
21
29bfa3095207
check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
89 RESULT_VARIABLE Failure |
74 | 90 OUTPUT_QUIET |
2 | 91 ) |
92 else() | |
93 foreach(SUBDIR ${ARGS}) | |
94 execute_process( | |
75 | 95 COMMAND ${ZIP_EXECUTABLE} x -y "-i!${SUBDIR}" "${TMP_FILENAME2}" |
2 | 96 WORKING_DIRECTORY ${CMAKE_BINARY_DIR} |
21
29bfa3095207
check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
97 RESULT_VARIABLE Failure |
74 | 98 OUTPUT_QUIET |
2 | 99 ) |
21
29bfa3095207
check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
100 |
29bfa3095207
check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
101 if (Failure) |
29bfa3095207
check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
102 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
|
103 endif() |
2 | 104 endforeach() |
105 endif() | |
106 elseif ("${TMP_EXTENSION}" STREQUAL "zip") | |
107 execute_process( | |
75 | 108 COMMAND ${ZIP_EXECUTABLE} x -y ${TMP_PATH} |
2 | 109 WORKING_DIRECTORY ${CMAKE_BINARY_DIR} |
21
29bfa3095207
check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
110 RESULT_VARIABLE Failure |
74 | 111 OUTPUT_QUIET |
2 | 112 ) |
113 else() | |
114 message(FATAL_ERROR "Support your platform here") | |
115 endif() | |
116 else() | |
117 message(FATAL_ERROR "Support your platform here") | |
118 endif() | |
21
29bfa3095207
check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
119 |
29bfa3095207
check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
120 if (Failure) |
29bfa3095207
check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
121 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
|
122 endif() |
2 | 123 |
124 if (NOT IS_DIRECTORY "${TargetDirectory}") | |
125 message(FATAL_ERROR "The package was not uncompressed at the proper location. Check the CMake instructions.") | |
126 endif() | |
127 endif() | |
128 endmacro() | |
129 |