Browse Source

Physx5 updatePhysX Split support for PhysX5 (#241)

Updates to the PhysX 3rd Party script to support the https://github.com/o3de/sig-simulation/issues/85.

* Support to rename FindPhysX.cmake -> FindPhysX5.cmake
* Update the FindPhysX5.cmake to only use static libraries instead of the shared equivalent. This is necessary to prevent collision of the same shared libraries from both versions that have the same name. This will also reduce the 3rd Party package size.
* Fix a macos specific compiile error when using the current macos sdk
* Update the PhysX5 3P package to rev4

---------

Signed-off-by: Steve Pham <[email protected]>
Steve Pham 1 year ago
parent
commit
dd4f27a2b0

+ 0 - 126
package-system/PhysX5/FindPhysX.cmake

@@ -1,126 +0,0 @@
-#
-# Copyright (c) Contributors to the Open 3D Engine Project.
-# For complete copyright and license terms please see the LICENSE at the root of this distribution.
-# 
-# SPDX-License-Identifier: Apache-2.0 OR MIT
-#
-#
-
-set(MY_NAME "PhysX")
-set(TARGET_WITH_NAMESPACE "3rdParty::${MY_NAME}")
-if (TARGET ${TARGET_WITH_NAMESPACE})
-    return()
-endif()
-
-set(_PACKAGE_DIR ${CMAKE_CURRENT_LIST_DIR}/PhysX/physx)
-
-set(${MY_NAME}_INCLUDE_DIR
-    ${_PACKAGE_DIR}/include
-    ${_PACKAGE_DIR}/include/foundation
-    ${_PACKAGE_DIR}/include/geometry
-)
-
-set(${MY_NAME}_COMPILE_DEFINITIONS $<$<BOOL:${LY_MONOLITHIC_GAME}>:PX_PHYSX_STATIC_LIB>)
-
-# LY_PHYSX_PROFILE_USE_CHECKED_LIBS allows to override what PhysX configuration to use on O3DE profile.
-set(LY_PHYSX_PROFILE_USE_CHECKED_LIBS OFF CACHE BOOL "When ON it uses PhysX SDK checked libraries on O3DE profile configuration")
-if(LY_PHYSX_PROFILE_USE_CHECKED_LIBS)
-    set(PHYSX_PROFILE_CONFIG "checked")
-else()
-    set(PHYSX_PROFILE_CONFIG "profile")
-endif()
-
-set(PATH_TO_LIBS ${_PACKAGE_DIR}/bin/$<IF:$<BOOL:${LY_MONOLITHIC_GAME}>,static,shared>/$<IF:$<CONFIG:profile>,${PHYSX_PROFILE_CONFIG},$<CONFIG>>)
-set(PATH_TO_SHARED_LIBS ${_PACKAGE_DIR}/bin/shared/$<IF:$<CONFIG:profile>,${PHYSX_PROFILE_CONFIG},$<CONFIG>>)
-
-if(DEFINED CMAKE_IMPORT_LIBRARY_SUFFIX)
-    set(import_lib_prefix ${CMAKE_IMPORT_LIBRARY_PREFIX})
-    set(import_lib_suffix ${CMAKE_IMPORT_LIBRARY_SUFFIX})
-else()
-    set(import_lib_prefix ${CMAKE_SHARED_LIBRARY_PREFIX})
-    set(import_lib_suffix ${CMAKE_SHARED_LIBRARY_SUFFIX})
-endif()
-
-set(${MY_NAME}_LIBRARIES
-    ${PATH_TO_LIBS}/${CMAKE_STATIC_LIBRARY_PREFIX}PhysXCharacterKinematic_static_64${CMAKE_STATIC_LIBRARY_SUFFIX}
-    ${PATH_TO_LIBS}/${CMAKE_STATIC_LIBRARY_PREFIX}PhysXVehicle_static_64${CMAKE_STATIC_LIBRARY_SUFFIX}
-    ${PATH_TO_LIBS}/${CMAKE_STATIC_LIBRARY_PREFIX}PhysXExtensions_static_64${CMAKE_STATIC_LIBRARY_SUFFIX}
-    ${PATH_TO_LIBS}/${CMAKE_STATIC_LIBRARY_PREFIX}PhysXPvdSDK_static_64${CMAKE_STATIC_LIBRARY_SUFFIX}
-)
-
-set(extra_static_libs ${EXTRA_STATIC_LIBS_NON_MONOLITHIC})
-set(extra_shared_libs ${EXTRA_SHARED_LIBS})
-
-if(LY_MONOLITHIC_GAME)
-    if(LY_PHYSX_PROFILE_USE_CHECKED_LIBS)
-        set(MONO_PATH_TO_STATIC_LIBS ${CMAKE_CURRENT_LIST_DIR}/PhysX/physx/bin/static/checked)
-    else()
-        set(MONO_PATH_TO_STATIC_LIBS ${CMAKE_CURRENT_LIST_DIR}/PhysX/physx/bin/static/profile)
-    endif()
-    # The order of PhysX 5.x static libraries is important for monolithic targets.
-    set(IMPORTED_PHYSICS_LIBS
-        PhysX_static_64
-        PhysXPvdSDK_static_64
-        PhysXVehicle_static_64
-        PhysXCharacterKinematic_static_64
-        PhysXExtensions_static_64
-        PhysXCooking_static_64
-        PhysXCommon_static_64
-        PhysXFoundation_static_64
-    )
-    foreach(PHYSICS_LIB ${IMPORTED_PHYSICS_LIBS})
-        add_library(${PHYSICS_LIB}::imported STATIC IMPORTED GLOBAL)
-        set(${PHYSICS_LIB}_PATH ${MONO_PATH_TO_STATIC_LIBS}/${CMAKE_STATIC_LIBRARY_PREFIX}${PHYSICS_LIB}${CMAKE_STATIC_LIBRARY_SUFFIX})
-        set_target_properties(${PHYSICS_LIB}::imported
-            PROPERTIES
-                IMPORTED_LOCATION_DEBUG   ${${PHYSICS_LIB}_PATH}
-                IMPORTED_LOCATION_PROFILE ${${PHYSICS_LIB}_PATH}
-                IMPORTED_LOCATION_RELEASE ${${PHYSICS_LIB}_PATH}
-        )
-        target_link_libraries(${PHYSICS_LIB}::imported INTERFACE 
-            ${PREVIOUS_PHYSICS_LIB}
-            ${MONO_PATH_TO_STATIC_LIBS}/${CMAKE_STATIC_LIBRARY_PREFIX}${PHYSICS_LIB}${CMAKE_STATIC_LIBRARY_SUFFIX}
-        )
-        set (PREVIOUS_PHYSICS_LIB ${PHYSICS_LIB}::imported)
-    endforeach()
-
-    add_library(Physx5_STATIC_LIBS_FOR_MONOLITHIC::imported INTERFACE IMPORTED GLOBAL)
-        target_link_libraries(Physx5_STATIC_LIBS_FOR_MONOLITHIC::imported INTERFACE
-        PhysXFoundation_static_64::imported
-    )
-
-    if(extra_shared_libs)
-        set(${MY_NAME}_RUNTIME_DEPENDENCIES
-            ${extra_shared_libs}
-        )
-    endif()
-else()
-    list(APPEND ${MY_NAME}_LIBRARIES
-        ${PATH_TO_LIBS}/${import_lib_prefix}PhysX_64${import_lib_suffix}
-        ${PATH_TO_LIBS}/${import_lib_prefix}PhysXCooking_64${import_lib_suffix}
-        ${PATH_TO_LIBS}/${import_lib_prefix}PhysXFoundation_64${import_lib_suffix}
-        ${PATH_TO_LIBS}/${import_lib_prefix}PhysXCommon_64${import_lib_suffix}
-        ${extra_static_libs}
-    )
-    set(${MY_NAME}_RUNTIME_DEPENDENCIES
-        ${PATH_TO_LIBS}/${CMAKE_SHARED_LIBRARY_PREFIX}PhysX_64${CMAKE_SHARED_LIBRARY_SUFFIX}
-        ${PATH_TO_LIBS}/${CMAKE_SHARED_LIBRARY_PREFIX}PhysXCooking_64${CMAKE_SHARED_LIBRARY_SUFFIX}
-        ${PATH_TO_LIBS}/${CMAKE_SHARED_LIBRARY_PREFIX}PhysXFoundation_64${CMAKE_SHARED_LIBRARY_SUFFIX}
-        ${PATH_TO_LIBS}/${CMAKE_SHARED_LIBRARY_PREFIX}PhysXCommon_64${CMAKE_SHARED_LIBRARY_SUFFIX}
-        ${extra_shared_libs}
-    )
-endif()
-
-add_library(${TARGET_WITH_NAMESPACE} INTERFACE IMPORTED GLOBAL)
-ly_target_include_system_directories(TARGET ${TARGET_WITH_NAMESPACE} INTERFACE ${${MY_NAME}_INCLUDE_DIR})
-if(LY_MONOLITHIC_GAME)
-    target_link_libraries(${TARGET_WITH_NAMESPACE} INTERFACE Physx5_STATIC_LIBS_FOR_MONOLITHIC::imported)
-else()
-    target_link_libraries(${TARGET_WITH_NAMESPACE} INTERFACE ${${MY_NAME}_LIBRARIES})
-endif()
-target_compile_definitions(${TARGET_WITH_NAMESPACE} INTERFACE ${${MY_NAME}_COMPILE_DEFINITIONS})
-if(DEFINED ${MY_NAME}_RUNTIME_DEPENDENCIES)
-    ly_add_target_files(TARGETS ${TARGET_WITH_NAMESPACE} FILES ${${MY_NAME}_RUNTIME_DEPENDENCIES})
-endif()
-
-set(${MY_NAME}_FOUND True)

+ 116 - 0
package-system/PhysX5/FindPhysX5.cmake

@@ -0,0 +1,116 @@
+#
+# Copyright (c) Contributors to the Open 3D Engine Project.
+# For complete copyright and license terms please see the LICENSE at the root of this distribution.
+# 
+# SPDX-License-Identifier: Apache-2.0 OR MIT
+#
+#
+
+set(MY_NAME "PhysX5")
+set(TARGET_WITH_NAMESPACE "3rdParty::${MY_NAME}")
+if (TARGET ${TARGET_WITH_NAMESPACE})
+    return()
+endif()
+
+set(_PACKAGE_DIR ${CMAKE_CURRENT_LIST_DIR}/PhysX/physx)
+
+set(${MY_NAME}_INCLUDE_DIR
+    ${_PACKAGE_DIR}/include
+    ${_PACKAGE_DIR}/include/foundation
+    ${_PACKAGE_DIR}/include/geometry
+)
+
+# We will only use the static libs for linking
+set(${MY_NAME}_COMPILE_DEFINITIONS PX_PHYSX_STATIC_LIB)
+
+# LY_PHYSX_PROFILE_USE_CHECKED_LIBS allows to override what PhysX configuration to use on O3DE profile.
+set(LY_PHYSX_PROFILE_USE_CHECKED_LIBS OFF CACHE BOOL "When ON it uses PhysX SDK checked libraries on O3DE profile configuration")
+if(LY_PHYSX_PROFILE_USE_CHECKED_LIBS)
+    set(PHYSX_PROFILE_CONFIG "checked")
+else()
+    set(PHYSX_PROFILE_CONFIG "profile")
+endif()
+
+# Set the generator-expression path to the static libs
+set(PATH_TO_LIBS ${_PACKAGE_DIR}/bin/static/$<IF:$<CONFIG:profile>,${PHYSX_PROFILE_CONFIG},$<CONFIG>>)
+
+if(DEFINED CMAKE_IMPORT_LIBRARY_SUFFIX)
+    set(import_lib_prefix ${CMAKE_IMPORT_LIBRARY_PREFIX})
+    set(import_lib_suffix ${CMAKE_IMPORT_LIBRARY_SUFFIX})
+else()
+    set(import_lib_prefix ${CMAKE_SHARED_LIBRARY_PREFIX})
+    set(import_lib_suffix ${CMAKE_SHARED_LIBRARY_SUFFIX})
+endif()
+
+set(extra_static_libs ${EXTRA_STATIC_LIBS})
+set(extra_shared_libs ${EXTRA_SHARED_LIBS})
+
+# The order of PhysX 5.x static libraries is important for static targets. We will loop through in order and define
+# each static library explicitly, while setting their dependency as a chain to ensure the order is preserved
+
+set(IMPORTED_PHYSICS_LIBS_SUFFIX
+    PhysX_static_64
+    PhysXPvdSDK_static_64
+    PhysXVehicle_static_64
+    PhysXCharacterKinematic_static_64
+    PhysXExtensions_static_64
+    PhysXCooking_static_64
+    PhysXCommon_static_64
+    PhysXFoundation_static_64
+)
+
+foreach(PHYSICS_LIB ${IMPORTED_PHYSICS_LIBS_SUFFIX})
+
+    # Set the individual target names to include a ${MY_NAME} prefix in order to prevent collisions
+    # with other 3rd party PhysX Packages of different versions while retaining the same actual
+    # filename
+
+    set(PHYSICS_LIB_NAME ${MY_NAME}${PHYSICS_LIB})
+
+    add_library(${PHYSICS_LIB_NAME}::imported STATIC IMPORTED GLOBAL)
+
+    # Set the import location (note: generator expressions are not supported as properties here, so each config needs to be explicit for its location)
+    set_target_properties(${PHYSICS_LIB_NAME}::imported
+        PROPERTIES
+            IMPORTED_LOCATION_DEBUG   ${CMAKE_CURRENT_LIST_DIR}/PhysX/physx/bin/static/debug/${CMAKE_STATIC_LIBRARY_PREFIX}${PHYSICS_LIB}${CMAKE_STATIC_LIBRARY_SUFFIX}
+            IMPORTED_LOCATION_PROFILE ${CMAKE_CURRENT_LIST_DIR}/PhysX/physx/bin/static/${PHYSX_PROFILE_CONFIG}/${CMAKE_STATIC_LIBRARY_PREFIX}${PHYSICS_LIB}${CMAKE_STATIC_LIBRARY_SUFFIX}
+            IMPORTED_LOCATION_RELEASE ${CMAKE_CURRENT_LIST_DIR}/PhysX/physx/bin/static/release/${CMAKE_STATIC_LIBRARY_PREFIX}${PHYSICS_LIB}${CMAKE_STATIC_LIBRARY_SUFFIX}
+    )
+
+    # Set the target libraries dependency on any previous lib to build the order chain
+    target_link_libraries(${PHYSICS_LIB_NAME}::imported INTERFACE
+        ${PREVIOUS_PHYSICS_LIB}
+        ${PATH_TO_LIBS}/${CMAKE_STATIC_LIBRARY_PREFIX}${PHYSICS_LIB}${CMAKE_STATIC_LIBRARY_SUFFIX}
+    )
+    set (PREVIOUS_PHYSICS_LIB ${PHYSICS_LIB_NAME}::imported)
+
+endforeach()
+
+add_library(${MY_NAME}_STATIC_LIBS::imported INTERFACE IMPORTED GLOBAL)
+
+# Set the final ${MY_NAME}_STATIC_LIBS to the last static target defined to complete the chain
+target_link_libraries(${MY_NAME}_STATIC_LIBS::imported INTERFACE
+    ${PREVIOUS_PHYSICS_LIB}
+    ${extra_static_libs}
+)
+
+# Add any optional shared library dependency as a runtime dependency
+if(extra_shared_libs)
+    set(${MY_NAME}_RUNTIME_DEPENDENCIES
+        ${extra_shared_libs}
+    )
+endif()
+
+add_library(${TARGET_WITH_NAMESPACE} INTERFACE IMPORTED GLOBAL)
+
+ly_target_include_system_directories(TARGET ${TARGET_WITH_NAMESPACE} INTERFACE ${${MY_NAME}_INCLUDE_DIR})
+
+target_link_libraries(${TARGET_WITH_NAMESPACE} INTERFACE ${MY_NAME}_STATIC_LIBS::imported)
+
+target_compile_definitions(${TARGET_WITH_NAMESPACE} INTERFACE ${${MY_NAME}_COMPILE_DEFINITIONS})
+
+if(DEFINED ${MY_NAME}_RUNTIME_DEPENDENCIES)
+    ly_add_target_files(TARGETS ${TARGET_WITH_NAMESPACE} FILES ${${MY_NAME}_RUNTIME_DEPENDENCIES})
+endif()
+
+set(${MY_NAME}_FOUND True)

+ 10 - 29
package-system/PhysX5/FindPhysX_ios.cmake → package-system/PhysX5/FindPhysX5_ios.cmake

@@ -6,7 +6,7 @@
 #
 #
 
-set(MY_NAME "PhysX")
+set(MY_NAME "PhysX5")
 set(TARGET_WITH_NAMESPACE "3rdParty::${MY_NAME}")
 if (TARGET ${TARGET_WITH_NAMESPACE})
     return()
@@ -20,7 +20,7 @@ set(${MY_NAME}_INCLUDE_DIR
     ${_PACKAGE_DIR}/include/geometry
 )
 
-set(${MY_NAME}_COMPILE_DEFINITIONS $<$<BOOL:${LY_MONOLITHIC_GAME}>:PX_PHYSX_STATIC_LIB>)
+set(${MY_NAME}_COMPILE_DEFINITIONS PX_PHYSX_STATIC_LIB)
 
 # LY_PHYSX_PROFILE_USE_CHECKED_LIBS allows to override what PhysX configuration to use on O3DE profile.
 set(LY_PHYSX_PROFILE_USE_CHECKED_LIBS OFF CACHE BOOL "When ON it uses PhysX SDK checked libraries on O3DE profile configuration")
@@ -30,44 +30,25 @@ else()
     set(PHYSX_PROFILE_CONFIG "profile")
 endif()
 
-if(LY_MONOLITHIC_GAME)
-    set(PATH_TO_LIBS ${_PACKAGE_DIR}/bin/static/$<IF:$<CONFIG:profile>,${PHYSX_PROFILE_CONFIG},$<CONFIG>>)
-else()
-    # iOS uses Frameworks for non-monolithic builds.
-    # Frameworks are added and managed by XCode during the build process.
-    # At the moment $<CONFIG> does not get replaced for "debug", "profile" or
-    # "release" for frameworks when added to XCode, so it's not able to find
-    # the frameworks since their path is wrong. To workaround this, for now it
-    # will only use the profile configuration since non-monolithic is not used
-    # when shipping.
-    set(PATH_TO_LIBS ${_PACKAGE_DIR}/bin/shared/${PHYSX_PROFILE_CONFIG})
-endif()
+set(PATH_TO_LIBS ${_PACKAGE_DIR}/bin/static/$<IF:$<CONFIG:profile>,${PHYSX_PROFILE_CONFIG},$<CONFIG>>)
 
 set(${MY_NAME}_LIBRARIES
     ${PATH_TO_LIBS}/libPhysXCharacterKinematic_static_64.a
     ${PATH_TO_LIBS}/libPhysXVehicle_static_64.a
     ${PATH_TO_LIBS}/libPhysXExtensions_static_64.a
     ${PATH_TO_LIBS}/libPhysXPvdSDK_static_64.a
+    ${PATH_TO_LIBS}/libPhysX_static_64.a
+    ${PATH_TO_LIBS}/libPhysXCooking_static_64.a
+    ${PATH_TO_LIBS}/libPhysXFoundation_static_64.a
+    ${PATH_TO_LIBS}/libPhysXCommon_static_64.a
 )
-if(LY_MONOLITHIC_GAME)
-    list(APPEND ${MY_NAME}_LIBRARIES
-        ${PATH_TO_LIBS}/libPhysX_static_64.a
-        ${PATH_TO_LIBS}/libPhysXCooking_static_64.a
-        ${PATH_TO_LIBS}/libPhysXFoundation_static_64.a
-        ${PATH_TO_LIBS}/libPhysXCommon_static_64.a
-    )
-else()
-    list(APPEND ${MY_NAME}_LIBRARIES
-        ${PATH_TO_LIBS}/PhysX.framework
-        ${PATH_TO_LIBS}/PhysXCooking.framework
-        ${PATH_TO_LIBS}/PhysXFoundation.framework
-        ${PATH_TO_LIBS}/PhysXCommon.framework
-    )
-endif()
 
 add_library(${TARGET_WITH_NAMESPACE} INTERFACE IMPORTED GLOBAL)
+
 ly_target_include_system_directories(TARGET ${TARGET_WITH_NAMESPACE} INTERFACE ${${MY_NAME}_INCLUDE_DIR})
+
 target_link_libraries(${TARGET_WITH_NAMESPACE} INTERFACE ${${MY_NAME}_LIBRARIES})
+
 target_compile_definitions(${TARGET_WITH_NAMESPACE} INTERFACE ${${MY_NAME}_COMPILE_DEFINITIONS})
 
 # Frameworks do not need to get added as runtime dependencies

+ 53 - 0
package-system/PhysX5/build_fix.patch

@@ -0,0 +1,53 @@
+diff --git a/physx/include/foundation/PxVecQuat.h b/physx/include/foundation/PxVecQuat.h
+index 0822c17..c24ae5f 100644
+--- a/physx/include/foundation/PxVecQuat.h
++++ b/physx/include/foundation/PxVecQuat.h
+@@ -308,7 +308,7 @@ PX_FORCE_INLINE bool isValidQuatV(const QuatV q)
+ 	const FloatV unitTolerance = FLoad(1e-4f);
+ 	const FloatV tmp = FAbs(FSub(QuatLength(q), FOne()));
+ 	const BoolV con = FIsGrtr(unitTolerance, tmp);
+-	return isFiniteVec4V(q) & (BAllEqTTTT(con) == 1);
++	return isFiniteVec4V(q) && (BAllEqTTTT(con) == 1);
+ }
+ 
+ PX_FORCE_INLINE bool isSaneQuatV(const QuatV q)
+@@ -316,7 +316,7 @@ PX_FORCE_INLINE bool isSaneQuatV(const QuatV q)
+ 	const FloatV unitTolerance = FLoad(1e-2f);
+ 	const FloatV tmp = FAbs(FSub(QuatLength(q), FOne()));
+ 	const BoolV con = FIsGrtr(unitTolerance, tmp);
+-	return isFiniteVec4V(q) & (BAllEqTTTT(con) == 1);
++	return isFiniteVec4V(q) && (BAllEqTTTT(con) == 1);
+ }
+ 
+ #if PX_LINUX && PX_CLANG
+diff --git a/physx/include/foundation/PxVecTransform.h b/physx/include/foundation/PxVecTransform.h
+index bd29307..d00a4e0 100644
+--- a/physx/include/foundation/PxVecTransform.h
++++ b/physx/include/foundation/PxVecTransform.h
+@@ -133,7 +133,7 @@ class PxTransformV
+ 	PX_FORCE_INLINE bool isValid() const
+ 	{
+ 		// return p.isFinite() && q.isFinite() && q.isValid();
+-		return isFiniteVec3V(p) & isFiniteQuatV(q) & isValidQuatV(q);
++		return isFiniteVec3V(p) && isFiniteQuatV(q) && isValidQuatV(q);
+ 	}
+ 
+ 	/**
+@@ -144,7 +144,7 @@ class PxTransformV
+ 	PX_FORCE_INLINE bool isSane() const
+ 	{
+ 		// return isFinite() && q.isSane();
+-		return isFinite() & isSaneQuatV(q);
++		return isFinite() && isSaneQuatV(q);
+ 	}
+ 
+ 	/**
+@@ -153,7 +153,7 @@ class PxTransformV
+ 	PX_FORCE_INLINE bool isFinite() const
+ 	{
+ 		// return p.isFinite() && q.isFinite();
+-		return isFiniteVec3V(p) & isFiniteQuatV(q);
++		return isFiniteVec3V(p) && isFiniteQuatV(q);
+ 	}
+ 
+ #if PX_LINUX && PX_CLANG

+ 84 - 47
package-system/PhysX5/build_package_image.py

@@ -13,6 +13,7 @@ import os
 import re
 import pathlib
 from pathlib import Path
+import platform
 import shutil
 import subprocess
 from tempfile import TemporaryDirectory
@@ -26,6 +27,7 @@ class PhysXBuilder(object):
         self._workingDir = workingDir
         self._packageSystemDir = basePackageSystemDir
         self._platform = targetPlatform
+        self._hostPlatformLower = platform.system().lower()
         self._env = dict(os.environ)
         self._env.update(
             GW_DEPS_ROOT=str(workingDir),
@@ -90,6 +92,11 @@ class PhysXBuilder(object):
         self.check_call(
             ['git', 'checkout', lockToCommit,],
         )
+        if self.platform in ['ios', 'mac']:
+            self.check_call(
+                ['git', 'apply', '--whitespace=fix', (pathlib.Path(__file__).parent / 'build_fix.patch').absolute()]
+            )
+
             
     def preparePreset(self, buildAsStaticLibs, config):
         preset_index = 0
@@ -109,7 +116,7 @@ class PhysXBuilder(object):
         elif self.platform == 'linux' or self.platform == 'linux-aarch64':
             content = re.sub('name="PX_BUILDSNIPPETS" value="(True|False)"', f'name="PX_BUILDSNIPPETS" value="False"', content, flags = re.M)
             content = re.sub('name="PX_BUILDPVDRUNTIME" value="(True|False)"', f'name="PX_BUILDPVDRUNTIME" value="False"', content, flags = re.M)
-            
+    
         self.writeFile(preset_file, content)
 
         # Ignore poison-system-directories warning when building mac/ios caused 
@@ -124,35 +131,55 @@ class PhysXBuilder(object):
         static_bin_dir = self.workingDir / 'physx' / 'bin' / 'static'
         shared_bin_dir = self.workingDir / 'physx' / 'bin' / 'shared'
     
-        # Remove dynamic libraries repeated in static folders to save space.
-        # Also freeglut is not necessary for PhysX.
+        # Remove dynamic libraries, but copy some missing static libs from
+        # the shared builds into the static lib folder. Also freeglut is not
+        # necessary for PhysX.
         if self.platform == 'windows':
-            if buildAsStaticLibs:
+            if not buildAsStaticLibs:
+
+                for extra_static_lib_filename in ['LowLevel_static_64',
+                                                  'LowLevelAABB_static_64',
+                                                  'LowLevelDynamics_static_64',
+                                                  'PhysXTask_static_64',
+                                                  'SceneQuery_static_64',
+                                                  'SimulationController_static_64']:
+
+                    for extra_static_lib_ext in ['.lib', '.pdb']:
+
+                        for config in ('release', 'profile', 'checked', 'debug'):
+
+                            src_extra_static_lib = shared_bin_dir / config / f'{extra_static_lib_filename}{extra_static_lib_ext}'
+                            dst_extra_static_lib = static_bin_dir / config / f'{extra_static_lib_filename}{extra_static_lib_ext}'
+                            print(f"Copying {src_extra_static_lib} -> {dst_extra_static_lib}")
+                            shutil.copy2(src=src_extra_static_lib, dst=dst_extra_static_lib)
+
                 for config in ('release', 'profile', 'checked', 'debug'):
-                    os.remove(static_bin_dir / config / 'PhysXDevice64.dll')
-                    os.remove(static_bin_dir / config / 'PhysXGpu_64.dll')
                     if config == 'debug':
                         os.remove(static_bin_dir / config / 'freeglutd.dll')
                     else:
                         os.remove(static_bin_dir / config / 'freeglut.dll')
-            else:
-                for config in ('release', 'profile', 'checked', 'debug'):
-                    if config == 'debug':
-                        os.remove(shared_bin_dir / config / 'freeglutd.dll')
-                    else:
-                        os.remove(shared_bin_dir / config / 'freeglut.dll')
-            
-        elif self.platform == 'linux' or self.platform == 'linux-aarch64':
-            if buildAsStaticLibs:
-                for config in ('release', 'profile', 'checked', 'debug'):
-                    os.remove(static_bin_dir / config / 'libPhysXGpu_64.so')
+
+                shutil.rmtree(shared_bin_dir)
             
     def build(self, buildAsStaticLibs):
         physx_dir = self.workingDir / 'physx'
-        
+
+        # Update the packman URLs
+        packman_dir = physx_dir / 'buildtools' / 'packman'
+        check_call_packman_update = functools.partial(subprocess.check_call,
+            cwd=packman_dir, # generate_projects script will fail if not called from physx directory
+            env=self.env
+        )
+
+        if self._hostPlatformLower == 'windows':
+            update_pacman_call = [ str(packman_dir / 'packman.cmd'), 'update', '-y']
+        else:
+            update_pacman_call = [ str(packman_dir / 'packman'), 'update', '-y']
+
+        check_call_packman_update(update_pacman_call)        
         preset, bin_folder, install_folder, is_multiconfig = self.platform_params[self.platform]
         
-        if self.platform == 'windows' or self.platform == 'android':
+        if self._hostPlatformLower == 'windows':
             generate_projects_cmd =  str(physx_dir / 'generate_projects.bat')
         else:
             generate_projects_cmd = str(physx_dir / 'generate_projects.sh')
@@ -203,20 +230,23 @@ class PhysXBuilder(object):
              
         self.cleanUpLibs(buildAsStaticLibs)
 
+    def build_all(self):
+
+        self.build(buildAsStaticLibs=True)
+
+        if self.platform == 'windows':
+            self.build(buildAsStaticLibs=False)
+
     def copyBuildOutputTo(self, packageDir: pathlib.Path):
         if packageDir.exists():
             shutil.rmtree(packageDir)
             
+
         shutil.copytree(
-            src=self.workingDir / 'physx' / 'install' / 'shared' / 'PhysX',
+            src=self.workingDir / 'physx' / 'install' / 'static' / 'PhysX',
             dst=packageDir / 'physx',
             symlinks=True,
         )
-        shutil.copytree(
-            src=self.workingDir / 'physx' / 'bin' / 'shared',
-            dst=packageDir / 'physx' / 'bin' / 'shared',
-            symlinks=True,
-        )
         shutil.copytree(
             src=self.workingDir / 'physx' / 'bin' / 'static',
             dst=packageDir / 'physx' / 'bin' / 'static',
@@ -244,7 +274,7 @@ class PhysXBuilder(object):
             json.dump(settings, fh, indent=4)
 
     def writeCMakeFindFile(self, packageDir: pathlib.Path, cmakeFindFile):
-        dst = packageDir / 'FindPhysX.cmake'
+        dst = packageDir / 'FindPhysX5.cmake'
         shutil.copy2(
             src=cmakeFindFile,
             dst=dst
@@ -252,12 +282,12 @@ class PhysXBuilder(object):
         
         extraLibsPerPlatform = {
             'windows': [
-                ['\${EXTRA_SHARED_LIBS}',
+                ['\\${EXTRA_SHARED_LIBS}',
                  ''.join(('\n',
-                    '\t${PATH_TO_SHARED_LIBS}/PhysXDevice64.dll\n',
-                    '\t${PATH_TO_SHARED_LIBS}/PhysXGpu_64.dll\n'
+                    '\t${PATH_TO_LIBS}/PhysXDevice64.dll\n',
+                    '\t${PATH_TO_LIBS}/PhysXGpu_64.dll\n'
                 ))],
-                ['\${EXTRA_STATIC_LIBS_NON_MONOLITHIC}',
+                ['\\${EXTRA_STATIC_LIBS}',
                  ''.join(('\n',
                     '\t${PATH_TO_LIBS}/LowLevel_static_64.lib\n',
                     '\t${PATH_TO_LIBS}/LowLevelAABB_static_64.lib\n',
@@ -268,23 +298,23 @@ class PhysXBuilder(object):
                 ))],
             ],
             'linux': [
-                ['\${EXTRA_SHARED_LIBS}', '${PATH_TO_SHARED_LIBS}/libPhysXGpu_64.so'],
-                ['\${EXTRA_STATIC_LIBS_NON_MONOLITHIC}', ''],
+                ['\\${EXTRA_SHARED_LIBS}', '${PATH_TO_LIBS}/libPhysXGpu_64.so'],
+                ['\\${EXTRA_STATIC_LIBS}', ''],
             ],
             'linux-aarch64': [
-                ['\${EXTRA_SHARED_LIBS}', '${PATH_TO_SHARED_LIBS}/libPhysXGpu_64.so'],
-                ['\${EXTRA_STATIC_LIBS_NON_MONOLITHIC}', ''],
+                ['\\${EXTRA_SHARED_LIBS}', '${PATH_TO_LIBS}/libPhysXGpu_64.so'],
+                ['\\${EXTRA_STATIC_LIBS}', ''],
             ],
             'mac': [
-                ['\${EXTRA_SHARED_LIBS}', ''],
-                ['\${EXTRA_STATIC_LIBS_NON_MONOLITHIC}', ''],
+                ['\\${EXTRA_SHARED_LIBS}', ''],
+                ['\\${EXTRA_STATIC_LIBS}', ''],
             ],
             # iOS has its own FindPhysX file where it doesn't need to do any adjustments.
             'ios': [
             ],
             'android': [
-                ['\${EXTRA_SHARED_LIBS}', ''],
-                ['\${EXTRA_STATIC_LIBS_NON_MONOLITHIC}', ''],
+                ['\\${EXTRA_SHARED_LIBS}', ''],
+                ['\\${EXTRA_STATIC_LIBS}', ''],
             ],
         }
         
@@ -295,6 +325,14 @@ class PhysXBuilder(object):
 
 def main():
     parser = argparse.ArgumentParser()
+    parser.add_argument(
+        '--package-name',
+        required=True
+    )
+    parser.add_argument(
+        '--package-rev',
+        required=True
+    )
     parser.add_argument(
         '--platform-name',
         dest='platformName',
@@ -314,16 +352,13 @@ def main():
     packageSourceDir = packageSystemDir / 'PhysX5'
     packageRoot = packageSourceDir / 'temp' / f'PhysX5-{args.platformName}'
 
-    cmakeFindFile = packageSourceDir / f'FindPhysX_{args.platformName}.cmake'
+    cmakeFindFile = packageSourceDir / f'FindPhysX5_{args.platformName}.cmake'
     if not cmakeFindFile.exists():
-        cmakeFindFile = packageSourceDir / 'FindPhysX.cmake'
+        cmakeFindFile = packageSourceDir / 'FindPhysX5.cmake'
 
     with TemporaryDirectory() as tempdir:
         # Package Name
-        revision = 'rev1'
-        if args.platformName == 'windows':
-            revision = 'rev2'
-        packageName = f'PhysX-5.1.1-{revision}-{args.platformName}'
+        packageName = f'{args.package_name}-{args.package_rev}-{args.platformName}'
         
         # Version 5.1.1 commits
         if args.platformName == 'mac':
@@ -336,11 +371,13 @@ def main():
             commit = '0bbcff3d0c541325f4d14c36ee18f24e22e35e6e' # Commit for 5.1.1 version
             
         tempdir = Path(tempdir)
-        builder = PhysXBuilder(workingDir=tempdir, basePackageSystemDir=packageSystemDir, targetPlatform=args.platformName)
+        builder = PhysXBuilder(workingDir=tempdir,
+                               basePackageSystemDir=packageSystemDir,
+                               targetPlatform=args.platformName)
         builder.clone(lockToCommit=commit)
         
-        builder.build(buildAsStaticLibs=False)
-        builder.build(buildAsStaticLibs=True)
+        builder.build_all()
+
         builder.copyBuildOutputTo(packageRoot/'PhysX')
         
         builder.writePackageInfoFile(

+ 4 - 4
package_build_list_host_darwin.json

@@ -28,8 +28,8 @@
         "openimageio-opencolorio-2.3.17-rev3-mac": "package-system/openimageio-opencolorio/build_openimageio.py --package-name=openimageio-opencolorio-2.3.17-rev3-mac --clean",
         "PhysX-4.1.2.29882248-rev8-mac": "package-system/PhysX/build_package_image.py --package-name PhysX-4.1.2.29882248 --package-rev rev8 --platform mac",
         "PhysX-4.1.2.29882248-rev8-ios": "package-system/PhysX/build_package_image.py --package-name PhysX-4.1.2.29882248 --package-rev rev8 --platform ios",
-        "PhysX-5.1.1-rev1-mac": "package-system/PhysX5/build_package_image.py --platform mac",
-        "PhysX-5.1.1-rev1-ios": "package-system/PhysX5/build_package_image.py --platform ios",
+        "PhysX-5.1.1-rev4-mac": "package-system/PhysX5/build_package_image.py --package-name PhysX-5.1.1 --package-rev rev4 --platform mac",
+        "PhysX-5.1.1-rev4-ios": "package-system/PhysX5/build_package_image.py --package-name PhysX-5.1.1 --package-rev rev4 --platform ios",
         "NvCloth-v1.1.6-4-gd243404-pr58-rev1-mac": "package-system/NvCloth/build_package_image.py --platform-name mac",
         "NvCloth-v1.1.6-4-gd243404-pr58-rev1-ios": "package-system/NvCloth/build_package_image.py --platform-name ios",
         "poly2tri-7f0487a-rev1-mac": "package-system/poly2tri/build_package_image.py --platform-name mac",
@@ -83,8 +83,8 @@
         "asn1-0.9.27-rev2-ios": "package-system/asn1-ios",
         "PhysX-4.1.2.29882248-rev8-mac": "package-system/PhysX-mac",
         "PhysX-4.1.2.29882248-rev8-ios": "package-system/PhysX-ios",
-        "PhysX-5.1.1-rev1-mac": "package-system/PhysX5/temp/PhysX5-mac",
-        "PhysX-5.1.1-rev1-ios": "package-system/PhysX5/temp/PhysX5-ios",
+        "PhysX-5.1.1-rev4-mac": "package-system/PhysX5/temp/PhysX5-mac",
+        "PhysX-5.1.1-rev4-ios": "package-system/PhysX5/temp/PhysX5-ios",
         "NvCloth-v1.1.6-4-gd243404-pr58-rev1-mac": "package-system/NvCloth-mac",
         "NvCloth-v1.1.6-4-gd243404-pr58-rev1-ios": "package-system/NvCloth-ios",
         "mikkelsen-1.0.0.4-mac": "package-system/mikkelsen-mac",

+ 2 - 2
package_build_list_host_linux-aarch64.json

@@ -29,7 +29,7 @@
         "OpenSSL-1.1.1t-rev1-linux-aarch64": "Scripts/extras/pull_and_build_from_git.py ../../package-system/OpenSSL --platform-name Linux-aarch64 --clean",
         "OpenXR-1.0.22-rev2-linux-aarch64": "Scripts/extras/pull_and_build_from_git.py ../../package-system/OpenXR --platform-name Linux-aarch64 --clean",
         "PhysX-4.1.2.29882248-rev8-linux-aarch64": "package-system/PhysX/build_package_image.py --package-name PhysX-4.1.2.29882248 --package-rev rev8 --platform-name linux-aarch64",
-        "PhysX-5.1.1-rev1-linux-aarch64": "package-system/PhysX5/build_package_image.py --platform-name linux-aarch64",
+        "PhysX-5.1.1-rev4-linux-aarch64": "package-system/PhysX5/build_package_image.py --package-name PhysX-5.1.1 --package-rev rev4 --platform-name linux-aarch64",
         "png-1.6.37-rev2-linux-aarch64": "Scripts/extras/pull_and_build_from_git.py ../../package-system/libpng --platform-name Linux-aarch64 --clean",
         "poly2tri-7f0487a-rev1-linux-aarch64": "package-system/poly2tri/build_package_image.py --platform-name linux-aarch64",
         "pyside2-5.15.2.1-py3.10-rev4-linux-aarch64": "Scripts/extras/pull_and_build_from_git.py ../../package-system/pyside2 --platform-name Linux-aarch64 --clean",
@@ -70,7 +70,7 @@
         "OpenSSL-1.1.1t-rev1-linux-aarch64": "package-system/OpenSSL/temp/OpenSSL-linux-aarch64",
         "OpenXR-1.0.22-rev2-linux-aarch64": "package-system/OpenXR/temp/OpenXR-linux-aarch64",
         "PhysX-4.1.2.29882248-rev8-linux-aarch64": "package-system/PhysX-linux-aarch64",
-        "PhysX-5.1.1-rev1-linux-aarch64": "package-system/PhysX5/temp/PhysX5-linux-aarch64",
+        "PhysX-5.1.1-rev4-linux-aarch64": "package-system/PhysX5/temp/PhysX5-linux-aarch64",
         "png-1.6.37-rev2-linux-aarch64":  "package-system/libpng/temp/png-linux-aarch64",
         "poly2tri-7f0487a-rev1-linux-aarch64": "package-system/poly2tri-linux-aarch64",
         "pyside2-5.15.2.1-py3.10-rev4-linux-aarch64": "package-system/pyside2/temp/pyside2-linux-aarch64",

+ 2 - 2
package_build_list_host_linux.json

@@ -27,7 +27,7 @@
         "OpenSSL-1.1.1t-rev1-linux": "Scripts/extras/pull_and_build_from_git.py ../../package-system/OpenSSL --platform-name Linux --clean",
         "OpenSSL-1.1.1t-rev1-linux-aarch64": "Scripts/extras/pull_and_build_from_git.py ../../package-system/OpenSSL --platform-name Linux-aarch64 --clean",
         "PhysX-4.1.2.29882248-rev8-linux": "package-system/PhysX/build_package_image.py --package-name PhysX-4.1.2.29882248 --package-rev rev8 --platform-name linux",
-        "PhysX-5.1.1-rev1-linux": "package-system/PhysX5/build_package_image.py --platform-name linux",
+        "PhysX-5.1.1-rev4-linux": "package-system/PhysX5/build_package_image.py --package-name PhysX-5.1.1 --package-rev rev4 --platform-name linux",
         "NvCloth-v1.1.6-4-gd243404-pr58-rev1-linux": "package-system/NvCloth/build_package_image.py --platform-name linux",
         "poly2tri-7f0487a-rev1-linux": "package-system/poly2tri/build_package_image.py --platform-name linux",
         "v-hacd-2.3-1a49edf-rev1-linux": "package-system/v-hacd/build_package_image.py --platform-name linux",
@@ -85,7 +85,7 @@
         "python-3.10.5-rev4-linux": "package-system/python/temp/python-linux",
         "python-3.10.5-rev4-linux-aarch64": "package-system/python/temp/python-linux-aarch64",
         "PhysX-4.1.2.29882248-rev8-linux": "package-system/PhysX-linux",
-        "PhysX-5.1.1-rev1-linux": "package-system/PhysX5/temp/PhysX5-linux",
+        "PhysX-5.1.1-rev4-linux": "package-system/PhysX5/temp/PhysX5-linux",
         "NvCloth-v1.1.6-4-gd243404-pr58-rev1-linux": "package-system/NvCloth-linux",
         "mikkelsen-1.0.0.4-linux": "package-system/mikkelsen-linux",
         "poly2tri-7f0487a-rev1-linux": "package-system/poly2tri-linux",

+ 4 - 4
package_build_list_host_windows.json

@@ -43,8 +43,8 @@
         "OpenXR-1.0.22-rev1-windows": "Scripts/extras/pull_and_build_from_git.py ../../package-system/OpenXR --platform-name Windows --package-root ../../package-system --clean",
         "PhysX-4.1.2.29882248-rev8-android": "package-system/PhysX/build_package_image.py --package-name PhysX-4.1.2.29882248 --package-rev rev8 --platform android",
         "PhysX-4.1.2.29882248-rev8-windows": "package-system/PhysX/build_package_image.py --package-name PhysX-4.1.2.29882248 --package-rev rev8 --platform windows",
-        "PhysX-5.1.1-rev1-android": "package-system/PhysX5/build_package_image.py --platform android",
-        "PhysX-5.1.1-rev2-windows": "package-system/PhysX5/build_package_image.py --platform windows",
+        "PhysX-5.1.1-rev4-android": "package-system/PhysX5/build_package_image.py --package-name PhysX-5.1.1 --package-rev rev4 --platform android",
+        "PhysX-5.1.1-rev4-windows": "package-system/PhysX5/build_package_image.py --package-name PhysX-5.1.1 --package-rev rev4 --platform windows",
         "png-1.6.37-rev2-android": "Scripts/extras/pull_and_build_from_git.py ../../package-system/libpng --platform-name Android --package-root ../../package-system/libpng/temp --clean",
         "png-1.6.37-rev2-windows": "Scripts/extras/pull_and_build_from_git.py ../../package-system/libpng --platform-name Windows --package-root ../../package-system/libpng/temp --clean",
         "poly2tri-7f0487a-rev1-windows": "package-system/poly2tri/build_package_image.py --platform-name windows",
@@ -112,8 +112,8 @@
     "OpenXR-1.0.22-rev1-windows": "package-system/OpenXR-windows",
     "PhysX-4.1.2.29882248-rev8-android": "package-system/PhysX-android",
     "PhysX-4.1.2.29882248-rev8-windows": "package-system/PhysX-windows",
-    "PhysX-5.1.1-rev1-android": "package-system/PhysX5/temp/PhysX5-android",
-    "PhysX-5.1.1-rev2-windows": "package-system/PhysX5/temp/PhysX5-windows",
+    "PhysX-5.1.1-rev4-android": "package-system/PhysX5/temp/PhysX5-android",
+    "PhysX-5.1.1-rev4-windows": "package-system/PhysX5/temp/PhysX5-windows",
     "png-1.6.37-rev2-android": "package-system/libpng/temp/png-android",
     "png-1.6.37-rev2-windows": "package-system/libpng/temp/png-windows",
     "poly2tri-7f0487a-rev1-windows": "package-system/poly2tri-windows",