diff --git a/.hgignore b/.hgignore
deleted file mode 100644
index 7e842947378e7a678021ab2c61f0d1ed063e68f1..0000000000000000000000000000000000000000
--- a/.hgignore
+++ /dev/null
@@ -1,10 +0,0 @@
-syntax: glob
-*~
-.*.swp
-*.orig
-*.pyc
-.\#*
-\#*\#
-tags
-*vim*
-*.template
diff --git a/.hgsigs b/.hgsigs
deleted file mode 100644
index 3a827ea0c1107475983f15a35a0a7ee6f740a4cb..0000000000000000000000000000000000000000
--- a/.hgsigs
+++ /dev/null
@@ -1,3 +0,0 @@
-68eebc1b170a636794feda66523e6c0135ebfef2 0 iEYEABECAAYFAkmvX3cACgkQwRJnCg+r8KFSCgCfVYSnx2ev+hIlpbM/arxzLVf3KvsAn3nqaJXaj62RcNUIjv+qcNWlJ5WG
-e0fdaae06d33190d9b17356c5d51f878fd8fa0b6 0 iEYEABECAAYFAkoNOJEACgkQwRJnCg+r8KHMrACeJMcezNBgXjfx57UNdd/WfXw8kf8An1VEqFVTeG/wUd6QiiVy2icgfLGl
-c07af3906a803b43018e1a7e15db5c11f54d14b4 0 iEYEABECAAYFAkw68W0ACgkQwRJnCg+r8KGhjgCfR4LL9xW8xYGFXWEpbxSSRsCFVhIAn2nPMTqZvUW0cQvU6pkJD1+eENNj
diff --git a/CMake/SourceStatus.cmake b/CMake/SourceStatus.cmake
index 4b245c81fa47ae5259f14dae77f986758374a95a..19d6facb7ce17a67a0d8a6d003770cfc77ea3fae 100644
--- a/CMake/SourceStatus.cmake
+++ b/CMake/SourceStatus.cmake
@@ -61,7 +61,7 @@ function(repository_status root_repo_dir result_var1)
   if(OTB_WC_STATUS)
     message(STATUS "  Local file modifications (${dir_name}) :")
     string(REPLACE "\n" "\n--     " OTB_WC_STATUS_PRETTYPRINT "    ${OTB_WC_STATUS}")
-    message(WARNING "${OTB_WC_STATUS_PRETTYPRINT}")
+    message(STATUS "${OTB_WC_STATUS_PRETTYPRINT}")
   else()
     message(STATUS "  No files modified locally (${dir_name})")
   endif()
diff --git a/Modules/Filtering/MathParserX/include/otbParserX.h b/Modules/Filtering/MathParserX/include/otbParserX.h
index eb58857f4cc4d1e1a15fb03f92443355efd1834b..30d571d76b5c11f72f6bfea767384cd7e478bb17 100644
--- a/Modules/Filtering/MathParserX/include/otbParserX.h
+++ b/Modules/Filtering/MathParserX/include/otbParserX.h
@@ -24,6 +24,7 @@
 #if defined(__clang__)
 #pragma clang diagnostic push
 #pragma clang diagnostic ignored "-Wc++11-extensions"
+#pragma clang diagnostic ignored "-Winconsistent-missing-override"
 #include "mpParser.h"
 #pragma GCC diagnostic pop
 #else
diff --git a/Modules/Learning/Supervised/include/otbSharkRandomForestsMachineLearningModel.h b/Modules/Learning/Supervised/include/otbSharkRandomForestsMachineLearningModel.h
index 458342b8c09fd1fbd4d76081bc04fbaa957da8f2..b362373e8eb7cad3aca821cbc219444f79b0b1d2 100644
--- a/Modules/Learning/Supervised/include/otbSharkRandomForestsMachineLearningModel.h
+++ b/Modules/Learning/Supervised/include/otbSharkRandomForestsMachineLearningModel.h
@@ -29,6 +29,9 @@
 #pragma GCC diagnostic ignored "-Wunused-parameter"
 #pragma GCC diagnostic ignored "-Woverloaded-virtual"
 #pragma GCC diagnostic ignored "-Wignored-qualifiers"
+#pragma GCC diagnostic ignored "-Wsign-compare"
+#pragma GCC diagnostic ignored "-Wcast-align"
+#pragma GCC diagnostic ignored "-Wunknown-pragmas"
 #endif
 #include "shark/Algorithms/Trainers/RFTrainer.h"
 #if defined(__GNUC__) || defined(__clang__)
diff --git a/Modules/MPI/MPIConfig/src/otbMPIConfig.cxx b/Modules/MPI/MPIConfig/src/otbMPIConfig.cxx
index 49ffb07ffc0df21083f07115224fb862ab4aad06..c582dc322fd9a5e5866e67562b568f8d94e9b538 100644
--- a/Modules/MPI/MPIConfig/src/otbMPIConfig.cxx
+++ b/Modules/MPI/MPIConfig/src/otbMPIConfig.cxx
@@ -27,6 +27,7 @@
 #if defined(__GNUC__) || defined(__clang__)
 # pragma GCC diagnostic push
 # pragma GCC diagnostic ignored "-Wunused-parameter"
+# pragma GCC diagnostic ignored "-Wcast-align"
 #include <mpi.h>
 # pragma GCC diagnostic pop
 #else
diff --git a/Modules/MPI/MPITiffWriter/include/otbSimpleParallelTiffWriter.h b/Modules/MPI/MPITiffWriter/include/otbSimpleParallelTiffWriter.h
index 2f6c6f4fc462393bd445b02328240b436920e835..7a32268ef933d97a52d186a897bc4de99cfdf1d4 100644
--- a/Modules/MPI/MPITiffWriter/include/otbSimpleParallelTiffWriter.h
+++ b/Modules/MPI/MPITiffWriter/include/otbSimpleParallelTiffWriter.h
@@ -60,6 +60,7 @@
 #if defined(__GNUC__) || defined(__clang__)
 # pragma GCC diagnostic push
 # pragma GCC diagnostic ignored "-Wunused-parameter"
+# pragma GCC diagnostic ignored "-Wcast-align"
 #include "sptw.h"
 # pragma GCC diagnostic pop
 #else
diff --git a/Modules/Wrappers/ApplicationEngine/src/otbWrapperApplicationHtmlDocGenerator.cxx b/Modules/Wrappers/ApplicationEngine/src/otbWrapperApplicationHtmlDocGenerator.cxx
index f576c75e0e252b698833f12f15964578b4a0142e..086ec18a624d7a6756a4a27e859a2595452a3837 100644
--- a/Modules/Wrappers/ApplicationEngine/src/otbWrapperApplicationHtmlDocGenerator.cxx
+++ b/Modules/Wrappers/ApplicationEngine/src/otbWrapperApplicationHtmlDocGenerator.cxx
@@ -53,9 +53,9 @@ namespace Wrapper
 #define otbDocHtmlParamMacro( type, param, fullKey, showKey )           \
   oss << "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:'Courier New, courier'; font-weight:600;\"; >"; \
   oss << param->GetName();                                              \
-  if( showKey == true &&  !std::string(param->GetKey()).empty() )       \
+  if( showKey == true &&  param->GetKey()[0] != '\0' )       \
     {                                                                   \
-if (fullKey != "")                                           \
+if (!fullKey.empty())                                           \
   {                                                                   \
   oss << " ("<< fullKey<< "." << param->GetKey() << ")";                                        \
   }                                                                   \
@@ -65,7 +65,7 @@ else                                                                  \
   } \
 }                                                                      \
   oss << ": </span>";                                                   \
-if( std::string(param->GetDescription()).size()!=0 )                  \
+if( param->GetDescription()[0] != '\0' )                  \
   {                                                                   \
   oss << param->GetDescription();                                     \
   }                                                                   \
@@ -172,6 +172,7 @@ ApplicationHtmlDocGenerator::GenerateDoc(const Application::Pointer app, const s
 void ApplicationHtmlDocGenerator::GetDocParameters( const Application::Pointer app, std::string & val, const bool showKey)
 {
   std::ostringstream oss;
+  const std::string emptyString;
   const std::vector<std::string> appKeyList = app->GetParametersKeys( false );
   const unsigned int nbOfParam = appKeyList.size();
 
@@ -189,7 +190,7 @@ void ApplicationHtmlDocGenerator::GetDocParameters( const Application::Pointer a
       if( app->GetParameterType(key) ==  ParameterType_Group)
         {
         oss << "<li>";
-        otbDocHtmlParamMacro( "group", param, "", showKey );
+        otbDocHtmlParamMacro( "group", param, emptyString, showKey );
         std::string grDoc;
         ApplicationHtmlDocGenerator::GetDocParameterGroup( app, grDoc, key, showKey );
         oss<<grDoc;
@@ -198,7 +199,7 @@ void ApplicationHtmlDocGenerator::GetDocParameters( const Application::Pointer a
       else if( app->GetParameterType(key) ==  ParameterType_Choice )
         {
         oss << "<li>";
-        otbDocHtmlParamMacro( "choice", param, "", showKey );
+        otbDocHtmlParamMacro( "choice", param, emptyString, showKey );
         std::string grDoc;
         ApplicationHtmlDocGenerator::GetDocParameterChoice(app, grDoc, key, showKey);
         oss<<grDoc;
@@ -207,7 +208,7 @@ void ApplicationHtmlDocGenerator::GetDocParameters( const Application::Pointer a
       else
         {
         oss << "<li>";
-        otbDocHtmlParamMacro("param", param, "", showKey );
+        otbDocHtmlParamMacro("param", param, emptyString, showKey );
         oss << "</li>";
         }
       }
@@ -227,6 +228,7 @@ void ApplicationHtmlDocGenerator::GetDocParameterGroup( const Application::Point
   ParameterGroup * group = dynamic_cast<ParameterGroup *>(paramGr);
   const std::vector<std::string> appKeyList = group->GetParametersKeys( false );
   unsigned int nbOfParam = appKeyList.size();
+  const std::string emptyString;
   std::ostringstream oss;
   oss<<"<ul>";
 
@@ -237,7 +239,7 @@ void ApplicationHtmlDocGenerator::GetDocParameterGroup( const Application::Point
     if( app->GetParameterType(fullKey) ==  ParameterType_Group)
       {
       oss<<"<li>";
-      otbDocHtmlParamMacro( "group", param, "", showKey );
+      otbDocHtmlParamMacro( "group", param, emptyString, showKey );
       std::string grDoc;
       ApplicationHtmlDocGenerator::GetDocParameterGroup( app, grDoc, fullKey, showKey );
       oss<<grDoc;
@@ -274,6 +276,7 @@ void ApplicationHtmlDocGenerator::GetDocParameterChoice( const Application::Poin
   ChoiceParameter * choice = dynamic_cast<ChoiceParameter *>(paramCh);
   const std::vector<std::string> appKeyList = choice->GetChoiceKeys();
   unsigned int nbOfParam = choice->GetNbChoices();
+  const std::string emptyString;
   std::ostringstream oss;
   oss<<"<ul>";
 
@@ -284,7 +287,7 @@ void ApplicationHtmlDocGenerator::GetDocParameterChoice( const Application::Poin
     std::string grDoc;
 
     oss << "<li>";
-    otbDocHtmlParamMacro( "group", group, "", showKey );
+    otbDocHtmlParamMacro( "group", group, emptyString, showKey );
     ApplicationHtmlDocGenerator::GetDocParameterGroup( app, grDoc, fullKey, showKey );
     oss<<grDoc;
     oss<<"</li>";
diff --git a/SuperBuild/Packaging/CMakeLists.txt b/SuperBuild/Packaging/CMakeLists.txt
index 3f293e52bde74257585da59632b807cd4bb09b1f..3d48cda512f907348364e09d347afc54017b40ee 100644
--- a/SuperBuild/Packaging/CMakeLists.txt
+++ b/SuperBuild/Packaging/CMakeLists.txt
@@ -1,189 +1,192 @@
-# cpack has a built-in target called 'package'. In our case we create two standalone installers with
-# and uses a custom target named packages.
-
-# stop generation of msvc packages for windows. 04-apr-2016. point OTB.
-
-##### check if standalone project ######
-set(OUT_OF_SOURCE_BUILD FALSE)
-if(NOT PROJECT_NAME)
-  cmake_minimum_required(VERSION 2.6)
-  include(CMakeParseArguments)
-  project(OTBPackaging)
-
-  option(GENERATE_PACKAGE "Generate OTB package" ON)
-  option(GENERATE_XDK "Generate XDK for OTB development" OFF)
-  
-  set(OUT_OF_SOURCE_BUILD TRUE)
-  
-  if(BUILD_TESTING)
-    include(CTest)
-  endif()
-  
-  if(NOT PACKAGE_OTB_SRC_DIR)
-    get_filename_component(PACKAGE_OTB_SRC_DIR ${OTBPackaging_SOURCE_DIR} PATH)
-    get_filename_component(PACKAGE_OTB_SRC_DIR ${PACKAGE_OTB_SRC_DIR} PATH)
-  endif()
-  
-  option(OTB_WRAP_PYTHON "enable python wrapping" ON)
-  if(OTB_WRAP_PYTHON AND NOT PYTHON_EXECUTABLE)
-    find_package ( PythonInterp REQUIRED )
-    mark_as_advanced(PYTHON_INCLUDE_DIR)
-    mark_as_advanced(PYTHON_LIBRARY)
-  endif()
-
- if(OTB_MINGW)
-    set(OTB_BINARY_DIR "" CACHE PATH "OTB binary directory")
-    set(OTB_INSTALL_DIR "" CACHE PATH "OTB install directory")
-  else()
-    set(SUPERBUILD_BINARY_DIR "" CACHE PATH "path to superbuild binary directory")
-    set(SUPERBUILD_INSTALL_DIR "" CACHE PATH "path to superbuild install directory")
-    set(DOWNLOAD_LOCATION "" CACHE PATH "path to superbuild download archives")
-  endif()
-  
-else() #if(NOT PROJECT_NAME)
-
-  # SUPERBUILD_BINARY_DIR is only set in Packaging/CMakeLists.txt and not available
-  # in the parent scope like others. So we need to set it as CMAKE_BINARY_DIR
-  # if doing packages from source tree.
-  set( SUPERBUILD_BINARY_DIR   ${CMAKE_BINARY_DIR}     )
-  set( SUPERBUILD_INSTALL_DIR  ${SB_INSTALL_PREFIX}    )
-  set( OTB_INSTALL_DIR         ${CMAKE_INSTALL_PREFIX} )
-  
-  if(NOT PACKAGE_OTB_SRC_DIR)
-    get_filename_component(PACKAGE_OTB_SRC_DIR ${OTB-SuperBuild_SOURCE_DIR} PATH)
-  endif()
-  
-endif()
-
-if(NOT GENERATE_PACKAGE AND NOT GENERATE_XDK)
-  #well. we don't have any businees here. Let's move on..
-  return()
-endif()
-
-set(LINUX FALSE)
-set(OTB_MINGW FALSE)
-if(WIN32 AND NOT MSVC)
-  set(OTB_MINGW TRUE)
-else()
-  if( "${CMAKE_SYSTEM_NAME}"  MATCHES "Linux")
-    set(LINUX TRUE)
-  endif()
-endif()
-
-set(SUPERBUILD_SOURCE_DIR ${PACKAGE_OTB_SRC_DIR}/SuperBuild)
-
-include(${SUPERBUILD_SOURCE_DIR}/CMake/SuperBuild_Macro.cmake)
-include(${PACKAGE_OTB_SRC_DIR}/CMake/OTBCheckTargetSystemArch.cmake)
-include(${CMAKE_CURRENT_SOURCE_DIR}/CreateCMakeProjects.cmake)
-
-if(WIN32)
-  set(ZIP_EXE_NAMES 7z 7za)
-  find_program(ZIP_EXECUTABLE NAMES ${ZIP_EXE_NAMES})
-  if(NOT ZIP_EXECUTABLE)
-    message(FATAL_ERROR "Cannot find 7z executable. searched names ${ZIP_EXE_NAMES}. Please add it to your path")
-  endif()
-endif()
-
-if(OTB_MINGW)
-  set(required_vars
-  OTB_BINARY_DIR
-  OTB_INSTALL_DIR
-  MXE_TARGET_DIR
-  )
-else()
-    set(required_vars
-  SUPERBUILD_BINARY_DIR
-  SUPERBUILD_INSTALL_DIR
-  SUPERBUILD_SOURCE_DIR
-  )
-endif()
-
-foreach(req
-  ${required_vars}
-  PACKAGE_OTB_SRC_DIR
-  OTB_TARGET_SYSTEM_ARCH
-  OTB_TARGET_SYSTEM_ARCH_IS_X64
- )
-  if(NOT DEFINED ${req} OR "${${req}}" STREQUAL "")
-    message(FATAL_ERROR "you must set ${req}")
-  endif()
-  set(vars "${vars}  ${req}=[${${req}}]\n")
-endforeach(req)
-
-message("\n${vars}\n")
-
-set(PKG_OTB_DEBUG OFF)
-
-set(EXTRA_CACHE_CONFIG)
-
-set(CMAKE_INSTALL_PREFIX "${SUPERBUILD_INSTALL_DIR}")
-
-set(PACKAGE_LONG_NAME OrfeoToolBox)
-
-# Make up part of output package file
-set(PACKAGE_NAME OTB)
-if(APPLE)
-  set(PACKAGE_PLATFORM_NAME "Darwin")
-elseif(WIN32)
-  set(PACKAGE_PLATFORM_NAME "win")
-elseif(LINUX)
-  set(PACKAGE_PLATFORM_NAME "Linux")
-endif()
-
-set(PACKAGE_ARCH "32")
-if(OTB_TARGET_SYSTEM_ARCH_IS_X64)
-set(PACKAGE_ARCH "64")
-endif()
-
-if(OTB_MINGW)
-  get_filename_component(MXE_MXEROOT ${MXE_TARGET_DIR} PATH)
-  get_filename_component(MXE_MXEROOT ${MXE_MXEROOT} PATH)
-  set(EXTRA_CACHE_CONFIG
-    "set(CMAKE_CROSSCOMPILING TRUE)
-     set(WIN32 TRUE)
-     set(MINGW TRUE)
-     set(MXE_MXEROOT \"${MXE_MXEROOT}\")"
-    )
-  set(CMAKE_INSTALL_PREFIX "${OTB_INSTALL_DIR}")  
-endif()
-
-# get itk version from External_itk.cmake if not on mingw
-# because mxe has different version
-if(NOT OTB_MINGW)
-  get_version(
-    INPUT_FILE   "${SUPERBUILD_SOURCE_DIR}/CMake/External_itk.cmake"
-    MATCH_STRINGS "SB_ITK_VERSION_MAJOR" "SB_ITK_VERSION_MINOR"
-    PREFIX PKG
-    )
-endif()
-
-set(PKG_ITK_SB_VERSION "${PKG_SB_ITK_VERSION_MAJOR}.${PKG_SB_ITK_VERSION_MINOR}")
-
-#get version of OTB from source_dir/CMakeLists.txt
-get_version(
-  INPUT_FILE   "${PACKAGE_OTB_SRC_DIR}/CMakeLists.txt"
-  MATCH_STRINGS "OTB_VERSION_MAJOR" "OTB_VERSION_MINOR" "OTB_VERSION_PATCH"
-  PREFIX PKG
-  )
-
-set(PKG_OTB_VERSION_STRING
-  ${PKG_OTB_VERSION_MAJOR}.${PKG_OTB_VERSION_MINOR}.${PKG_OTB_VERSION_PATCH})
-
-if(OTB_MINGW)
-  set(OTB_BINARY_DIR              "${OTB_BINARY_DIR}")
-  set(OTB_INSTALL_DIR             "${OTB_INSTALL_DIR}")
-  set(DEPENDENCIES_INSTALL_DIR    "${MXE_MXEROOT}/usr/${OTB_TARGET_SYSTEM_ARCH}-w64-mingw32.shared")
-  set(QT_PLUGINS_DIR              "${DEPENDENCIES_INSTALL_DIR}/qt/plugins")
-  set(QT_TRANSLATIONS_DIR         "${DEPENDENCIES_INSTALL_DIR}/qt/translations")
-else() #unixes
-  set(OTB_BINARY_DIR            "${SUPERBUILD_BINARY_DIR}/OTB/build")
-  set(OTB_INSTALL_DIR           "${SUPERBUILD_INSTALL_DIR}")
-  set(DEPENDENCIES_INSTALL_DIR  "${SUPERBUILD_INSTALL_DIR}")
-  set(QT_PLUGINS_DIR            "${SUPERBUILD_INSTALL_DIR}/plugins")
-  set(QT_TRANSLATIONS_DIR       "${SUPERBUILD_INSTALL_DIR}/translations")
-endif()
-
-macro_setup_cmake_project(OTB)
-if(GENERATE_XDK)
-  macro_setup_cmake_project(XDK)
-endif()
+# cpack has a built-in target called 'package'. In our case we create two standalone installers with
+# and uses a custom target named packages.
+
+# stop generation of msvc packages for windows. 04-apr-2016. point OTB.
+
+##### check if standalone project ######
+set(OUT_OF_SOURCE_BUILD FALSE)
+if(NOT PROJECT_NAME)
+  cmake_minimum_required(VERSION 2.6)
+  include(CMakeParseArguments)
+  project(OTBPackaging)
+
+  option(GENERATE_PACKAGE "Generate OTB package" ON)
+  option(GENERATE_XDK "Generate XDK for OTB development" OFF)
+  
+  set(OUT_OF_SOURCE_BUILD TRUE)
+  
+  if(BUILD_TESTING)
+    include(CTest)
+  endif()
+  
+  if(NOT PACKAGE_OTB_SRC_DIR)
+    get_filename_component(PACKAGE_OTB_SRC_DIR ${OTBPackaging_SOURCE_DIR} PATH)
+    get_filename_component(PACKAGE_OTB_SRC_DIR ${PACKAGE_OTB_SRC_DIR} PATH)
+  endif()
+  
+  option(OTB_WRAP_PYTHON "enable python wrapping" ON)
+  if(OTB_WRAP_PYTHON AND NOT PYTHON_EXECUTABLE)
+    find_package ( PythonInterp REQUIRED )
+    mark_as_advanced(PYTHON_INCLUDE_DIR)
+    mark_as_advanced(PYTHON_LIBRARY)
+  endif()
+
+ if(OTB_MINGW)
+    set(OTB_BINARY_DIR "" CACHE PATH "OTB binary directory")
+    set(OTB_INSTALL_DIR "" CACHE PATH "OTB install directory")
+  else()
+    set(SUPERBUILD_BINARY_DIR "" CACHE PATH "path to superbuild binary directory")
+    set(SUPERBUILD_INSTALL_DIR "" CACHE PATH "path to superbuild install directory")
+    set(DOWNLOAD_LOCATION "" CACHE PATH "path to superbuild download archives")
+  endif()
+  
+else() #if(NOT PROJECT_NAME)
+
+  # SUPERBUILD_BINARY_DIR is only set in Packaging/CMakeLists.txt and not available
+  # in the parent scope like others. So we need to set it as CMAKE_BINARY_DIR
+  # if doing packages from source tree.
+  set( SUPERBUILD_BINARY_DIR   ${CMAKE_BINARY_DIR}     )
+  set( SUPERBUILD_INSTALL_DIR  ${SB_INSTALL_PREFIX}    )
+  set( OTB_INSTALL_DIR         ${CMAKE_INSTALL_PREFIX} )
+  
+  if(NOT PACKAGE_OTB_SRC_DIR)
+    get_filename_component(PACKAGE_OTB_SRC_DIR ${OTB-SuperBuild_SOURCE_DIR} PATH)
+  endif()
+  
+endif()
+
+if(NOT GENERATE_PACKAGE AND NOT GENERATE_XDK)
+  #well. we don't have any businees here. Let's move on..
+  return()
+endif()
+
+set(LINUX FALSE)
+set(OTB_MINGW FALSE)
+if(WIN32 AND NOT MSVC)
+  set(OTB_MINGW TRUE)
+else()
+  if( "${CMAKE_SYSTEM_NAME}"  MATCHES "Linux")
+    set(LINUX TRUE)
+  endif()
+endif()
+
+find_program(FILE_COMMAND "file")
+mark_as_advanced(FILE_COMMAND)
+
+set(SUPERBUILD_SOURCE_DIR ${PACKAGE_OTB_SRC_DIR}/SuperBuild)
+
+include(${SUPERBUILD_SOURCE_DIR}/CMake/SuperBuild_Macro.cmake)
+include(${PACKAGE_OTB_SRC_DIR}/CMake/OTBCheckTargetSystemArch.cmake)
+include(${CMAKE_CURRENT_SOURCE_DIR}/CreateCMakeProjects.cmake)
+
+if(WIN32)
+  set(ZIP_EXE_NAMES 7z 7za)
+  find_program(ZIP_EXECUTABLE NAMES ${ZIP_EXE_NAMES})
+  if(NOT ZIP_EXECUTABLE)
+    message(FATAL_ERROR "Cannot find 7z executable. searched names ${ZIP_EXE_NAMES}. Please add it to your path")
+  endif()
+endif()
+
+if(OTB_MINGW)
+  set(required_vars
+  OTB_BINARY_DIR
+  OTB_INSTALL_DIR
+  MXE_TARGET_DIR
+  )
+else()
+    set(required_vars
+  SUPERBUILD_BINARY_DIR
+  SUPERBUILD_INSTALL_DIR
+  SUPERBUILD_SOURCE_DIR
+  )
+endif()
+
+foreach(req
+  ${required_vars}
+  PACKAGE_OTB_SRC_DIR
+  OTB_TARGET_SYSTEM_ARCH
+  OTB_TARGET_SYSTEM_ARCH_IS_X64
+ )
+  if(NOT DEFINED ${req} OR "${${req}}" STREQUAL "")
+    message(FATAL_ERROR "you must set ${req}")
+  endif()
+  set(vars "${vars}  ${req}=[${${req}}]\n")
+endforeach(req)
+
+message("\n${vars}\n")
+
+set(PKG_DEBUG OFF)
+
+set(EXTRA_CACHE_CONFIG)
+
+set(CMAKE_INSTALL_PREFIX "${SUPERBUILD_INSTALL_DIR}")
+
+set(PACKAGE_LONG_NAME OrfeoToolBox)
+
+# Make up part of output package file
+set(PACKAGE_NAME OTB)
+if(APPLE)
+  set(PACKAGE_PLATFORM_NAME "Darwin")
+elseif(WIN32)
+  set(PACKAGE_PLATFORM_NAME "win")
+elseif(LINUX)
+  set(PACKAGE_PLATFORM_NAME "Linux")
+endif()
+
+set(PACKAGE_ARCH "32")
+if(OTB_TARGET_SYSTEM_ARCH_IS_X64)
+set(PACKAGE_ARCH "64")
+endif()
+
+if(OTB_MINGW)
+  get_filename_component(MXE_MXEROOT ${MXE_TARGET_DIR} PATH)
+  get_filename_component(MXE_MXEROOT ${MXE_MXEROOT} PATH)
+  set(EXTRA_CACHE_CONFIG
+    "set(CMAKE_CROSSCOMPILING TRUE)
+     set(WIN32 TRUE)
+     set(MINGW TRUE)
+     set(MXE_MXEROOT \"${MXE_MXEROOT}\")"
+    )
+  set(CMAKE_INSTALL_PREFIX "${OTB_INSTALL_DIR}")  
+endif()
+
+# get itk version from External_itk.cmake if not on mingw
+# because mxe has different version
+if(NOT OTB_MINGW)
+  get_version(
+    INPUT_FILE   "${SUPERBUILD_SOURCE_DIR}/CMake/External_itk.cmake"
+    MATCH_STRINGS "SB_ITK_VERSION_MAJOR" "SB_ITK_VERSION_MINOR"
+    PREFIX PKG
+    )
+endif()
+
+set(PKG_ITK_SB_VERSION "${PKG_SB_ITK_VERSION_MAJOR}.${PKG_SB_ITK_VERSION_MINOR}")
+
+#get version of OTB from source_dir/CMakeLists.txt
+get_version(
+  INPUT_FILE   "${PACKAGE_OTB_SRC_DIR}/CMakeLists.txt"
+  MATCH_STRINGS "OTB_VERSION_MAJOR" "OTB_VERSION_MINOR" "OTB_VERSION_PATCH"
+  PREFIX PKG
+  )
+
+set(PKG_OTB_VERSION_STRING
+  ${PKG_OTB_VERSION_MAJOR}.${PKG_OTB_VERSION_MINOR}.${PKG_OTB_VERSION_PATCH})
+
+if(OTB_MINGW)
+  set(OTB_BINARY_DIR              "${OTB_BINARY_DIR}")
+  set(OTB_INSTALL_DIR             "${OTB_INSTALL_DIR}")
+  set(DEPENDENCIES_INSTALL_DIR    "${MXE_MXEROOT}/usr/${OTB_TARGET_SYSTEM_ARCH}-w64-mingw32.shared")
+  set(QT_PLUGINS_DIR              "${DEPENDENCIES_INSTALL_DIR}/qt/plugins")
+  set(QT_TRANSLATIONS_DIR         "${DEPENDENCIES_INSTALL_DIR}/qt/translations")
+else() #unixes
+  set(OTB_BINARY_DIR            "${SUPERBUILD_BINARY_DIR}/OTB/build")
+  set(OTB_INSTALL_DIR           "${SUPERBUILD_INSTALL_DIR}")
+  set(DEPENDENCIES_INSTALL_DIR  "${SUPERBUILD_INSTALL_DIR}")
+  set(QT_PLUGINS_DIR            "${SUPERBUILD_INSTALL_DIR}/plugins")
+  set(QT_TRANSLATIONS_DIR       "${SUPERBUILD_INSTALL_DIR}/translations")
+endif()
+
+macro_setup_cmake_project(OTB)
+if(GENERATE_XDK)
+  macro_setup_cmake_project(XDK)
+endif()
diff --git a/SuperBuild/Packaging/CreateCMakeProjects.cmake b/SuperBuild/Packaging/CreateCMakeProjects.cmake
index f68e0356a6d1678f51da18e8e0c7d087a0b4b562..b21a95cb0df62f9068216b955aa09017db41679b 100644
--- a/SuperBuild/Packaging/CreateCMakeProjects.cmake
+++ b/SuperBuild/Packaging/CreateCMakeProjects.cmake
@@ -16,7 +16,6 @@ macro(macro_setup_cmake_project pkg)
   else()
     set(PKG_GENERATE_XDK OFF)
   endif()
-
  
   if(PKG_GENERATE_XDK)
     set(archive_name ${PACKAGE_NAME}-${PKG_OTB_VERSION_STRING}-xdk-${PACKAGE_PLATFORM_NAME}${PACKAGE_ARCH})
@@ -49,7 +48,8 @@ macro(macro_setup_cmake_project pkg)
    set(OTB_TARGET_SYSTEM_ARCH        ${OTB_TARGET_SYSTEM_ARCH})
    set(OTB_TARGET_SYSTEM_ARCH_IS_X64 ${OTB_TARGET_SYSTEM_ARCH_IS_X64})   
    set(OTB_WRAP_PYTHON               ${OTB_WRAP_PYTHON})
-   set(PKG_OTB_DEBUG                 ${PKG_OTB_DEBUG})
+   set(PKG_DEBUG                     ${PKG_DEBUG})
+   set(FILE_COMMAND                  \"${FILE_COMMAND}\")
    ${EXTRA_CACHE_CONFIG}
    include(${SUPERBUILD_SOURCE_DIR}/Packaging/PackageMacros.cmake)
    include(${SUPERBUILD_SOURCE_DIR}/Packaging/PackageHelper.cmake)
diff --git a/SuperBuild/Packaging/PackageGlobals.cmake b/SuperBuild/Packaging/PackageGlobals.cmake
index 47f8fff5763619e7266d3a531bf2f9173b61a2d0..d59c32f730d97b30baa6ec8155d2154f89d9abdc 100644
--- a/SuperBuild/Packaging/PackageGlobals.cmake
+++ b/SuperBuild/Packaging/PackageGlobals.cmake
@@ -101,6 +101,15 @@ else() #case for unixes
   endif()
 endif(WIN32)
 
+# Take gtk libs from system. we should fix this to take from custom
+# build location
+set(PKG_GTK_SEARCHDIRS
+  /usr/lib64
+  /lib64
+  /lib/x86_64-linux-gnu/
+  /usr/lib/x86_64-linux-gnu/
+  )
+
 #superbuild cannot manage build of gtk2+ just for qt gtkstyle.
 # -gtkstyle option is deactivated by default in build of QT4
 # So the list of requirements on building OTB with superbuild stays same.
@@ -117,4 +126,5 @@ set(ALLOWED_SYSTEM_DLLS
   libgobject-2.0.so.0
   libXrender.so.1
   libfontconfig.so.1
+  libpcre.so.3
   )
diff --git a/SuperBuild/Packaging/PackageHelper.cmake b/SuperBuild/Packaging/PackageHelper.cmake
index f6e670522f2c4aec213eacd7f0e86b216a7149c5..88061550968272491accd8c33299514e2c6eaa29 100644
--- a/SuperBuild/Packaging/PackageHelper.cmake
+++ b/SuperBuild/Packaging/PackageHelper.cmake
@@ -14,9 +14,18 @@ macro(macro_super_package)
     message(FATAL_ERROR "DEPENDENCIES_INSTALL_DIR is not set of empty")
   endif()
 
-  if(LINUX AND NOT PATCHELF_PROGRAM)
-    message(FATAL_ERROR "PATCHELF_PROGRAM not set")
-  endif()
+  if(LINUX)
+    if(NOT FILE_COMMAND)
+      message(FATAL_ERROR "warning: No 'file' command, cannot continue...")
+    endif()
+
+    if(NOT PATCHELF_PROGRAM)
+      message(FATAL_ERROR "PATCHELF_PROGRAM not set")
+    endif()
+  endif(LINUX)
+  
+  #setting this variable. prints a lot of debug information
+  #set( PKG_DEBUG 1)
 
   set(loader_program_PATHS)
   set(eol_char "E")
@@ -48,7 +57,7 @@ macro(macro_super_package)
   if(NOT LOADER_PROGRAM)
     message(FATAL_ERROR "${loader_program_names} not found in ${loader_program_PATHS}.")
   endif()
-  
+
   include(GetPrerequisites)
 
   set(LOADER_PROGRAM_ARGS ${loader_program_args})
@@ -307,29 +316,40 @@ function(func_prepare_package)
   unset(matched_vars CACHE)
   get_vars_ending_with("_USED|_RESOLVED" matched_vars)
   foreach (var_to_unset IN LISTS matched_vars)
-    if(PKG_OTB_DEBUG)
+    if(PKG_DEBUG)
       message("unset ${var_to_unset} from cache")
     endif()
     unset(${var_to_unset} CACHE)
   endforeach()
-  
- 
+
   foreach(infile ${PKG_PEFILES})
    get_filename_component(bn ${infile} NAME)
    func_process_deps(${bn})
   endforeach()
-
  
 endfunction() #func_prepare_package
 
 function(func_process_deps input_file)
+
   search_library(${input_file} PKG_SEARCHDIRS input_file_full_path)
   if(NOT input_file_full_path)
-    message(FATAL_ERROR "${input_file} not found. searched in ${PKG_SEARCHDIRS}")
-  endif()
-  
+    if(LINUX)
+      setif_value_in_list(is_gtk_lib "${input_file}" ALLOWED_SYSTEM_DLLS)
+      if(is_gtk_lib)
+	search_library(${input_file} PKG_GTK_SEARCHDIRS input_file_full_path)
+	if( NOT input_file_full_path)
+	  message(FATAL_ERROR "${input_file} not found. searched in ${PKG_GTK_SEARCHDIRS}")
+	endif()
+      endif()
+      if( NOT input_file_full_path)
+	message(FATAL_ERROR "${input_file} not found. searched in ${PKG_SEARCHDIRS}")
+	endif()
+    endif(LINUX)
+
+  endif() #if(NOT input_file_full_path)
+
   message("Processing ${input_file_full_path}")
- 
+
   set(is_executable FALSE)
   is_file_executable2("${input_file_full_path}" is_executable)
   if(NOT is_executable)
@@ -421,28 +441,35 @@ function(func_process_deps input_file)
       continue()        
     endif()
    
-    if(PKG_OTB_DEBUG)
+    if(PKG_DEBUG)
       message("${raw_item} is not resolved, used. ${raw_item}_RESOLVED | ${raw_item}_USED")
     endif()
     
     list(APPEND raw_items ${raw_item})
     
   endforeach()
-  
-  if(PKG_OTB_DEBUG)
-    message(FATAL_ERROR "raw_items=${raw_items}")
-  endif(PKG_OTB_DEBUG)
-   
+
+  if(PKG_DEBUG)
+    string(REPLACE ";" "\n" raw_items_pretty_print "${raw_items}")
+    message(FATAL_ERROR "raw_items=${raw_items_pretty_print}")
+  endif(PKG_DEBUG)
+
   if(raw_items)
     list(REVERSE raw_items)
     foreach(item ${raw_items})      
       search_library(${item} PKG_SEARCHDIRS item_full_path)
       set(is_a_symlink FALSE)
       set(item_target_file)
+      if(PKG_DEBUG)
+	message("item0=${item_full_path}")
+      endif()
       func_is_file_a_symbolic_link("${item_full_path}" is_a_symlink item_target_file)      
       if(is_a_symlink)
 	set(${item}_RESOLVED TRUE CACHE INTERNAL "")
-	set(item ${item_target_file})     
+	set(item ${item_target_file})
+      endif()
+      if(PKG_DEBUG)
+	message("running func_process_deps on '${item}'")
       endif()
       func_process_deps(${item})
   endforeach()
diff --git a/SuperBuild/Packaging/PackageMacros.cmake b/SuperBuild/Packaging/PackageMacros.cmake
index a04a4bb0a4c8a0e4ca4b498c6f19472bb321f6be..6a2084b8aa78c8ea6e620ff0d666db3ebfce7fc7 100755
--- a/SuperBuild/Packaging/PackageMacros.cmake
+++ b/SuperBuild/Packaging/PackageMacros.cmake
@@ -1,18 +1,18 @@
 function(find_python_soname result)
-set(${result} PARENT_SCOPE)
-    execute_process(
-      COMMAND ${PYTHON_EXECUTABLE}
-      -c
-      "import sys; from distutils import sysconfig; print (sysconfig.get_config_var('INSTSONAME'));"
-      RESULT_VARIABLE python_INSTALLED_SONAME_rv
-      OUTPUT_VARIABLE python_INSTALLED_SONAME_ov
-      )
+  set(${result} PARENT_SCOPE)
+  execute_process(
+    COMMAND ${PYTHON_EXECUTABLE}
+    -c
+    "import sys; from distutils import sysconfig; print (sysconfig.get_config_var('INSTSONAME'));"
+    RESULT_VARIABLE python_INSTALLED_SONAME_rv
+    OUTPUT_VARIABLE python_INSTALLED_SONAME_ov
+    )
 
-    if(NOT python_INSTALLED_SONAME_rv EQUAL 0)
-      message( FATAL_ERROR
-	"python_INSTALLED_SONAME_rv=${python_INSTALLED_SONAME_rv}: Cannot find python library")
-    endif()
-    set(${result} "${python_INSTALLED_SONAME_ov}" PARENT_SCOPE)
+  if(NOT python_INSTALLED_SONAME_rv EQUAL 0)
+    message( FATAL_ERROR
+      "python_INSTALLED_SONAME_rv=${python_INSTALLED_SONAME_rv}: Cannot find python library")
+  endif()
+  set(${result} "${python_INSTALLED_SONAME_ov}" PARENT_SCOPE)
 endfunction()
 
 
@@ -22,7 +22,7 @@ function(func_install_without_message src_dir dst_dir_suffix)
   if (${num_extra_args} GREATER 0)
     list(GET extra_func_args 0 optional_msg)
   endif()
- 
+
   if( "${dst_dir_suffix}" STREQUAL "")
     set(dst_dir "${PKG_STAGE_DIR}")
   else()
@@ -51,27 +51,24 @@ endmacro() #macro_empty_package_staging_directory
 
 function(search_library input_file pkg_searchdirs result)
   set(${result} "" PARENT_SCOPE)
-  set(found_lib FALSE) 
-  foreach(SEARCHDIR ${${pkg_searchdirs}})
-    if(EXISTS ${SEARCHDIR}/${input_file} )
-      set(${result} "${SEARCHDIR}/${input_file}" PARENT_SCOPE)
+  foreach(pkg_searchdir ${${pkg_searchdirs}})
+
+    if(EXISTS ${pkg_searchdir}/${input_file} )
+      if(PKG_DEBUG)
+	message("searching for '${input_file}' in '${pkg_searchdir}'")
+      endif()
+      set(${result} "${pkg_searchdir}/${input_file}" PARENT_SCOPE)
       return()
     endif()
-    
+
+    #check for file with lowercase
     string(TOLOWER "${input_file}" input_file_lower )
-    if(EXISTS ${SEARCHDIR}/${input_file_lower})
-      set(${result} "${SEARCHDIR}/${input_file_lower}"  PARENT_SCOPE)
+    if(EXISTS ${pkg_searchdir}/${input_file_lower})
+      set(${result} "${pkg_searchdir}/${input_file_lower}"  PARENT_SCOPE)
       return()
     endif()
-  endforeach() 
+  endforeach()
 
-  if(NOT found_lib)
-    check_for_gtk_libs(${input_file} gtk_lib_full_path)  
-    if(gtk_lib_full_path)
-      set(${result} "${gtk_lib_full_path}" PARENT_SCOPE)
-    endif()
-  endif()
-    
 endfunction()
 
 macro(add_to_symlink_list src_file target_file)
@@ -96,41 +93,13 @@ macro(add_to_symlink_list src_file target_file)
   # NOTE: $OUT_DIR is set actually in pkgsetup.in. So don't try
   # any pre-mature optimization on that variable names
   if(NOT SKIP_INSTALL)
-  file(APPEND 
-    ${CMAKE_BINARY_DIR}/make_symlinks_temp
-    "ln -sf \"$OUT_DIR/lib/${src_file}\" \"$OUT_DIR/lib/${target_file}\" \n"
-    )
+    file(APPEND
+      ${CMAKE_BINARY_DIR}/make_symlinks_temp
+      "ln -sf \"$OUT_DIR/lib/${src_file}\" \"$OUT_DIR/lib/${target_file}\" \n"
+      )
   endif()
 endmacro()
 
-function(check_for_gtk_libs input_file result)
-  # Take gtk libs from system. we should fix this to take from custom
-  # build location
-  set(GTK_LIBS_SEARCH_PATHS
-    /usr/lib64
-    /lib64
-     )
-  
-  set(${result} "" PARENT_SCOPE)
-  if(NOT LINUX)
-    return()
-  endif()
-
-
- setif_value_in_list(is_allowed "${input_file}" ALLOWED_SYSTEM_DLLS)   
-  if(NOT is_allowed)
-    return()
-  endif()
-  
-   foreach( search_path ${GTK_LIBS_SEARCH_PATHS})
-     if(EXISTS ${search_path}/${input_file} )
-       set(${result} ${search_path}/${input_file} PARENT_SCOPE)
-       endif()
-     endforeach()
- 
-endfunction()
-
-
 function(is_file_executable2 file result_var)
   #
   # A file is not executable until proven otherwise:
@@ -152,6 +121,14 @@ function(is_file_executable2 file result_var)
     # to determine ${result_var}. In 99%+? practical cases, the exe name
     # match will be sufficient...
     #
+  endif() #WIN32 AND NOT UNIX
+
+  func_is_file_a_symbolic_link("${file_full}" is_a_symlink file_full_target)
+  if(is_a_symlink)
+    message("resolving '${file_full}' to  '${file_full_target}")
+    get_filename_component(file_full_path "${file_full}" PATH)
+    set(file_full "${file_full_path}/${file_full_target}")
+    string(TOLOWER "${file_full}" file_full_lower)
   endif()
 
   # Use the information returned from the Unix shell command "file" to
@@ -161,96 +138,97 @@ function(is_file_executable2 file result_var)
   # "text" then it is likely an executable suitable for prerequisite analysis
   # via the get_prerequisites macro.
   #
-  if(UNIX)
-    if(NOT file_cmd)
-      find_program(file_cmd "file")
-      mark_as_advanced(file_cmd)
-    endif()
-
-    if(file_cmd)
-      execute_process(COMMAND "${file_cmd}" "${file_full}"
-        RESULT_VARIABLE file_rv
-        OUTPUT_VARIABLE file_ov
-        ERROR_VARIABLE file_ev
-        OUTPUT_STRIP_TRAILING_WHITESPACE
-        )
-      if(NOT file_rv STREQUAL "0")
-        message(FATAL_ERROR "${file_cmd} failed: ${file_rv}\n${file_ev}")
-      endif()
+  #if we are not on a unix or unix-like platform, then we don't have any business here
+  if(NOT UNIX)
+    return()
+  endif()
 
-      # Replace the name of the file in the output with a placeholder token
-      # (the string " _file_full_ ") so that just in case the path name of
-      # the file contains the word "text" or "executable" we are not fooled
-      # into thinking "the wrong thing" because the file name matches the
-      # other 'file' command output we are looking for...
-      #
-      string(REPLACE "${file_full}" " _file_full_ " file_ov "${file_ov}")
-      string(TOLOWER "${file_ov}" file_ov)
-
-      #message(STATUS "file_ov='${file_ov}'")
-      #below executable check works for both mac osx and linux
-      if("${file_ov}" MATCHES "executable")
-        #message(STATUS "executable!")
-        if("${file_ov}" MATCHES "text")
-	  set(${result_var} 0 PARENT_SCOPE)
-          #message(FATAL_ERROR "but text, so *not* a binary executable!")
-        else()
-          set(${result_var} 1 PARENT_SCOPE)
-          return()
-        endif()
-      endif()
+  if(NOT FILE_COMMAND)
+    message(FATAL_ERROR "warning: No 'file' command, cannot continue...")
+  endif()
 
-      # Also detect position independent executables on Linux,
-      # where "file" gives "dynamically linked (uses shared libraries)"
-      if("${file_ov}" MATCHES "dynamically linked.*\(uses shared libs\)")
-        set(${result_var} 1 PARENT_SCOPE)
-        return()
-      endif()
-      
-      # Also detect position independent executables on Linux,
-      # where "file" gives "shared object ... (uses shared libraries)"
-      if("${file_ov}" MATCHES "shared object.*\(uses shared libs\)")
-        set(${result_var} 1 PARENT_SCOPE)
-        return()
-      endif()
+  if(NOT EXISTS "${file_full}")
+    message(FATAL_ERROR "err. '${file_full}' does not exists or is not absolute path")
+  endif()
 
-      # Also detect shared libraries on Linux,
-      # where "file" gives "ELF 64-bit LSB shared object, AMD x86-64, version 1 (SYSV), not stripped"
-      if("${file_ov}" MATCHES "elf.*shared object.*version")
-        set(${result_var} 1 PARENT_SCOPE)
-        return()
-      endif()
-      
-      # "file" version 5.22 does not print "(used shared libraries)"
-      # but uses "interpreter"
-      if("${file_ov}" MATCHES "shared object.*interpreter")
-        set(${result_var} 1 PARENT_SCOPE)
-        return()
-      endif()
+  execute_process(COMMAND "${FILE_COMMAND}" "${file_full}"
+    RESULT_VARIABLE file_rv
+    OUTPUT_VARIABLE file_ov
+    ERROR_VARIABLE file_ev
+    OUTPUT_STRIP_TRAILING_WHITESPACE
+    )
+  if(NOT file_rv STREQUAL "0")
+    message(FATAL_ERROR "${FILE_COMMAND} failed: ${file_rv}\n${file_ev}")
+  endif()
 
-      if(APPLE)
-	# detect shared libraries on Mac OSX
-	# where "file" gives "Mach-O 64-bit x86_64 dynamically linked shared library"
-	if("${file_ov}" MATCHES "mach-o.*dynamically linked shared library")
-          set(${result_var} 1 PARENT_SCOPE)
-          return()
-	endif()
-	
-	
-	#below check is redundant.
-	# detect executables on Mac OSX
-	# where "file" gives "Mach-O 64-bit x86_64 executable"
-	if("${file_ov}" MATCHES "mach-o.*executable")
-          set(${result_var} 1 PARENT_SCOPE)
-          return()
-	endif()
-	
-      endif(APPLE)
-    
+  # Replace the name of the file in the output with a placeholder token
+  # (the string " _file_full_ ") so that just in case the path name of
+  # the file contains the word "text" or "executable" we are not fooled
+  # into thinking "the wrong thing" because the file name matches the
+  # other 'file' command output we are looking for...
+  #
+  string(REPLACE "${file_full}" " _file_full_ " file_ov "${file_ov}")
+  string(TOLOWER "${file_ov}" file_ov)
+
+  # message(STATUS "file_ov='${file_ov}'")
+  # below executable check works for both mac osx and linux
+  # message("file_full=${file_ov}")
+  if("${file_ov}" MATCHES "executable")
+    #message(STATUS "executable!")
+    if("${file_ov}" MATCHES "text")
+      set(${result_var} 0 PARENT_SCOPE)
+      #message(FATAL_ERROR "but text, so *not* a binary executable!")
     else()
-      message(STATUS "warning: No 'file' command, skipping execute_process...")
+      set(${result_var} 1 PARENT_SCOPE)
+      return()
     endif()
   endif()
+
+  # detect position independent executables on Linux,
+  # where "file" gives "dynamically linked (uses shared libraries)"
+  if("${file_ov}" MATCHES "dynamically linked.*\(uses shared libs\)")
+    set(${result_var} 1 PARENT_SCOPE)
+    return()
+  endif()
+
+  # detect position independent executables on Linux,
+  # where "file" gives "shared object ... (uses shared libraries)"
+  if("${file_ov}" MATCHES "shared object.*\(uses shared libs\)")
+    set(${result_var} 1 PARENT_SCOPE)
+    return()
+  endif()
+
+  # detect shared libraries on Linux,
+  # where "file" gives "ELF 64-bit LSB shared object, AMD x86-64, version 1 (SYSV), not stripped"
+  if("${file_ov}" MATCHES "elf.*shared object.*version")
+    set(${result_var} 1 PARENT_SCOPE)
+    return()
+  endif()
+
+  # "file" version 5.22 does not print "(used shared libraries)"
+  # but uses "interpreter"
+  if("${file_ov}" MATCHES "shared object.*interpreter")
+    set(${result_var} 1 PARENT_SCOPE)
+    return()
+  endif()
+
+  if(APPLE)
+    # detect shared libraries on Mac OSX
+    # where "file" gives "Mach-O 64-bit x86_64 dynamically linked shared library"
+    if("${file_ov}" MATCHES "mach-o.*dynamically linked shared library")
+      set(${result_var} 1 PARENT_SCOPE)
+      return()
+    endif()
+
+    #below check is redundant.  detect executables on Mac OSX
+    # where "file" gives "Mach-O 64-bit x86_64 executable"
+    if("${file_ov}" MATCHES "mach-o.*executable")
+      set(${result_var} 1 PARENT_SCOPE)
+      return()
+    endif()
+
+  endif(APPLE)
+
 endfunction()
 
 
@@ -283,6 +261,11 @@ function(func_is_file_a_symbolic_link file result_var1 result_var2)
     #
   endif()
 
+  #if we are not on a unix or unix-like platform, then we don't have any business here
+  if(NOT UNIX)
+    return()
+  endif()
+
   # Use the information returned from the Unix shell command "file" to
   # determine if ${file_full} should be considered an executable file...
   #
@@ -290,59 +273,50 @@ function(func_is_file_a_symbolic_link file result_var1 result_var2)
   # "text" then it is likely an executable suitable for prerequisite analysis
   # via the get_prerequisites macro.
   #
-  if(UNIX)
-    if(NOT file_cmd)
-      find_program(file_cmd "file")
-      mark_as_advanced(file_cmd)
-    endif()
+  if(NOT FILE_COMMAND)
+    message(FATAL_ERROR "warning: No 'file' command, cannot continue...")
+  endif()
 
-    if(file_cmd)
-      execute_process(COMMAND "${file_cmd}" "${file_full}"
-        RESULT_VARIABLE file_rv
-        OUTPUT_VARIABLE file_ov
-        ERROR_VARIABLE file_ev
-        OUTPUT_STRIP_TRAILING_WHITESPACE
-        )
-      if(NOT file_rv STREQUAL "0")
-        message(FATAL_ERROR "${file_cmd} failed: ${file_rv}\n${file_ev}")
-      endif()
+  execute_process(COMMAND "${FILE_COMMAND}" "${file_full}"
+    RESULT_VARIABLE file_rv
+    OUTPUT_VARIABLE file_ov
+    ERROR_VARIABLE file_ev
+    OUTPUT_STRIP_TRAILING_WHITESPACE
+    )
+  if(NOT file_rv STREQUAL "0")
+    message(FATAL_ERROR "${FILE_COMMAND} failed: ${file_rv}\n${file_ev}")
+  endif()
 
-      # Replace the name of the file in the output with a placeholder token
-      # (the string " _file_full_ ") so that just in case the path name of
-      # the file contains the word "text" or "executable" we are not fooled
-      # into thinking "the wrong thing" because the file name matches the
-      # other 'file' command output we are looking for...
-      #
-      string(REPLACE "${file_full}" " _file_full_ " file_ov "${file_ov}")
-      string(TOLOWER "${file_ov}" file_ov_lower)
-
-      #message(FATAL_ERROR "file_ov='${file_ov}'")
-      if("${file_ov_lower}" MATCHES "symbolic link")
-        set(${result_var1} 1 PARENT_SCOPE)
-        #Now find where the symlink is linked to.
-        #Do a regex replace
-        if(UNIX)
-          if(APPLE)
-            string(REGEX REPLACE "_file_full_*.*symbolic.link.to."
-              "" symlinked_to ${file_ov})
-          else(APPLE)
-            string(REGEX REPLACE "_file_full_*.*symbolic.link.to.."
-              "" symlinked_to ${file_ov})
-          endif(APPLE)
-        endif(UNIX)
-        #Take out last character which is a single quote
-        string(REPLACE "'" "" symlinked_to "${symlinked_to}")
-        #strip for our own sanity
-        string(STRIP ${symlinked_to} symlinked_to)
-        set(${result_var2} "${symlinked_to}" PARENT_SCOPE)
-        #message(FATAL_ERROR "${file_full} is symlinked_to ${symlinked_to}")
-        return()
-      endif()
+  # Replace the name of the file in the output with a placeholder token
+  # (the string " _file_full_ ") so that just in case the path name of
+  # the file contains the word "text" or "executable" we are not fooled
+  # into thinking "the wrong thing" because the file name matches the
+  # other 'file' command output we are looking for...
+  #
+  string(REPLACE "${file_full}" " _file_full_ " file_ov "${file_ov}")
+  string(TOLOWER "${file_ov}" file_ov_lower)
 
-    else()
-      message(STATUS "warning: No 'file' command, skipping execute_process...")
-    endif()
+  # message(FATAL_ERROR "file_ov='${file_ov}'")
+  if("${file_ov_lower}" MATCHES "symbolic link")
+    set(${result_var1} 1 PARENT_SCOPE)
+    #Now find where the symlink is linked to.
+    #Do a regex replace
+    string(REGEX REPLACE "_file_full_*.*symbolic.link.to." "" symlinked_to ${file_ov})
+
+    #older version of file command output has  [`} character(remove it).
+    string(REPLACE "`" "" symlinked_to ${symlinked_to} )
+
+    #older version of file command output has  {'} character(remove it).
+    string(REPLACE "'" "" symlinked_to "${symlinked_to}")
+
+    #strip final output
+    string(STRIP ${symlinked_to} symlinked_to)
+    set(${result_var2} "${symlinked_to}" PARENT_SCOPE)
+
+    #message(FATAL_ERROR "${file_full} is symlinked_to ${symlinked_to}")
+    return()
   endif()
+
 endfunction()
 
 macro(setif_value_in_list matched value list)
@@ -354,11 +328,11 @@ macro(setif_value_in_list matched value list)
       set(${matched} TRUE)
     endif()
   endforeach()
-#message("'${value}' not found in ${list}")  
+  #message("'${value}' not found in ${list}")
 endmacro()
 
 function (get_vars_ending_with suffix result)
   get_cmake_property(all_cmake_vars VARIABLES)
   string (REGEX MATCHALL "(^|;)[A-Za-z0-9_\\.\\-]*(${suffix})" _matchedVars "${all_cmake_vars}")
-  set (${result} ${_matchedVars} PARENT_SCOPE)
+  set(${result} ${_matchedVars} PARENT_SCOPE)
 endfunction()