Browse Source

CMake: Add variable for host bin directory

When crosscompiling, the executables created for the target cannot be used on the host. Add a HOST_BIN_DIR variable that can be pointed to a Panda3D bin/ directory that contains interrogate and pzip.
Donny Lawrence 6 years ago
parent
commit
d21895ae2e
3 changed files with 26 additions and 8 deletions
  1. 16 8
      cmake/macros/RunPzip.cmake
  2. 5 0
      dtool/Config.cmake
  3. 5 0
      dtool/src/interrogate/CMakeLists.txt

+ 16 - 8
cmake/macros/RunPzip.cmake

@@ -1,15 +1,23 @@
 function(run_pzip target_name source destination glob)
   if(NOT TARGET host_pzip)
-    # If pzip isn't built, we just copy instead.
-    file(COPY "${source}"
-      DESTINATION "${destination}"
-      FILES_MATCHING PATTERN "${glob}")
-
-    return()
+    if(CMAKE_CROSSCOMPILING AND NOT EXISTS "${HOST_BIN_DIR}/pzip")
+      # If pzip isn't built, we just copy instead.
+      file(COPY "${source}"
+        DESTINATION "${destination}"
+        FILES_MATCHING PATTERN "${glob}")
+
+      return()
+    endif()
   endif()
 
   file(GLOB_RECURSE files RELATIVE "${source}" "${source}/${glob}")
 
+  if(CMAKE_CROSSCOMPILING)
+    set(pzip_executable ${HOST_BIN_DIR}/pzip)
+  else()
+    set(pzip_executable host_pzip)
+  endif()
+
   set(dstfiles "")
   foreach(filename ${files})
     string(REGEX REPLACE "^/" "" filename "${filename}")
@@ -21,8 +29,8 @@ function(run_pzip target_name source destination glob)
 
     add_custom_command(OUTPUT "${destination}/${dstfile}"
       COMMAND ${CMAKE_COMMAND} -E make_directory "${dstdir}"
-      COMMAND host_pzip -c > "${destination}/${dstfile}" < "${source}/${filename}"
-      DEPENDS host_pzip
+      COMMAND ${pzip_executable} -c > "${destination}/${dstfile}" < "${source}/${filename}"
+      DEPENDS ${pzip_executable}
       COMMENT "")
 
   endforeach(filename)

+ 5 - 0
dtool/Config.cmake

@@ -47,6 +47,11 @@ else()
     Release RelWithDebInfo Debug MinSizeRel Distribution)
 endif()
 
+# If we're crosscompiling, give options to specify host interrogate and pzip.
+if(CMAKE_CROSSCOMPILING)
+  set(HOST_BIN_DIR "" CACHE STRING "The location of the native executables for the machine performing the cross-compile.")
+endif()
+
 # Provide convenient boolean expression based on build type
 if(CMAKE_BUILD_TYPE MATCHES "Debug")
   set(IS_DEBUG_BUILD True)

+ 5 - 0
dtool/src/interrogate/CMakeLists.txt

@@ -82,6 +82,11 @@ target_link_libraries(interrogate_module p3cppParser p3dtoolconfig p3pystub
 if(NOT CMAKE_CROSSCOMPILING)
   add_executable(host_interrogate ALIAS interrogate)
   add_executable(host_interrogate_module ALIAS interrogate_module)
+else()
+  add_executable(host_interrogate IMPORTED GLOBAL)
+  set_property(TARGET host_interrogate PROPERTY IMPORTED_LOCATION "${HOST_BIN_DIR}/interrogate")
+  add_executable(host_interrogate_module IMPORTED GLOBAL)
+  set_property(TARGET host_interrogate_module PROPERTY IMPORTED_LOCATION "${HOST_BIN_DIR}/interrogate_module")
 endif()
 
 if(WANT_INTERROGATE)