Mercurial > hg > orthanc
comparison Resources/CMake/DownloadPackage.cmake @ 0:3959d33612cc
initial commit
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 19 Jul 2012 14:32:22 +0200 |
parents | |
children | 67a6978503b7 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:3959d33612cc |
---|---|
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} | |
37 ) | |
38 elseif (("${TMP_EXTENSION}" STREQUAL "gz") OR ("${TMP_EXTENSION}" STREQUAL "tgz")) | |
39 #message("tar xvfz ${TMP_PATH} ${UncompressArguments}") | |
40 execute_process( | |
41 COMMAND sh -c "tar xvfz ${TMP_PATH} ${UncompressArguments}" | |
42 WORKING_DIRECTORY ${CMAKE_BINARY_DIR} | |
43 ) | |
44 elseif ("${TMP_EXTENSION}" STREQUAL "bz2") | |
45 execute_process( | |
46 COMMAND sh -c "tar xvfj ${TMP_PATH} ${UncompressArguments}" | |
47 WORKING_DIRECTORY ${CMAKE_BINARY_DIR} | |
48 ) | |
49 else() | |
50 message(FATAL_ERROR "Unknown package format.") | |
51 endif() | |
52 else() | |
53 message(FATAL_ERROR "Support your platform here") | |
54 endif() | |
55 | |
56 if (NOT IS_DIRECTORY "${TargetDirectory}") | |
57 message(FATAL_ERROR "The package was not uncompressed at the proper location. Check the CMake instructions.") | |
58 endif() | |
59 endif() | |
60 endmacro() | |
61 |