diff --git a/CMakeLists.txt b/CMakeLists.txt index d1c8594a46..d8f2aa77d0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,6 +54,7 @@ include(AddBisonTarget) # Defines add_bison_target function include(AddFlexTarget) # Defines add_flex_target function include(CompositeSources) # Defines composite_sources function include(Interrogate) # Defines target_interrogate AND add_python_module +include(RunPzip) # Defines run_pzip function # Add the include path for source and header files generated by CMake include_directories("${PROJECT_BINARY_DIR}/include") @@ -63,6 +64,7 @@ option(BUILD_DTOOL "Build the dtool source tree." ON) option(BUILD_PANDA "Build the panda source tree." ON) option(BUILD_DIRECT "Build the direct source tree." ON) option(BUILD_PANDATOOL "Build the pandatool source tree." ON) +option(BUILD_MODELS "Build/install the built-in models." ON) # Include Panda3D packages if(BUILD_DTOOL) @@ -81,6 +83,29 @@ if(BUILD_PANDATOOL) add_subdirectory(pandatool "${CMAKE_BINARY_DIR}/pandatool") endif() +if(BUILD_MODELS) + # We don't really "build" the models, just pzip them + file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/models/maps/" + DESTINATION "${PROJECT_BINARY_DIR}/models/maps" + ) + run_pzip(models + "${CMAKE_CURRENT_SOURCE_DIR}/models" + "${PROJECT_BINARY_DIR}/models" + *.egg + ) + file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/dmodels/src/" + DESTINATION "${PROJECT_BINARY_DIR}/models" + FILES_MATCHING PATTERN *.rgb PATTERN *.png PATTERN *.jpg PATTERN *.wav + ) + run_pzip(dmodels + "${CMAKE_CURRENT_SOURCE_DIR}/dmodels/src" + "${PROJECT_BINARY_DIR}/models" + *.egg + ) + install(DIRECTORY "${PROJECT_BINARY_DIR}/models" + DESTINATION share/panda3d) +endif() + # This bit is to generate the 'pandac' compatibility shim. It's deprecated now, # but in older versions of Panda3D, one would use # from pandac.PandaModules import * diff --git a/cmake/macros/RunPzip.cmake b/cmake/macros/RunPzip.cmake new file mode 100644 index 0000000000..ef428b92d6 --- /dev/null +++ b/cmake/macros/RunPzip.cmake @@ -0,0 +1,23 @@ +function(run_pzip target_name source destination glob) + file(GLOB_RECURSE files RELATIVE "${source}" "${source}/${glob}") + + set(dstfiles "") + foreach(srcfile ${files}) + file(RELATIVE_PATH srcfile_rel "${destination}" "${source}/${srcfile}") + file(RELATIVE_PATH dstfile_rel "${destination}" "${destination}/${srcfile}.pz") + + list(APPEND dstfiles "${dstfile_rel}") + add_custom_command(OUTPUT "${dstfile_rel}" + COMMAND pzip -c > "${dstfile_rel}" < "${srcfile_rel}" + WORKING_DIRECTORY "${destination}" + DEPENDS pzip + COMMENT "") + + get_filename_component(dstdir "${destination}/${dstfile_rel}" DIRECTORY) + file(MAKE_DIRECTORY "${dstdir}") + endforeach(srcfile) + + add_custom_target(${target_name} ALL + DEPENDS ${dstfiles} + WORKING_DIRECTORY "${destination}") +endfunction(run_pzip)