From 3df4098d9b626d3092e9de9facb06650282fa0cf Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Thu, 21 Sep 2017 15:48:25 +0200
Subject: [PATCH] support iOS11

---
 CMakeLists.txt                                      | 1 +
 Common/OS.cpp                                       | 2 ++
 Common/onelab.h                                     | 2 ++
 contrib/mobile/iOS/Onelab.xcodeproj/project.pbxproj | 2 ++
 contrib/mobile/iOS/Onelab/Onelab-Info.plist         | 2 ++
 contrib/mobile/iOS/Onelab/emulatorFix.c             | 5 -----
 contrib/mobile/utils/ios_build.sh                   | 2 +-
 7 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7ea3e8c79d..8ebd0c6bce 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -579,6 +579,7 @@ if(ENABLE_BUILD_IOS)
   if(NOT CMAKE_TOOLCHAIN_FILE)
     message(FATAL_ERROR "Cannot compile Gmsh for iOS without a toolchain")
   endif(NOT CMAKE_TOOLCHAIN_FILE)
+  add_definitions(-DBUILD_IOS)
 endif(ENABLE_BUILD_IOS)
 
 if(HAVE_FLTK OR HAVE_QT OR ENABLE_GRAPHICS)
diff --git a/Common/OS.cpp b/Common/OS.cpp
index 8ed61b4909..c03afab62b 100644
--- a/Common/OS.cpp
+++ b/Common/OS.cpp
@@ -579,6 +579,8 @@ int SystemCallExe(const std::string &exe, const std::string &argsOrCommand,
 		    &suInfo, &prInfo);
     }
   }
+#elif(BUILD_IOS)
+  Msg::Warning("SystemCall is not supported on iOS");
 #else
   std::string cmd(command);
   if(isPython || isOctave || isExe){
diff --git a/Common/onelab.h b/Common/onelab.h
index 347af79592..2fbcdc3ffa 100644
--- a/Common/onelab.h
+++ b/Common/onelab.h
@@ -1548,6 +1548,7 @@ namespace onelab{
     }
     void runNonBlockingSubClient(const std::string &name, const std::string &command)
     {
+#if !defined(BUILD_IOS)
       if(!_gmshClient){
         int res = system(command.c_str());
         if(res){
@@ -1555,6 +1556,7 @@ namespace onelab{
         }
         return;
       }
+#endif
       std::string msg = name + parameter::charSep() + command;
       _gmshClient->SendMessage(GmshSocket::GMSH_CONNECT, msg.size(), &msg[0]);
       _numSubClients += 1;
diff --git a/contrib/mobile/iOS/Onelab.xcodeproj/project.pbxproj b/contrib/mobile/iOS/Onelab.xcodeproj/project.pbxproj
index 7f49cd8062..873da030d7 100644
--- a/contrib/mobile/iOS/Onelab.xcodeproj/project.pbxproj
+++ b/contrib/mobile/iOS/Onelab.xcodeproj/project.pbxproj
@@ -465,6 +465,7 @@
 				);
 				GCC_PRECOMPILE_PREFIX_HEADER = YES;
 				GCC_PREFIX_HEADER = "Onelab/Onelab-Prefix.pch";
+                                GCC_PREPROCESSOR_DEFINITIONS = (BUILD_IOS, "DEBUG=1", "$(inherited)");
 				INFOPLIST_FILE = "Onelab/Onelab-Info.plist";
 				IPHONEOS_DEPLOYMENT_TARGET = 8.0;
 				LIBRARY_SEARCH_PATHS = (
@@ -493,6 +494,7 @@
 				);
 				GCC_PRECOMPILE_PREFIX_HEADER = YES;
 				GCC_PREFIX_HEADER = "Onelab/Onelab-Prefix.pch";
+                                GCC_PREPROCESSOR_DEFINITIONS = BUILD_IOS;
 				INFOPLIST_FILE = "Onelab/Onelab-Info.plist";
 				IPHONEOS_DEPLOYMENT_TARGET = 8.0;
 				LIBRARY_SEARCH_PATHS = (
diff --git a/contrib/mobile/iOS/Onelab/Onelab-Info.plist b/contrib/mobile/iOS/Onelab/Onelab-Info.plist
index ae5b56279f..7d253f6102 100644
--- a/contrib/mobile/iOS/Onelab/Onelab-Info.plist
+++ b/contrib/mobile/iOS/Onelab/Onelab-Info.plist
@@ -44,6 +44,8 @@
     <true/>
     <key>UIFileSharingEnabled</key>
     <true/>
+    <key>LSSupportsOpeningDocumentsInPlace</key>
+    <true/>
     <key>UIMainStoryboardFile</key>
     <string>iPhoneiPodStoryboard</string>
     <key>UIMainStoryboardFile~ipad</key>
diff --git a/contrib/mobile/iOS/Onelab/emulatorFix.c b/contrib/mobile/iOS/Onelab/emulatorFix.c
index c1bc6137a5..4841b5ede0 100644
--- a/contrib/mobile/iOS/Onelab/emulatorFix.c
+++ b/contrib/mobile/iOS/Onelab/emulatorFix.c
@@ -177,8 +177,3 @@ double strtod$UNIX2003(const char *restrict nptr, char **restrict endptr)
 {
   return strtod(nptr, endptr);
 }
-
-int system$UNIX2003(const char *command)
-{
-  return system(command);
-}
diff --git a/contrib/mobile/utils/ios_build.sh b/contrib/mobile/utils/ios_build.sh
index ebde9e933a..b348197200 100755
--- a/contrib/mobile/utils/ios_build.sh
+++ b/contrib/mobile/utils/ios_build.sh
@@ -54,7 +54,7 @@ getdp_framework="$frameworks_dir/GetDP.framework"
 occt_framework="$frameworks_dir/OCCT.framework"
 
 if [ $enable_simulator != 0 ]; then
-  cmake_default="-DDEFAULT=0 -DCMAKE_TOOLCHAIN_FILE=$gmsh_git/contrib/mobile/utils/iOS.cmake -DIOS_PLATFORM=SIMULATOR -DENABLE_BUILD_IOS=1 -DCMAKE_BUILD_TYPE=Release -DCMAKE_OSX_ARCHITECTURES=i386;x86_64 -GXcode"
+  cmake_default="-DDEFAULT=0 -DCMAKE_TOOLCHAIN_FILE=$gmsh_git/contrib/mobile/utils/iOS.cmake -DIOS_PLATFORM=SIMULATOR -DENABLE_BUILD_IOS=1 -DCMAKE_BUILD_TYPE=Release -DCMAKE_OSX_ARCHITECTURES=x86_64 -GXcode"
 else
   cmake_default="-DDEFAULT=0 -DCMAKE_TOOLCHAIN_FILE=$gmsh_git/contrib/mobile/utils/iOS.cmake -DIOS_PLATFORM=OS -DENABLE_BUILD_IOS=1 -DCMAKE_BUILD_TYPE=Release -DCMAKE_OSX_ARCHITECTURES=armv7;armv7s;arm64 -GXcode"
 fi
-- 
GitLab