changeset 603:49945044b06d

check the presence of external software in CMake
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 15 Oct 2013 16:23:42 +0200
parents d5043ff68d58
children 489f6a375277 b82292ba2083 ce5d2040c47b
files NEWS Resources/CMake/DownloadPackage.cmake
diffstat 2 files changed, 27 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Mon Oct 14 15:57:51 2013 +0200
+++ b/NEWS	Tue Oct 15 16:23:42 2013 +0200
@@ -2,6 +2,7 @@
 ===============================
 
 * Possibility to keep the PatientID during an anonymization
+* Check whether "unzip", "tar" and/or "7-zip" are installed from CMake
 
 
 Version 0.6.2 (2013/10/04)
--- a/Resources/CMake/DownloadPackage.cmake	Mon Oct 14 15:57:51 2013 +0200
+++ b/Resources/CMake/DownloadPackage.cmake	Tue Oct 15 16:23:42 2013 +0200
@@ -10,6 +10,29 @@
 endmacro()
 
 
+##
+## Check the existence of the required decompression tools
+##
+
+if ("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows")
+  find_program(ZIP_EXECUTABLE 7z PATHS "$ENV{ProgramFiles}/7-Zip")
+  if (${ZIP_EXECUTABLE} MATCHES "ZIP_EXECUTABLE-NOTFOUND")
+    message(FATAL_ERROR "Please install the '7-zip' software (http://www.7-zip.org/)")
+  endif()
+
+else()
+  find_program(UNZIP_EXECUTABLE unzip)
+  if (${UNZIP_EXECUTABLE} MATCHES "UNZIP_EXECUTABLE-NOTFOUND")
+    message(FATAL_ERROR "Please install the 'unzip' package")
+  endif()
+
+  find_program(TAR_EXECUTABLE tar)
+  if (${TAR_EXECUTABLE} MATCHES "TAR_EXECUTABLE-NOTFOUND")
+    message(FATAL_ERROR "Please install the 'tar' package")
+  endif()
+endif()
+
+
 macro(DownloadPackage MD5 Url TargetDirectory)
   if (NOT IS_DIRECTORY "${TargetDirectory}")
     GetUrlFilename(TMP_FILENAME "${Url}")
@@ -30,8 +53,6 @@
       # How to silently extract files using 7-zip
       # http://superuser.com/questions/331148/7zip-command-line-extract-silently-quietly
 
-      FIND_PROGRAM(ZIP_EXECUTABLE 7z PATHS "$ENV{ProgramFiles}/7-Zip") 
-
       if (("${TMP_EXTENSION}" STREQUAL "gz") OR ("${TMP_EXTENSION}" STREQUAL "tgz"))
         execute_process(
           COMMAND ${ZIP_EXECUTABLE} e -y ${TMP_PATH}
@@ -70,20 +91,20 @@
     else()
       if ("${TMP_EXTENSION}" STREQUAL "zip")
         execute_process(
-          COMMAND sh -c "unzip -q ${TMP_PATH}"
+          COMMAND sh -c "${UNZIP_EXECUTABLE} -q ${TMP_PATH}"
           WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
           RESULT_VARIABLE Failure
         )
       elseif (("${TMP_EXTENSION}" STREQUAL "gz") OR ("${TMP_EXTENSION}" STREQUAL "tgz"))
         #message("tar xvfz ${TMP_PATH}")
         execute_process(
-          COMMAND sh -c "tar xfz ${TMP_PATH}"
+          COMMAND sh -c "${TAR_EXECUTABLE} xfz ${TMP_PATH}"
           WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
           RESULT_VARIABLE Failure
           )
       elseif ("${TMP_EXTENSION}" STREQUAL "bz2")
         execute_process(
-          COMMAND sh -c "tar xfj ${TMP_PATH}"
+          COMMAND sh -c "${TAR_EXECUTABLE} xfj ${TMP_PATH}"
           WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
           RESULT_VARIABLE Failure
           )