From e035d269f0e171451a64b4ef3b3c05d73d1f4235 Mon Sep 17 00:00:00 2001
From: Maxime Graulich <maxime.graulich@gmail.com>
Date: Fri, 3 May 2013 13:46:35 +0000
Subject: [PATCH] Mobile port

---
 CMakeLists.txt         | 39 +++++++++++++++++++++++++++++++++++++++
 Common/GmshMessage.cpp |  6 +++++-
 Common/GmshMessage.h   |  1 +
 Common/OpenFile.cpp    |  2 +-
 4 files changed, 46 insertions(+), 2 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 943c6d373f..072b617f5d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -30,6 +30,8 @@ option(ENABLE_BLAS_LAPACK "Use BLAS and Lapack for linear algebra" ON)
 option(ENABLE_BLOSSOM "Enable Blossom algo (based on MATCH and concorde97)" ${DEFAULT})
 option(ENABLE_BUILD_LIB "Build static Gmsh library" OFF)
 option(ENABLE_BUILD_SHARED "Build shared Gmsh library" OFF)
+option(ENABLE_BUILD_ANDROID "Build Gmsh library for Android NDK" OFF)
+option(ENABLE_BUILD_IOS "Build Gmsh library for iOS" OFF)
 option(ENABLE_CGNS "Enable CGNS mesh export" OFF)
 option(ENABLE_CHACO "Enable Chaco mesh partitioner" ${DEFAULT})
 option(ENABLE_DINTEGRATION "Enable discrete integration and levelsets" ${DEFAULT})
@@ -285,6 +287,10 @@ if(ENABLE_BLAS_LAPACK)
     set_config_option(HAVE_BLAS "Blas(VecLib)")
     set_config_option(HAVE_LAPACK "Lapack(VecLib)")
   endif(MSVC)
+  if(BUILD_ANDROID)
+    set_config_option(HAVE_BLAS "Blas")
+    set_config_option(HAVE_LAPACK "Lapack")
+  endif(BUILD_ANDROID)
   if(NOT HAVE_BLAS OR NOT HAVE_LAPACK)
     # if we haven't found blas and lapack without using the standard
     # cmake tests, do it (this requires a working Fortran compiler)
@@ -427,6 +433,35 @@ if(ENABLE_ONELAB)
   endif(ENABLE_ONELAB_METAMODEL)
 endif(ENABLE_ONELAB)
 
+if(ENABLE_BUILD_IOS)
+ #TODO
+endif(ENABLE_BUILD_IOS)
+
+if(ENABLE_BUILD_ANDROID)
+  # we need getdp lib
+  #find_library(GETDP_LIB Gmsh PATH_SUFFIXES lib)
+  #find_path(GETDP_INC "GetDP.h" PATH_SUFFIXES include getdp include/getdp)
+  #if(GETDP_LIB AND GETDP_INC)
+  #  list(APPEND EXTERNAL_LIBRARIES ${GETDP_LIB})
+  #  list(APPEND EXTERNAL_INCLUDES ${GETDP_INC})
+  #  set_config_option(HAVE_GETDP "GetDP")
+  #else(GETDP_LIB AND GETDP_INC)
+  #  message(SEND_ERROR "Cannot compile Gmsh for Android without GetDP")
+  #endif(GETDP_LIB AND GETDP_INC)
+  # then we can make gmsh lib
+  set(CMAKE_BUILD_TYPE Release)
+  add_definitions(-DBUILD_ANDROID)
+  set(LIBRARY_OUTPUT_PATH_ROOT ${CMAKE_CURRENT_BINARY_DIR})
+  set(LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/libs/)
+  #add_subdirectory(Mobile/Android/)
+  #add_library(androidGmsh SHARED Mobile/Android/drawGModel.cpp Mobile/Android/androidGModel.cpp ${GMSH_SRC})
+  add_library(androidGmsh SHARED ${GMSH_SRC})
+  #set( LIBRARY_DEPS GLESv1_CM log)
+  set_target_properties(androidGmsh PROPERTIES OUTPUT_NAME Gmsh)
+  target_link_libraries(androidGmsh  ${LINK_LIBRARIES})
+endif(ENABLE_BUILD_ANDROID)
+
+
 if(HAVE_FLTK OR HAVE_QT OR ENABLE_GRAPHICS)
   if(NOT HAVE_MESH OR NOT HAVE_POST OR NOT HAVE_PLUGINS OR NOT HAVE_ONELAB)
     message(SEND_ERROR "Cannot compile GUI without Mesh, Post, Plugin or OneLab")
@@ -1205,6 +1240,10 @@ endif(ENABLE_BUILD_LIB)
 if(ENABLE_BUILD_SHARED)
   install(TARGETS shared DESTINATION lib OPTIONAL)
 endif(ENABLE_BUILD_SHARED)
+if(ENABLE_BUILD_ANDROID)
+  install(TARGETS androidGmsh DESTINATION lib OPTIONAL)
+endif(ENABLE_BUILD_ANDROID)
+
 install(FILES ${GMSH_API} DESTINATION include/gmsh)
 install(FILES ${WELCOME_FILE} DESTINATION ${GMSH_DOC} RENAME README.txt)
 install(FILES ${LICENSE_FILE} DESTINATION ${GMSH_DOC})
diff --git a/Common/GmshMessage.cpp b/Common/GmshMessage.cpp
index 7e4e02e05b..7628c9cbd0 100644
--- a/Common/GmshMessage.cpp
+++ b/Common/GmshMessage.cpp
@@ -352,6 +352,10 @@ void Msg::Info(const char *fmt, ...)
     fflush(stdout);
   }
 }
+void Msg::RequestRender()
+{
+  if(_callback) (*_callback)("RequestRender", "");
+}
 
 void Msg::Direct(const char *fmt, ...)
 {
@@ -487,7 +491,7 @@ void Msg::ProgressMeter(int n, int N, bool log, const char *fmt, ...)
       FlGui::instance()->setProgress(str, (n > N - 1) ? 0 : n, 0, N);
     }
 #endif
-
+    if(_callback) (*_callback)("Progress", str);
     if(!streamIsFile(stdout) && log && CTX::instance()->terminal){
       fprintf(stdout, "%s                                          \r",
               (n > N - 1) ? "" : str2);
diff --git a/Common/GmshMessage.h b/Common/GmshMessage.h
index e5a3e676cc..e44f310175 100644
--- a/Common/GmshMessage.h
+++ b/Common/GmshMessage.h
@@ -68,6 +68,7 @@ class Msg {
   static void Error(const char *fmt, ...);
   static void Warning(const char *fmt, ...);
   static void Info(const char *fmt, ...);
+  static void RequestRender();
   static void Direct(const char *fmt, ...);
   static void StatusBar(bool log, const char *fmt, ...);
   static void StatusGl(const char *fmt, ...);
diff --git a/Common/OpenFile.cpp b/Common/OpenFile.cpp
index 049a075b33..2bf8f9844e 100644
--- a/Common/OpenFile.cpp
+++ b/Common/OpenFile.cpp
@@ -402,7 +402,7 @@ int MergeFile(const std::string &fileName, bool warnIfMissing)
     status = readFile3M(fileName);
   }
 #endif
-#if defined(HAVE_ONELAB) && defined(HAVE_FLTK)
+#if defined(HAVE_ONELAB)
   else if(ext == ".pro" && opt_solver_name(0, GMSH_GET, "") == "GetDP"){
     std::vector<std::string> split = SplitFileName(fileName);
     GModel::current()->setName(split[1] + ".geo");
-- 
GitLab