Mercurial > hg > orthanc
comparison 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 |
comparison
equal
deleted
inserted
replaced
552:938d8461cf8f | 553:27d32fc6209a |
---|---|
8 string(REGEX REPLACE "^.*\\." "" TMP "${Url}") | 8 string(REGEX REPLACE "^.*\\." "" TMP "${Url}") |
9 string(TOLOWER "${TMP}" "${TargetVariable}") | 9 string(TOLOWER "${TMP}" "${TargetVariable}") |
10 endmacro() | 10 endmacro() |
11 | 11 |
12 | 12 |
13 macro(DownloadPackage MD5 Url TargetDirectory PreloadedVariable UncompressArguments) | 13 macro(DownloadPackage MD5 Url TargetDirectory) |
14 if (NOT IS_DIRECTORY "${TargetDirectory}") | 14 if (NOT IS_DIRECTORY "${TargetDirectory}") |
15 GetUrlFilename(TMP_FILENAME "${Url}") | 15 GetUrlFilename(TMP_FILENAME "${Url}") |
16 if ("${PreloadedVariable}" STREQUAL "") | 16 |
17 set(TMP_PATH "${CMAKE_SOURCE_DIR}/ThirdPartyDownloads/${TMP_FILENAME}") | 17 set(TMP_PATH "${CMAKE_SOURCE_DIR}/ThirdPartyDownloads/${TMP_FILENAME}") |
18 if (NOT EXISTS "${TMP_PATH}") | 18 if (NOT EXISTS "${TMP_PATH}") |
19 message("Downloading ${Url}") | 19 message("Downloading ${Url}") |
20 file(DOWNLOAD "${Url}" "${TMP_PATH}" SHOW_PROGRESS EXPECTED_MD5 "${MD5}") | 20 file(DOWNLOAD "${Url}" "${TMP_PATH}" SHOW_PROGRESS EXPECTED_MD5 "${MD5}") |
21 else() | |
22 message("Using local copy of ${Url}") | |
23 endif() | |
24 else() | 21 else() |
25 message("Using preloaded archive ${PreloadedVariable} for ${Url}") | 22 message("Using local copy of ${Url}") |
26 set(TMP_PATH "${PreloadedVariable}") | |
27 endif() | 23 endif() |
28 | 24 |
29 GetUrlExtension(TMP_EXTENSION "${Url}") | 25 GetUrlExtension(TMP_EXTENSION "${Url}") |
30 #message(${TMP_EXTENSION}) | 26 #message(${TMP_EXTENSION}) |
31 message("Uncompressing ${TMP_FILENAME}") | 27 message("Uncompressing ${TMP_FILENAME}") |
46 | 42 |
47 if (Failure) | 43 if (Failure) |
48 message(FATAL_ERROR "Error while running the uncompression tool") | 44 message(FATAL_ERROR "Error while running the uncompression tool") |
49 endif() | 45 endif() |
50 | 46 |
51 set(ARGS ${UncompressArguments}) | |
52 SEPARATE_ARGUMENTS(ARGS) | |
53 list(LENGTH ARGS TMP_LENGTH) | |
54 | |
55 if ("${TMP_EXTENSION}" STREQUAL "tgz") | 47 if ("${TMP_EXTENSION}" STREQUAL "tgz") |
56 string(REGEX REPLACE ".tgz$" ".tar" TMP_FILENAME2 "${TMP_FILENAME}") | 48 string(REGEX REPLACE ".tgz$" ".tar" TMP_FILENAME2 "${TMP_FILENAME}") |
57 else() | 49 else() |
58 string(REGEX REPLACE ".gz$" "" TMP_FILENAME2 "${TMP_FILENAME}") | 50 string(REGEX REPLACE ".gz$" "" TMP_FILENAME2 "${TMP_FILENAME}") |
59 endif() | 51 endif() |
60 | 52 |
61 if (TMP_LENGTH EQUAL 0) | 53 execute_process( |
62 execute_process( | 54 COMMAND ${ZIP_EXECUTABLE} x -y ${TMP_FILENAME2} |
63 COMMAND ${ZIP_EXECUTABLE} x -y ${TMP_FILENAME2} | 55 WORKING_DIRECTORY ${CMAKE_BINARY_DIR} |
64 WORKING_DIRECTORY ${CMAKE_BINARY_DIR} | 56 RESULT_VARIABLE Failure |
65 RESULT_VARIABLE Failure | 57 OUTPUT_QUIET |
66 OUTPUT_QUIET | 58 ) |
67 ) | |
68 else() | |
69 foreach(SUBDIR ${ARGS}) | |
70 execute_process( | |
71 COMMAND ${ZIP_EXECUTABLE} x -y "-i!${SUBDIR}" "${TMP_FILENAME2}" | |
72 WORKING_DIRECTORY ${CMAKE_BINARY_DIR} | |
73 RESULT_VARIABLE Failure | |
74 OUTPUT_QUIET | |
75 ) | |
76 | |
77 if (Failure) | |
78 message(FATAL_ERROR "Error while running the uncompression tool") | |
79 endif() | |
80 endforeach() | |
81 endif() | |
82 elseif ("${TMP_EXTENSION}" STREQUAL "zip") | 59 elseif ("${TMP_EXTENSION}" STREQUAL "zip") |
83 execute_process( | 60 execute_process( |
84 COMMAND ${ZIP_EXECUTABLE} x -y ${TMP_PATH} | 61 COMMAND ${ZIP_EXECUTABLE} x -y ${TMP_PATH} |
85 WORKING_DIRECTORY ${CMAKE_BINARY_DIR} | 62 WORKING_DIRECTORY ${CMAKE_BINARY_DIR} |
86 RESULT_VARIABLE Failure | 63 RESULT_VARIABLE Failure |
91 endif() | 68 endif() |
92 | 69 |
93 else() | 70 else() |
94 if ("${TMP_EXTENSION}" STREQUAL "zip") | 71 if ("${TMP_EXTENSION}" STREQUAL "zip") |
95 execute_process( | 72 execute_process( |
96 COMMAND sh -c "unzip -q ${TMP_PATH} ${UncompressArguments}" | 73 COMMAND sh -c "unzip -q ${TMP_PATH}" |
97 WORKING_DIRECTORY ${CMAKE_BINARY_DIR} | 74 WORKING_DIRECTORY ${CMAKE_BINARY_DIR} |
98 RESULT_VARIABLE Failure | 75 RESULT_VARIABLE Failure |
99 ) | 76 ) |
100 elseif (("${TMP_EXTENSION}" STREQUAL "gz") OR ("${TMP_EXTENSION}" STREQUAL "tgz")) | 77 elseif (("${TMP_EXTENSION}" STREQUAL "gz") OR ("${TMP_EXTENSION}" STREQUAL "tgz")) |
101 #message("tar xvfz ${TMP_PATH} ${UncompressArguments}") | 78 #message("tar xvfz ${TMP_PATH}") |
102 execute_process( | 79 execute_process( |
103 COMMAND sh -c "tar xfz ${TMP_PATH} ${UncompressArguments}" | 80 COMMAND sh -c "tar xfz ${TMP_PATH}" |
104 WORKING_DIRECTORY ${CMAKE_BINARY_DIR} | 81 WORKING_DIRECTORY ${CMAKE_BINARY_DIR} |
105 RESULT_VARIABLE Failure | 82 RESULT_VARIABLE Failure |
106 ) | 83 ) |
107 elseif ("${TMP_EXTENSION}" STREQUAL "bz2") | 84 elseif ("${TMP_EXTENSION}" STREQUAL "bz2") |
108 execute_process( | 85 execute_process( |
109 COMMAND sh -c "tar xfj ${TMP_PATH} ${UncompressArguments}" | 86 COMMAND sh -c "tar xfj ${TMP_PATH}" |
110 WORKING_DIRECTORY ${CMAKE_BINARY_DIR} | 87 WORKING_DIRECTORY ${CMAKE_BINARY_DIR} |
111 RESULT_VARIABLE Failure | 88 RESULT_VARIABLE Failure |
112 ) | 89 ) |
113 else() | 90 else() |
114 message(FATAL_ERROR "Unknown package format.") | 91 message(FATAL_ERROR "Unknown package format.") |
122 if (NOT IS_DIRECTORY "${TargetDirectory}") | 99 if (NOT IS_DIRECTORY "${TargetDirectory}") |
123 message(FATAL_ERROR "The package was not uncompressed at the proper location. Check the CMake instructions.") | 100 message(FATAL_ERROR "The package was not uncompressed at the proper location. Check the CMake instructions.") |
124 endif() | 101 endif() |
125 endif() | 102 endif() |
126 endmacro() | 103 endmacro() |
127 |