Browse Source

cmake: Fix iOS build on merged CMake branch.

Donny Lawrence 5 years ago
parent
commit
711af76ff8

+ 14 - 0
CMakeLists.txt

@@ -95,6 +95,20 @@ include(dtool/PandaVersion.cmake)
 include(dtool/Package.cmake)
 include(dtool/Package.cmake)
 include(dtool/Config.cmake)
 include(dtool/Config.cmake)
 
 
+# If cross compiling, find the host's Panda3D, if needed.
+if(CMAKE_CROSSCOMPILING)
+  if(INTERROGATE_PYTHON_INTERFACE)
+    find_package(Panda3D REQUIRED COMPONENTS Core OPTIONAL_COMPONENTS Tools CONFIG)
+    set_target_properties(Panda3D::Core::interrogate Panda3D::Core::interrogate_module PROPERTIES IMPORTED_GLOBAL TRUE)
+  else()
+    find_package(Panda3D COMPONENTS Tools CONFIG)
+  endif()
+
+  if(TARGET Panda3D::Tools::pzip)
+    set_target_properties(Panda3D::Tools::pzip PROPERTIES IMPORTED_GLOBAL TRUE)
+  endif()
+endif()
+
 # Include global modules
 # Include global modules
 include(AddBisonTarget)     # Defines add_bison_target function
 include(AddBisonTarget)     # Defines add_bison_target function
 include(AddFlexTarget)      # Defines add_flex_target function
 include(AddFlexTarget)      # Defines add_flex_target function

+ 7 - 0
cmake/macros/PackageConfig.cmake

@@ -310,6 +310,13 @@ endfunction()
 function(export_packages filename)
 function(export_packages filename)
   set(exports "# Exports for Panda3D PKG:: packages\n")
   set(exports "# Exports for Panda3D PKG:: packages\n")
 
 
+  if(IS_OSX)
+    set(exports "${exports}set(_panda_archs ${CMAKE_OSX_ARCHITECTURES})\n")
+    set(exports "${exports}if(NOT _panda_archs STREQUAL \$\{CMAKE_OSX_ARCHITECTURES\})\n")
+    set(exports "${exports}  return()\n")
+    set(exports "${exports}endif()\n")
+  endif()
+
   foreach(pkg ${_ALL_PACKAGE_OPTIONS})
   foreach(pkg ${_ALL_PACKAGE_OPTIONS})
     set(exports "${exports}\n# Create imported target PKG::${pkg}\n")
     set(exports "${exports}\n# Create imported target PKG::${pkg}\n")
     set(exports "${exports}add_library(PKG::${pkg} INTERFACE IMPORTED)\n\n")
     set(exports "${exports}add_library(PKG::${pkg} INTERFACE IMPORTED)\n\n")

+ 2 - 2
cmake/macros/RunPzip.cmake

@@ -2,9 +2,9 @@ function(run_pzip target_name source destination glob)
   file(GLOB_RECURSE files RELATIVE "${source}" "${source}/${glob}")
   file(GLOB_RECURSE files RELATIVE "${source}" "${source}/${glob}")
 
 
   if(CMAKE_CROSSCOMPILING)
   if(CMAKE_CROSSCOMPILING)
-    set(pzip_executable ${HOST_BIN_DIR}/pzip)
+    add_executable(host_pzip ALIAS Panda3D::Tools::pzip)
   else()
   else()
-    set(pzip_executable host_pzip)
+    add_executable(host_pzip ALIAS pzip)
   endif()
   endif()
 
 
   set(dstfiles "")
   set(dstfiles "")

+ 3 - 1
dtool/Config.cmake

@@ -335,7 +335,9 @@ mark_as_advanced(USE_MEMORY_DLMALLOC USE_MEMORY_PTMALLOC2
 #
 #
 
 
 # iOS support
 # iOS support
-if(CMAKE_SYSTEM_NAME STREQUAL "iOS")
+if(IS_IOS)
+
+  set(CMAKE_MACOSX_BUNDLE OFF)
 
 
   # A bug in CMake (https://gitlab.kitware.com/cmake/cmake/issues/19375) causes
   # A bug in CMake (https://gitlab.kitware.com/cmake/cmake/issues/19375) causes
   # MACOSX_RPATH to not be respected on iOS.
   # MACOSX_RPATH to not be respected on iOS.

+ 20 - 25
dtool/Package.cmake

@@ -20,14 +20,23 @@ if(THIRDPARTY_DIRECTORY)
     message(FATAL_ERROR
     message(FATAL_ERROR
       "Your version of CMake is too old; please upgrade or unset THIRDPARTY_DIRECTORY to continue.")
       "Your version of CMake is too old; please upgrade or unset THIRDPARTY_DIRECTORY to continue.")
   endif()
   endif()
-
   # Dig up the actual "libs" directory
   # Dig up the actual "libs" directory
-  if(APPLE)
+  if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
     set(_package_dir "${THIRDPARTY_DIRECTORY}/darwin-libs-a")
     set(_package_dir "${THIRDPARTY_DIRECTORY}/darwin-libs-a")
 
 
     # Make sure thirdparty has the first shot, not system frameworks
     # Make sure thirdparty has the first shot, not system frameworks
     set(CMAKE_FIND_FRAMEWORK LAST)
     set(CMAKE_FIND_FRAMEWORK LAST)
+  elseif(CMAKE_SYSTEM_NAME MATCHES "iOS")
+    set(_package_dir "${THIRDPARTY_DIRECTORY}/ios-libs-arm64")
+    file(GLOB _python_dirs "${THIRDPARTY_DIRECTORY}/ios-python*-arm64")
+
+    # Make sure thirdparty has the first shot, not system frameworks
+    set(CMAKE_FIND_FRAMEWORK LAST)
 
 
+    list(REVERSE _python_dirs) # Descending order of version
+    if(NOT DEFINED Python_ROOT)
+      set(Python_ROOT "${_python_dirs}")
+    endif()
   elseif(WIN32)
   elseif(WIN32)
     if(CMAKE_SIZEOF_VOID_P EQUAL 8)
     if(CMAKE_SIZEOF_VOID_P EQUAL 8)
       set(_package_dir "${THIRDPARTY_DIRECTORY}/win-libs-vc14-x64")
       set(_package_dir "${THIRDPARTY_DIRECTORY}/win-libs-vc14-x64")
@@ -153,28 +162,7 @@ endfunction(thirdparty_copy_alongside)
 # ------------ Python ------------
 # ------------ Python ------------
 #
 #
 
 
-set(THIRDPARTY_DIRECTORY "" CACHE PATH
-  "Optional location of a makepanda-style thirdparty directory. All libraries
-   located here will be prioritized over system libraries. Useful for
-   cross-compiling.")
-# Makes CMake look for modules here first.
-if(THIRDPARTY_DIRECTORY)
-  set(CMAKE_FIND_ROOT_PATH ${CMAKE_FIND_ROOT_PATH} "${THIRDPARTY_DIRECTORY}")
-  set(OpenSSL_ROOT "${THIRDPARTY_DIRECTORY}/openssl")
-  set(JPEG_ROOT "${THIRDPARTY_DIRECTORY}/jpeg")
-  set(PNG_ROOT "${THIRDPARTY_DIRECTORY}/png")
-  set(TIFF_ROOT "${THIRDPARTY_DIRECTORY}/tiff")
-  set(LibSquish_ROOT "${THIRDPARTY_DIRECTORY}/squish")
-  set(FFMPEG_ROOT "${THIRDPARTY_DIRECTORY}/ffmpeg")
-  set(SWScale_ROOT "${THIRDPARTY_DIRECTORY}/ffmpeg")
-  set(SWResample_ROOT "${THIRDPARTY_DIRECTORY}/ffmpeg")
-  set(ODE_ROOT "${THIRDPARTY_DIRECTORY}/ode")
-  set(HarfBuzz_ROOT "${THIRDPARTY_DIRECTORY}/harfbuzz")
-  set(OpusFile_ROOT "${THIRDPARTY_DIRECTORY}/opus")
-  set(VorbisFile_ROOT "${THIRDPARTY_DIRECTORY}/vorbis")
-  set(ARToolKit_ROOT "${THIRDPARTY_DIRECTORY}/artoolkit")
-  set(Bullet_ROOT "${THIRDPARTY_DIRECTORY}/bullet")
-endif()
+list(APPEND CMAKE_FIND_ROOT_PATH "${_package_dir}" "${_python_dirs}")
 
 
 set(WANT_PYTHON_VERSION ""
 set(WANT_PYTHON_VERSION ""
   CACHE STRING "Which Python version to seek out for building Panda3D against.")
   CACHE STRING "Which Python version to seek out for building Panda3D against.")
@@ -205,7 +193,14 @@ if(WANT_PYTHON_VERSION)
 endif()
 endif()
 
 
 get_directory_property(_old_cache_vars CACHE_VARIABLES)
 get_directory_property(_old_cache_vars CACHE_VARIABLES)
-find_package(Python ${WANT_PYTHON_VERSION} QUIET COMPONENTS Interpreter Development)
+
+if(CMAKE_SYSTEM_NAME MATCHES "iOS")
+  set(Python_LIBRARY ${Python_ROOT}/Python.framework/libPython.a)
+  set(Python_INCLUDE_DIR ${Python_ROOT}/Python.framework/Headers)
+  find_package(Python ${WANT_PYTHON_VERSION} QUIET COMPONENTS Development)
+else()
+  find_package(Python ${WANT_PYTHON_VERSION} QUIET COMPONENTS Interpreter Development)
+endif()
 
 
 if(Python_FOUND)
 if(Python_FOUND)
   set(PYTHON_FOUND ON)
   set(PYTHON_FOUND ON)

+ 2 - 17
dtool/src/interrogate/CMakeLists.txt

@@ -96,23 +96,8 @@ if(NOT CMAKE_CROSSCOMPILING)
   add_executable(host_interrogate ALIAS interrogate)
   add_executable(host_interrogate ALIAS interrogate)
   add_executable(host_interrogate_module ALIAS interrogate_module)
   add_executable(host_interrogate_module ALIAS interrogate_module)
 else()
 else()
-  # When cross-compiling, we must find the host Interrogate.
-  # TODO: We should also try to find_package(Panda3D ...) before falling back
-  # to searching manually.
-  find_program(HOST_PATH_INTERROGATE interrogate)
-  find_program(HOST_PATH_INTERROGATE_MODULE interrogate_module)
-
-  add_executable(host_interrogate IMPORTED GLOBAL)
-  if(HOST_PATH_INTERROGATE)
-    set_target_properties(host_interrogate PROPERTIES
-      IMPORTED_LOCATION "${HOST_PATH_INTERROGATE}")
-  endif()
-
-  add_executable(host_interrogate_module IMPORTED GLOBAL)
-  if(HOST_PATH_INTERROGATE_MODULE)
-    set_target_properties(host_interrogate_module PROPERTIES
-      IMPORTED_LOCATION "${HOST_PATH_INTERROGATE_MODULE}")
-  endif()
+  add_executable(host_interrogate ALIAS Panda3D::Core::interrogate)
+  add_executable(host_interrogate_module ALIAS Panda3D::Core::interrogate_module)
 endif()
 endif()
 
 
 if(WANT_INTERROGATE)
 if(WANT_INTERROGATE)

+ 0 - 13
panda/src/downloadertools/CMakeLists.txt

@@ -20,19 +20,6 @@ if(HAVE_ZLIB)
   add_executable(pzip pzip.cxx)
   add_executable(pzip pzip.cxx)
   target_link_libraries(pzip panda)
   target_link_libraries(pzip panda)
 
 
-  if(NOT CMAKE_CROSSCOMPILING)
-    add_executable(host_pzip ALIAS pzip)
-  else()
-    find_program(HOST_PATH_PZIP pzip)
-
-    add_executable(host_pzip IMPORTED GLOBAL)
-    if(HOST_PATH_PZIP)
-      set_target_properties(host_pzip PROPERTIES
-        IMPORTED_LOCATION "${HOST_PATH_PZIP}")
-    endif()
-
-  endif()
-
   add_executable(punzip punzip.cxx)
   add_executable(punzip punzip.cxx)
   target_link_libraries(punzip panda)
   target_link_libraries(punzip panda)
 
 

+ 2 - 2
panda/src/eagldisplay/eaglGraphicsBuffer.h

@@ -17,14 +17,14 @@
 #include "pandabase.h"
 #include "pandabase.h"
 #include "gles2gsg.h"
 #include "gles2gsg.h"
 
 
-
+#import <QuartzCore/CAEAGLLayer.h>
 
 
 /**
 /**
  * This is a light wrapper around GLGraphicsBuffer (ie. FBOs) to interface
  * This is a light wrapper around GLGraphicsBuffer (ie. FBOs) to interface
  * with Cocoa contexts, so that it can be used without a host window.
  * with Cocoa contexts, so that it can be used without a host window.
  */
  */
 class EAGLGraphicsBuffer : public GLES2GraphicsBuffer {
 class EAGLGraphicsBuffer : public GLES2GraphicsBuffer {
-friend EAGLGraphicsWindow;
+friend class EAGLGraphicsWindow;
 
 
 public:
 public:
   EAGLGraphicsBuffer(GraphicsEngine *engine, GraphicsPipe *pipe,
   EAGLGraphicsBuffer(GraphicsEngine *engine, GraphicsPipe *pipe,

+ 1 - 0
panda/src/eagldisplay/eaglGraphicsStateGuardian.h

@@ -20,6 +20,7 @@
 
 
 
 
 #import <OpenGLES/EAGL.h>
 #import <OpenGLES/EAGL.h>
+#import <QuartzCore/CAEAGLLayer.h>
 
 
 /**
 /**
  * A variation of GLES2GraphicsStateGuardian to support Apple's EGL
  * A variation of GLES2GraphicsStateGuardian to support Apple's EGL

+ 2 - 0
panda/src/eagldisplay/eaglGraphicsWindow.mm

@@ -17,6 +17,8 @@
 
 
 #include "eaglGraphicsStateGuardian.h"
 #include "eaglGraphicsStateGuardian.h"
 #include "mouseButton.h"
 #include "mouseButton.h"
+
+#include "config_eagldisplay.h"
 // #import "iOSNSNotificationHandler.h"
 // #import "iOSNSNotificationHandler.h"
 
 
 TypeHandle EAGLGraphicsWindow::_type_handle;
 TypeHandle EAGLGraphicsWindow::_type_handle;