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