Mercurial > hg > orthanc
annotate Resources/CMake/DownloadPackage.cmake @ 579:714cf0e144cb laaw
fix path
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 30 Sep 2013 17:39:22 +0200 |
parents | 27d32fc6209a |
children | 49945044b06d |
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 | |
553
27d32fc6209a
simplifications to cmake, use a digest of boost 1.54.0 thanks bcp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
411
diff
changeset
|
13 macro(DownloadPackage MD5 Url TargetDirectory) |
2 | 14 if (NOT IS_DIRECTORY "${TargetDirectory}") |
15 GetUrlFilename(TMP_FILENAME "${Url}") | |
553
27d32fc6209a
simplifications to cmake, use a digest of boost 1.54.0 thanks bcp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
411
diff
changeset
|
16 |
27d32fc6209a
simplifications to cmake, use a digest of boost 1.54.0 thanks bcp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
411
diff
changeset
|
17 set(TMP_PATH "${CMAKE_SOURCE_DIR}/ThirdPartyDownloads/${TMP_FILENAME}") |
27d32fc6209a
simplifications to cmake, use a digest of boost 1.54.0 thanks bcp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
411
diff
changeset
|
18 if (NOT EXISTS "${TMP_PATH}") |
27d32fc6209a
simplifications to cmake, use a digest of boost 1.54.0 thanks bcp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
411
diff
changeset
|
19 message("Downloading ${Url}") |
27d32fc6209a
simplifications to cmake, use a digest of boost 1.54.0 thanks bcp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
411
diff
changeset
|
20 file(DOWNLOAD "${Url}" "${TMP_PATH}" SHOW_PROGRESS EXPECTED_MD5 "${MD5}") |
2 | 21 else() |
553
27d32fc6209a
simplifications to cmake, use a digest of boost 1.54.0 thanks bcp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
411
diff
changeset
|
22 message("Using local copy of ${Url}") |
2 | 23 endif() |
24 | |
25 GetUrlExtension(TMP_EXTENSION "${Url}") | |
26 #message(${TMP_EXTENSION}) | |
113 | 27 message("Uncompressing ${TMP_FILENAME}") |
2 | 28 |
364
37b066ee2988
trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
29 if ("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows") |
77 | 30 # How to silently extract files using 7-zip |
31 # http://superuser.com/questions/331148/7zip-command-line-extract-silently-quietly | |
32 | |
2 | 33 FIND_PROGRAM(ZIP_EXECUTABLE 7z PATHS "$ENV{ProgramFiles}/7-Zip") |
34 | |
35 if (("${TMP_EXTENSION}" STREQUAL "gz") OR ("${TMP_EXTENSION}" STREQUAL "tgz")) | |
36 execute_process( | |
75 | 37 COMMAND ${ZIP_EXECUTABLE} e -y ${TMP_PATH} |
2 | 38 WORKING_DIRECTORY ${CMAKE_BINARY_DIR} |
21
29bfa3095207
check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
39 RESULT_VARIABLE Failure |
74 | 40 OUTPUT_QUIET |
2 | 41 ) |
21
29bfa3095207
check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
42 |
29bfa3095207
check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
43 if (Failure) |
29bfa3095207
check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
44 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
|
45 endif() |
29bfa3095207
check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
46 |
2 | 47 if ("${TMP_EXTENSION}" STREQUAL "tgz") |
48 string(REGEX REPLACE ".tgz$" ".tar" TMP_FILENAME2 "${TMP_FILENAME}") | |
49 else() | |
50 string(REGEX REPLACE ".gz$" "" TMP_FILENAME2 "${TMP_FILENAME}") | |
51 endif() | |
52 | |
553
27d32fc6209a
simplifications to cmake, use a digest of boost 1.54.0 thanks bcp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
411
diff
changeset
|
53 execute_process( |
27d32fc6209a
simplifications to cmake, use a digest of boost 1.54.0 thanks bcp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
411
diff
changeset
|
54 COMMAND ${ZIP_EXECUTABLE} x -y ${TMP_FILENAME2} |
27d32fc6209a
simplifications to cmake, use a digest of boost 1.54.0 thanks bcp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
411
diff
changeset
|
55 WORKING_DIRECTORY ${CMAKE_BINARY_DIR} |
27d32fc6209a
simplifications to cmake, use a digest of boost 1.54.0 thanks bcp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
411
diff
changeset
|
56 RESULT_VARIABLE Failure |
27d32fc6209a
simplifications to cmake, use a digest of boost 1.54.0 thanks bcp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
411
diff
changeset
|
57 OUTPUT_QUIET |
27d32fc6209a
simplifications to cmake, use a digest of boost 1.54.0 thanks bcp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
411
diff
changeset
|
58 ) |
2 | 59 elseif ("${TMP_EXTENSION}" STREQUAL "zip") |
60 execute_process( | |
75 | 61 COMMAND ${ZIP_EXECUTABLE} x -y ${TMP_PATH} |
2 | 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 |
74 | 64 OUTPUT_QUIET |
2 | 65 ) |
66 else() | |
67 message(FATAL_ERROR "Support your platform here") | |
68 endif() | |
364
37b066ee2988
trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
69 |
2 | 70 else() |
364
37b066ee2988
trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
71 if ("${TMP_EXTENSION}" STREQUAL "zip") |
37b066ee2988
trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
72 execute_process( |
553
27d32fc6209a
simplifications to cmake, use a digest of boost 1.54.0 thanks bcp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
411
diff
changeset
|
73 COMMAND sh -c "unzip -q ${TMP_PATH}" |
364
37b066ee2988
trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
74 WORKING_DIRECTORY ${CMAKE_BINARY_DIR} |
37b066ee2988
trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
75 RESULT_VARIABLE Failure |
37b066ee2988
trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
76 ) |
37b066ee2988
trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
77 elseif (("${TMP_EXTENSION}" STREQUAL "gz") OR ("${TMP_EXTENSION}" STREQUAL "tgz")) |
553
27d32fc6209a
simplifications to cmake, use a digest of boost 1.54.0 thanks bcp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
411
diff
changeset
|
78 #message("tar xvfz ${TMP_PATH}") |
364
37b066ee2988
trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
79 execute_process( |
553
27d32fc6209a
simplifications to cmake, use a digest of boost 1.54.0 thanks bcp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
411
diff
changeset
|
80 COMMAND sh -c "tar xfz ${TMP_PATH}" |
364
37b066ee2988
trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
81 WORKING_DIRECTORY ${CMAKE_BINARY_DIR} |
37b066ee2988
trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
82 RESULT_VARIABLE Failure |
37b066ee2988
trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
83 ) |
37b066ee2988
trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
84 elseif ("${TMP_EXTENSION}" STREQUAL "bz2") |
37b066ee2988
trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
85 execute_process( |
553
27d32fc6209a
simplifications to cmake, use a digest of boost 1.54.0 thanks bcp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
411
diff
changeset
|
86 COMMAND sh -c "tar xfj ${TMP_PATH}" |
364
37b066ee2988
trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
87 WORKING_DIRECTORY ${CMAKE_BINARY_DIR} |
37b066ee2988
trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
88 RESULT_VARIABLE Failure |
37b066ee2988
trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
89 ) |
37b066ee2988
trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
90 else() |
37b066ee2988
trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
91 message(FATAL_ERROR "Unknown package format.") |
37b066ee2988
trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
92 endif() |
2 | 93 endif() |
21
29bfa3095207
check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
94 |
29bfa3095207
check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
95 if (Failure) |
29bfa3095207
check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
96 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
|
97 endif() |
2 | 98 |
99 if (NOT IS_DIRECTORY "${TargetDirectory}") | |
100 message(FATAL_ERROR "The package was not uncompressed at the proper location. Check the CMake instructions.") | |
101 endif() | |
102 endif() | |
103 endmacro() |