Mercurial > hg > orthanc
annotate Resources/CMake/DownloadPackage.cmake @ 715:78239878727a
news
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 14 Feb 2014 11:26:59 +0100 |
parents | d775a3cb5a06 |
children | ee0d5abf7958 |
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 | |
603
49945044b06d
check the presence of external software in CMake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
553
diff
changeset
|
13 ## |
49945044b06d
check the presence of external software in CMake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
553
diff
changeset
|
14 ## Check the existence of the required decompression tools |
49945044b06d
check the presence of external software in CMake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
553
diff
changeset
|
15 ## |
49945044b06d
check the presence of external software in CMake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
553
diff
changeset
|
16 |
49945044b06d
check the presence of external software in CMake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
553
diff
changeset
|
17 if ("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows") |
49945044b06d
check the presence of external software in CMake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
553
diff
changeset
|
18 find_program(ZIP_EXECUTABLE 7z PATHS "$ENV{ProgramFiles}/7-Zip") |
49945044b06d
check the presence of external software in CMake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
553
diff
changeset
|
19 if (${ZIP_EXECUTABLE} MATCHES "ZIP_EXECUTABLE-NOTFOUND") |
49945044b06d
check the presence of external software in CMake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
553
diff
changeset
|
20 message(FATAL_ERROR "Please install the '7-zip' software (http://www.7-zip.org/)") |
49945044b06d
check the presence of external software in CMake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
553
diff
changeset
|
21 endif() |
49945044b06d
check the presence of external software in CMake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
553
diff
changeset
|
22 |
49945044b06d
check the presence of external software in CMake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
553
diff
changeset
|
23 else() |
49945044b06d
check the presence of external software in CMake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
553
diff
changeset
|
24 find_program(UNZIP_EXECUTABLE unzip) |
49945044b06d
check the presence of external software in CMake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
553
diff
changeset
|
25 if (${UNZIP_EXECUTABLE} MATCHES "UNZIP_EXECUTABLE-NOTFOUND") |
49945044b06d
check the presence of external software in CMake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
553
diff
changeset
|
26 message(FATAL_ERROR "Please install the 'unzip' package") |
49945044b06d
check the presence of external software in CMake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
553
diff
changeset
|
27 endif() |
49945044b06d
check the presence of external software in CMake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
553
diff
changeset
|
28 |
49945044b06d
check the presence of external software in CMake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
553
diff
changeset
|
29 find_program(TAR_EXECUTABLE tar) |
49945044b06d
check the presence of external software in CMake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
553
diff
changeset
|
30 if (${TAR_EXECUTABLE} MATCHES "TAR_EXECUTABLE-NOTFOUND") |
49945044b06d
check the presence of external software in CMake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
553
diff
changeset
|
31 message(FATAL_ERROR "Please install the 'tar' package") |
49945044b06d
check the presence of external software in CMake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
553
diff
changeset
|
32 endif() |
49945044b06d
check the presence of external software in CMake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
553
diff
changeset
|
33 endif() |
49945044b06d
check the presence of external software in CMake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
553
diff
changeset
|
34 |
49945044b06d
check the presence of external software in CMake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
553
diff
changeset
|
35 |
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
|
36 macro(DownloadPackage MD5 Url TargetDirectory) |
2 | 37 if (NOT IS_DIRECTORY "${TargetDirectory}") |
38 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
|
39 |
27d32fc6209a
simplifications to cmake, use a digest of boost 1.54.0 thanks bcp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
411
diff
changeset
|
40 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
|
41 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
|
42 message("Downloading ${Url}") |
634 | 43 |
44 # This fixes issue 6: "I think cmake shouldn't download the | |
45 # packages which are not in the system, it should stop and let | |
46 # user know." | |
47 # https://code.google.com/p/orthanc/issues/detail?id=6 | |
48 if (NOT STATIC_BUILD AND NOT ALLOW_DOWNLOADS) | |
49 message(FATAL_ERROR "CMake is not allowed to download from Internet. Please set the ALLOW_DOWNLOADS option to ON") | |
50 endif() | |
51 | |
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
|
52 file(DOWNLOAD "${Url}" "${TMP_PATH}" SHOW_PROGRESS EXPECTED_MD5 "${MD5}") |
2 | 53 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
|
54 message("Using local copy of ${Url}") |
2 | 55 endif() |
56 | |
57 GetUrlExtension(TMP_EXTENSION "${Url}") | |
58 #message(${TMP_EXTENSION}) | |
113 | 59 message("Uncompressing ${TMP_FILENAME}") |
2 | 60 |
364
37b066ee2988
trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
61 if ("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows") |
77 | 62 # How to silently extract files using 7-zip |
63 # http://superuser.com/questions/331148/7zip-command-line-extract-silently-quietly | |
64 | |
2 | 65 if (("${TMP_EXTENSION}" STREQUAL "gz") OR ("${TMP_EXTENSION}" STREQUAL "tgz")) |
66 execute_process( | |
75 | 67 COMMAND ${ZIP_EXECUTABLE} e -y ${TMP_PATH} |
2 | 68 WORKING_DIRECTORY ${CMAKE_BINARY_DIR} |
21
29bfa3095207
check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
69 RESULT_VARIABLE Failure |
74 | 70 OUTPUT_QUIET |
2 | 71 ) |
21
29bfa3095207
check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
72 |
29bfa3095207
check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
73 if (Failure) |
29bfa3095207
check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
74 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
|
75 endif() |
29bfa3095207
check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
76 |
2 | 77 if ("${TMP_EXTENSION}" STREQUAL "tgz") |
78 string(REGEX REPLACE ".tgz$" ".tar" TMP_FILENAME2 "${TMP_FILENAME}") | |
79 else() | |
80 string(REGEX REPLACE ".gz$" "" TMP_FILENAME2 "${TMP_FILENAME}") | |
81 endif() | |
82 | |
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
|
83 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
|
84 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
|
85 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
|
86 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
|
87 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
|
88 ) |
2 | 89 elseif ("${TMP_EXTENSION}" STREQUAL "zip") |
90 execute_process( | |
75 | 91 COMMAND ${ZIP_EXECUTABLE} x -y ${TMP_PATH} |
2 | 92 WORKING_DIRECTORY ${CMAKE_BINARY_DIR} |
21
29bfa3095207
check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
93 RESULT_VARIABLE Failure |
74 | 94 OUTPUT_QUIET |
2 | 95 ) |
96 else() | |
97 message(FATAL_ERROR "Support your platform here") | |
98 endif() | |
364
37b066ee2988
trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
99 |
2 | 100 else() |
364
37b066ee2988
trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
101 if ("${TMP_EXTENSION}" STREQUAL "zip") |
37b066ee2988
trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
102 execute_process( |
603
49945044b06d
check the presence of external software in CMake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
553
diff
changeset
|
103 COMMAND sh -c "${UNZIP_EXECUTABLE} -q ${TMP_PATH}" |
364
37b066ee2988
trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
104 WORKING_DIRECTORY ${CMAKE_BINARY_DIR} |
37b066ee2988
trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
105 RESULT_VARIABLE Failure |
37b066ee2988
trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
106 ) |
37b066ee2988
trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
107 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
|
108 #message("tar xvfz ${TMP_PATH}") |
364
37b066ee2988
trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
109 execute_process( |
603
49945044b06d
check the presence of external software in CMake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
553
diff
changeset
|
110 COMMAND sh -c "${TAR_EXECUTABLE} xfz ${TMP_PATH}" |
364
37b066ee2988
trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
111 WORKING_DIRECTORY ${CMAKE_BINARY_DIR} |
37b066ee2988
trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
112 RESULT_VARIABLE Failure |
37b066ee2988
trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
113 ) |
37b066ee2988
trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
114 elseif ("${TMP_EXTENSION}" STREQUAL "bz2") |
37b066ee2988
trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
115 execute_process( |
603
49945044b06d
check the presence of external software in CMake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
553
diff
changeset
|
116 COMMAND sh -c "${TAR_EXECUTABLE} xfj ${TMP_PATH}" |
364
37b066ee2988
trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
117 WORKING_DIRECTORY ${CMAKE_BINARY_DIR} |
37b066ee2988
trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
118 RESULT_VARIABLE Failure |
37b066ee2988
trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
119 ) |
37b066ee2988
trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
120 else() |
37b066ee2988
trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
121 message(FATAL_ERROR "Unknown package format.") |
37b066ee2988
trying to support more platforms
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
122 endif() |
2 | 123 endif() |
21
29bfa3095207
check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
124 |
29bfa3095207
check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
125 if (Failure) |
29bfa3095207
check return code in download
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
126 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
|
127 endif() |
2 | 128 |
129 if (NOT IS_DIRECTORY "${TargetDirectory}") | |
130 message(FATAL_ERROR "The package was not uncompressed at the proper location. Check the CMake instructions.") | |
131 endif() | |
132 endif() | |
133 endmacro() |