From f377bdfb29ca490a6be3eb2923579098f362facb Mon Sep 17 00:00:00 2001 From: Sam Edwards Date: Wed, 13 Nov 2019 00:29:00 -0700 Subject: [PATCH] CMake: Copy thirdparty/**/*.dll to bin/ directory --- dtool/Package.cmake | 37 +++++++++++++++++++++++++++++ dtool/metalibs/dtool/CMakeLists.txt | 3 +++ 2 files changed, 40 insertions(+) diff --git a/dtool/Package.cmake b/dtool/Package.cmake index 6de060f922..4677f62cf6 100644 --- a/dtool/Package.cmake +++ b/dtool/Package.cmake @@ -3,6 +3,8 @@ set(THIRDPARTY_DIRECTORY "" CACHE PATH located here will be prioritized over system libraries. Useful for cross-compiling.") +set(THIRDPARTY_DLLS) + if(THIRDPARTY_DIRECTORY) # This policy is necessary for PackageName_ROOT variables to be respected if(POLICY CMP0074) @@ -78,6 +80,7 @@ if(THIRDPARTY_DIRECTORY) ) string(TOLOWER "${_Package}" _package) + string(TOUPPER "${_Package}" _PACKAGE) # Some packages in the thirdparty dir have different subdirectory names from # the name of the CMake package @@ -100,10 +103,44 @@ if(THIRDPARTY_DIRECTORY) # Set search path set(${_Package}_ROOT "${_package_dir}/${_package}") + # Set up copying DLLs, if necessary + file(GLOB _dlls "${${_Package}_ROOT}/bin/*.dll") + if(_dlls) + set(_havevar "HAVE_${_PACKAGE}") + set(THIRDPARTY_DLLS_${_havevar} "${_dlls}") + list(APPEND THIRDPARTY_DLLS "${_havevar}") + + endif() + endforeach(_Package) endif() +# This is used to copy the DLLs alongside the output of `package` +function(thirdparty_copy_alongside package) + set(_dlls) + + foreach(_havevar ${THIRDPARTY_DLLS}) + if(${_havevar}) + list(APPEND _dlls ${THIRDPARTY_DLLS_${_havevar}}) + endif() + endforeach(_havevar) + + if(NOT _dlls) + # Don't try to copy/install nothingness + return() + endif() + + add_custom_command(TARGET ${package} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + ${_dlls} $ + ) + + # Also install the DLLs + install(FILES ${_dlls} DESTINATION ${CMAKE_INSTALL_BINDIR}) + +endfunction(thirdparty_copy_alongside) + # # ------------ Python ------------ # diff --git a/dtool/metalibs/dtool/CMakeLists.txt b/dtool/metalibs/dtool/CMakeLists.txt index fc5eb3c722..812c457b72 100644 --- a/dtool/metalibs/dtool/CMakeLists.txt +++ b/dtool/metalibs/dtool/CMakeLists.txt @@ -8,3 +8,6 @@ install(TARGETS p3dtool RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/panda3d ARCHIVE COMPONENT CoreDevel) + +# Also handle thirdparty DLLs +thirdparty_copy_alongside(p3dtool)