Browse Source

CMake: Generate panda.prc with the correct model-path

This also generates a second prc for installation purposes,
which has the correct paths once installed
Sam Edwards 6 years ago
parent
commit
4a307f9cdf
2 changed files with 33 additions and 7 deletions
  1. 29 5
      panda/src/configfiles/CMakeLists.txt
  2. 4 2
      panda/src/configfiles/panda.prc.in

+ 29 - 5
panda/src/configfiles/CMakeLists.txt

@@ -32,19 +32,43 @@ else()
     "$XDG_CACHE_HOME/panda3d")
 endif()
 
-configure_file(panda.prc.in "${CMAKE_BINARY_DIR}/etc/20_panda.prc")
 if(IS_MULTICONFIG)
-  file(GENERATE OUTPUT "${PROJECT_BINARY_DIR}/$<CONFIG>/etc/20_panda.prc"
-                INPUT "${PROJECT_BINARY_DIR}/etc/20_panda.prc")
+  set(_out_path "${PROJECT_BINARY_DIR}/$<CONFIG>/etc")
+else()
+  set(_out_path "${PROJECT_BINARY_DIR}/etc")
 endif()
 
 if(WIN32)
   set(_confdir "etc")
-
 else()
   # On Unices, ask the GNUInstallDirs module where /etc is
   set(_confdir "${CMAKE_INSTALL_FULL_SYSCONFDIR}")
+endif()
+
+# Path from the directory containing *.prc to the *parent of* models/
+# In the build tree, reckoning this is pretty easy
+set(MODELS_PARENT_PATH "..")
+configure_file(panda.prc.in "${CMAKE_CURRENT_BINARY_DIR}/20_panda.prc")
 
+# For the install tree, we need to introspect our paths
+if(_confdir MATCHES "^/")
+  set(_abs_confdir "${_confdir}")
+else()
+  set(_abs_confdir "${CMAKE_INSTALL_PREFIX}/${_confdir}")
+endif()
+if(CMAKE_INSTALL_DATADIR MATCHES "^/")
+  set(_abs_datadir "${CMAKE_INSTALL_DATADIR}")
+else()
+  set(_abs_datadir "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}")
 endif()
+file(RELATIVE_PATH MODELS_PARENT_PATH
+  "${_abs_confdir}" "${_abs_datadir}/panda3d")
+configure_file(panda.prc.in "${CMAKE_CURRENT_BINARY_DIR}/20_panda.prc.install")
+
+file(GENERATE OUTPUT "${_out_path}/20_panda.prc"
+              INPUT "${CMAKE_CURRENT_BINARY_DIR}/20_panda.prc")
+file(GENERATE OUTPUT "${_out_path}/20_panda.prc.install"
+              INPUT "${CMAKE_CURRENT_BINARY_DIR}/20_panda.prc.install")
 
-install(FILES "${CMAKE_BINARY_DIR}/etc/20_panda.prc" COMPONENT Core DESTINATION ${_confdir})
+install(FILES "${_out_path}/20_panda.prc.install" RENAME "20_panda.prc"
+  COMPONENT Core DESTINATION ${_confdir})

+ 4 - 2
panda/src/configfiles/panda.prc.in

@@ -3,10 +3,12 @@
 
 # Some paths first...
 plugin-path $THIS_PRC_DIR/../lib
-model-path $THIS_PRC_DIR/../share/panda3d/models
+model-path $MAIN_DIR
+model-path $THIS_PRC_DIR/${MODELS_PARENT_PATH}
+model-path $THIS_PRC_DIR/${MODELS_PARENT_PATH}/models
 
 # Let's set up a default window size of 800x600.  The user can
-# override this in his or her personal prc file.
+# override this in a separate, personal prc file.
 win-origin -2 -2
 win-size 800 600