Forráskód Böngészése

PhysX 5.1.1 build scripts (#165)

Added build script for PhysX 5 that can generate the following packages:
- PhysX-5.1.1-rev1-windows
- PhysX-5.1.1-rev1-linux
- PhysX-5.1.1-rev1-linux-aarch64
- PhysX-5.1.1-rev1-mac
- PhysX-5.1.1-rev1-ios
- PhysX-5.1.1-rev1-android

Signed-off-by: moraaar <[email protected]>
moraaar 2 éve
szülő
commit
4e533cad0c

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

@@ -0,0 +1,91 @@
+#
+# 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)
+    list(APPEND ${MY_NAME}_LIBRARIES
+        ${PATH_TO_LIBS}/${CMAKE_STATIC_LIBRARY_PREFIX}PhysX_static_64${CMAKE_STATIC_LIBRARY_SUFFIX}
+        ${PATH_TO_LIBS}/${CMAKE_STATIC_LIBRARY_PREFIX}PhysXCooking_static_64${CMAKE_STATIC_LIBRARY_SUFFIX}
+        ${PATH_TO_LIBS}/${CMAKE_STATIC_LIBRARY_PREFIX}PhysXFoundation_static_64${CMAKE_STATIC_LIBRARY_SUFFIX}
+        ${PATH_TO_LIBS}/${CMAKE_STATIC_LIBRARY_PREFIX}PhysXCommon_static_64${CMAKE_STATIC_LIBRARY_SUFFIX}
+    )
+    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})
+target_link_libraries(${TARGET_WITH_NAMESPACE} INTERFACE ${${MY_NAME}_LIBRARIES})
+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)

+ 77 - 0
package-system/PhysX5/FindPhysX_ios.cmake

@@ -0,0 +1,77 @@
+#
+# 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()
+
+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(${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
+)
+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
+# since they are handled by XCode directly. Frameworks will
+# be copied into the app when constructed by XCode.
+
+set(${MY_NAME}_FOUND True)

+ 366 - 0
package-system/PhysX5/build_package_image.py

@@ -0,0 +1,366 @@
+#!/usr/bin/env python3
+#
+# 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
+#
+#
+
+import argparse
+import functools
+import json
+import os
+import re
+import pathlib
+from pathlib import Path
+import shutil
+import subprocess
+from tempfile import TemporaryDirectory
+
+import sys
+sys.path.append(str(Path(__file__).parent.parent.parent / 'Scripts'))
+import builders.monkeypatch_tempdir_cleanup
+
+class PhysXBuilder(object):
+    def __init__(self, workingDir: pathlib.Path, basePackageSystemDir: pathlib.Path, targetPlatform: str):
+        self._workingDir = workingDir
+        self._packageSystemDir = basePackageSystemDir
+        self._platform = targetPlatform
+        self._env = dict(os.environ)
+        self._env.update(
+            GW_DEPS_ROOT=str(workingDir),
+        )
+
+        self.check_call = functools.partial(subprocess.check_call,
+            cwd=self.workingDir,
+            env=self.env
+        )
+        
+        # nVidia CMakeModules (downloaded while building PhysX) do not cover ios or android
+        # bin folder names yet, so they appear as UNKNOWN.
+        self.platform_params = { 
+            # system-name   : (build preset, bin folder name, install folder name, is multiconfig)
+            'windows'       : ('vc16win64', 'win.x86_64.vc142.md', 'vc16win64', True),
+            'linux'         : ('linux', 'linux.clang', 'linux', False),
+            'linux-aarch64' : ('linux-aarch64', 'linux.aarch64', 'linux-aarch64', False),
+            'mac'           : ('mac64', 'mac.x86_64', 'mac64', True),
+            'ios'           : ('ios64', 'UNKNOWN', 'ios64', True),
+            'android'       : ('android-arm64-v8a', 'UNKNOWN', "android-29", False)
+        }
+
+    @property
+    def workingDir(self):
+        return self._workingDir
+
+    @property
+    def packageSystemDir(self):
+        return self._packageSystemDir
+
+    @property
+    def platform(self):
+        return self._platform
+
+    @property
+    def env(self):
+        return self._env
+
+    def readFile(self, file):
+        f = open(file, 'r')
+        content = f.read()
+        f.close()
+        return content
+
+    def writeFile(self, file, content):
+        f = open(file, 'w')
+        f.write(content)
+        f.close()
+
+    def clone(self, lockToCommit: str, prNumber: int = 0):
+        if not (self.workingDir / '.git').exists():
+            self.check_call(
+                ['git', 'init',],
+            )
+            self.check_call(
+                ['git', 'remote', 'add', 'origin', 'https://github.com/NVIDIA-Omniverse/PhysX',],
+            )
+
+        # No PR specified, use commit directly.
+        if prNumber == 0:
+            self.check_call(
+                ['git', 'fetch', 'origin', '--update-head-ok', '--depth=1', lockToCommit,],
+            )
+            self.check_call(
+                ['git', 'checkout', lockToCommit,],
+            )
+        else:
+            self.check_call(
+                ['git', 'fetch', 'origin', '--update-head-ok', '--depth=1', f'pull/{prNumber}/head:pr-{prNumber}',],
+            )
+            self.check_call(
+                ['git', 'checkout', f'pr-{prNumber}',],
+            )
+            
+    def preparePreset(self, buildAsStaticLibs):
+        preset_index = 0
+        preset_file = self.workingDir / 'physx' / 'buildtools' / 'presets' / 'public' / f'{self.platform_params[self.platform][preset_index]}.xml'
+        content = self.readFile(preset_file)
+        content = re.sub('name="PX_GENERATE_STATIC_LIBRARIES" value="(True|False)"', f'name="PX_GENERATE_STATIC_LIBRARIES" value="{buildAsStaticLibs}"', content, flags = re.M)
+        
+        if self.platform == 'windows':
+            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)
+            content = re.sub('name="NV_USE_DEBUG_WINCRT" value="(True|False)"', f'name="NV_USE_DEBUG_WINCRT" value="False"', content, flags = re.M)
+            content = re.sub('name="NV_USE_STATIC_WINCRT" value="(True|False)"', f'name="NV_USE_STATIC_WINCRT" value="False"', content, flags = re.M) # sets dynamic runtime usage
+            
+        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 
+        # by running 'cmake --build' using python subprocess on Mac.
+        if self.platform == 'mac' or self.platform == 'ios':
+            cmake_file = self.workingDir / 'physx' / 'source' / 'compiler' / 'cmake' / self.platform / 'CMakeLists.txt'
+            content = self.readFile(cmake_file)
+            content = re.sub('-Werror', r'-Werror -Wno-poison-system-directories', content, flags = re.M)
+            self.writeFile(cmake_file, content)
+        
+    def cleanUpLibs(self, buildAsStaticLibs):
+        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.
+        if self.platform == 'windows':
+            if buildAsStaticLibs:
+                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')
+            
+    def build(self, buildAsStaticLibs):
+        physx_dir = self.workingDir / 'physx'
+        
+        preset, bin_folder, install_folder, is_multiconfig = self.platform_params[self.platform]
+        
+        self.preparePreset(buildAsStaticLibs);
+        
+        if self.platform == 'windows' or self.platform == 'android':
+            generate_projects_cmd =  str(physx_dir / 'generate_projects.bat')
+        else:
+            generate_projects_cmd = str(physx_dir / 'generate_projects.sh')
+        
+        # Generate
+        check_call_physx_dir = functools.partial(subprocess.check_call,
+            cwd=physx_dir, # generate_projects script will fail if not called from physx directory
+            env=self.env
+        )
+        generate_call =[generate_projects_cmd, preset,]
+        print(generate_call)
+        check_call_physx_dir(generate_call)
+
+        # Build
+        if is_multiconfig:
+            build_dir = os.path.join(physx_dir, 'compiler', preset)
+            for config in ('release', 'profile', 'checked', 'debug'):
+                if config == 'release':
+                    # Build install target on release to produce the install folder where all the headers will be generated
+                    cmake_build_call =['cmake', '--build', build_dir, '--config', config, '--target', 'install']
+                else:
+                    cmake_build_call =['cmake', '--build', build_dir, '--config', config]
+                print(cmake_build_call)
+                self.check_call(cmake_build_call)
+        else:
+            for config in ('release', 'profile', 'checked', 'debug'):
+                build_dir = os.path.join(physx_dir, 'compiler', f'{preset}-{config}')
+                if config == 'release':
+                    # Build install target on release to produce the install folder where all the headers will be generated
+                    cmake_build_call =['cmake', '--build', build_dir, '--target', 'install']
+                else:
+                    cmake_build_call =['cmake', '--build', build_dir]
+                print(cmake_build_call)
+                self.check_call(cmake_build_call)
+                
+        # Delete bin inside install folder if exists (we'll copy them later in copyBuildOutputTo)
+        bin_install_folder = physx_dir / 'install' / install_folder / 'PhysX' / 'bin'
+        if bin_install_folder.exists():
+            shutil.rmtree(bin_install_folder)
+        
+        # Rename bin output folder to static/shared, avoiding the platform name in bin folder makes the FindPhysX.cmake simpler.
+        if buildAsStaticLibs:
+            shutil.move(physx_dir / 'bin' / bin_folder, physx_dir / 'bin' / 'static')
+            shutil.move(physx_dir / 'install' / install_folder, physx_dir / 'install' / 'static')
+        else:
+            shutil.move(physx_dir / 'bin' / bin_folder, physx_dir / 'bin' / 'shared')
+            shutil.move(physx_dir / 'install' / install_folder, physx_dir / 'install' / 'shared')
+             
+        self.cleanUpLibs(buildAsStaticLibs)
+
+    def copyBuildOutputTo(self, packageDir: pathlib.Path):
+        if packageDir.exists():
+            shutil.rmtree(packageDir)
+            
+        shutil.copytree(
+            src=self.workingDir / 'physx' / 'install' / 'shared' / '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',
+            symlinks=True,
+        )
+        shutil.copy2(
+            src=self.workingDir / 'README.md',
+            dst=packageDir / 'README.md',
+        )
+        shutil.copy2(
+            src=self.workingDir / 'LICENSE.md',
+            dst=packageDir / 'LICENSE.md',
+        )
+        shutil.copy2(
+            src=self.workingDir / 'physx' / 'README.md',
+            dst=packageDir / 'physx' / 'README.md',
+        )
+        shutil.copy2(
+            src=self.workingDir / 'physx' / 'version.txt',
+            dst=packageDir / 'physx' / 'version.txt',
+        )
+
+    def writePackageInfoFile(self, packageDir: pathlib.Path, settings: dict):
+        with (packageDir / 'PackageInfo.json').open('w') as fh:
+            json.dump(settings, fh, indent=4)
+
+    def writeCMakeFindFile(self, packageDir: pathlib.Path, cmakeFindFile):
+        dst = packageDir / 'FindPhysX.cmake'
+        shutil.copy2(
+            src=cmakeFindFile,
+            dst=dst
+        )
+        
+        extraLibsPerPlatform = {
+            'windows': [
+                ['\${EXTRA_SHARED_LIBS}',
+                 ''.join(('\n',
+                    '\t${PATH_TO_SHARED_LIBS}/PhysXDevice64.dll\n',
+                    '\t${PATH_TO_SHARED_LIBS}/PhysXGpu_64.dll\n'
+                ))],
+                ['\${EXTRA_STATIC_LIBS_NON_MONOLITHIC}',
+                 ''.join(('\n',
+                    '\t${PATH_TO_LIBS}/LowLevel_static_64.lib\n',
+                    '\t${PATH_TO_LIBS}/LowLevelAABB_static_64.lib\n',
+                    '\t${PATH_TO_LIBS}/LowLevelDynamics_static_64.lib\n',
+                    '\t${PATH_TO_LIBS}/PhysXTask_static_64.lib\n',
+                    '\t${PATH_TO_LIBS}/SceneQuery_static_64.lib\n',
+                    '\t${PATH_TO_LIBS}/SimulationController_static_64.lib\n',
+                ))],
+            ],
+            'linux': [
+                ['\${EXTRA_SHARED_LIBS}', '${PATH_TO_SHARED_LIBS}/libPhysXGpu_64.so'],
+                ['\${EXTRA_STATIC_LIBS_NON_MONOLITHIC}', ''],
+            ],
+            'linux-aarch64': [
+                ['\${EXTRA_SHARED_LIBS}', '${PATH_TO_SHARED_LIBS}/libPhysXGpu_64.so'],
+                ['\${EXTRA_STATIC_LIBS_NON_MONOLITHIC}', ''],
+            ],
+            'mac': [
+                ['\${EXTRA_SHARED_LIBS}', ''],
+                ['\${EXTRA_STATIC_LIBS_NON_MONOLITHIC}', ''],
+            ],
+            # 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}', ''],
+            ],
+        }
+        
+        content = self.readFile(dst)
+        for extraLibs in extraLibsPerPlatform[self.platform]:
+            content = re.sub(extraLibs[0], extraLibs[1], content, flags = re.M)
+        self.writeFile(dst, content)
+
+def main():
+    parser = argparse.ArgumentParser()
+    parser.add_argument(
+        '--platform-name',
+        dest='platformName',
+        choices=['windows', 'linux', 'linux-aarch64', 'android', 'mac', 'ios'],
+    )
+    args = parser.parse_args()
+
+    if args.platformName == 'mac' or args.platformName == 'ios':
+        # Necessary to build PhysX SDK on arm-based Mac machines
+        # since the build process will try to use an x86_64 python3
+        # package that PhysX downloads itself. This environment variable
+        # allows to use the system's python until nVidia updates its build
+        # scripts to obtain an arm-based python package.
+        os.environ['PM_PYTHON_EXT'] = 'python3'
+
+    packageSystemDir = Path(__file__).resolve().parents[1]
+    packageSourceDir = packageSystemDir / 'PhysX5'
+    packageRoot = packageSourceDir / 'temp' / f'PhysX5-{args.platformName}'
+
+    cmakeFindFile = packageSourceDir / f'FindPhysX_{args.platformName}.cmake'
+    if not cmakeFindFile.exists():
+        cmakeFindFile = packageSourceDir / 'FindPhysX.cmake'
+
+    with TemporaryDirectory() as tempdir:
+        # Version 5.1.1 commit
+        commit = '0bbcff3d0c541325f4d14c36ee18f24e22e35e6e'
+        packageName = f'PhysX-5.1.1-rev1-{args.platformName}'
+        if args.platformName == 'mac':
+            prNumber = 51
+        elif args.platformName == 'ios':
+            prNumber = 49
+        elif args.platformName == 'android':
+            prNumber = 40
+        else:
+            prNumber = 0
+            
+        tempdir = Path(tempdir)
+        builder = PhysXBuilder(workingDir=tempdir, basePackageSystemDir=packageSystemDir, targetPlatform=args.platformName)
+        builder.clone(lockToCommit=commit, prNumber=prNumber)
+        
+        builder.build(buildAsStaticLibs=False)
+        builder.build(buildAsStaticLibs=True)
+        builder.copyBuildOutputTo(packageRoot/'PhysX')
+        
+        builder.writePackageInfoFile(
+            packageRoot,
+            settings={
+                'PackageName': packageName,
+                'URL': 'https://github.com/NVIDIA-Omniverse/PhysX',
+                'License': 'BSD-3-Clause',
+                'LicenseFile': 'PhysX/LICENSE.md'
+            },
+        )
+        
+        builder.writeCMakeFindFile(
+            packageRoot,
+            cmakeFindFile
+        )
+
+if __name__ == '__main__':
+    main()

+ 4 - 0
package_build_list_host_darwin.json

@@ -28,6 +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-rev5-mac": "package-system/PhysX/build_package_image.py --platform mac",
         "PhysX-4.1.2.29882248-rev5-ios": "package-system/PhysX/build_package_image.py --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",
         "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",
@@ -81,6 +83,8 @@
         "asn1-0.9.27-rev2-ios": "package-system/asn1-ios",
         "PhysX-4.1.2.29882248-rev5-mac": "package-system/PhysX-mac",
         "PhysX-4.1.2.29882248-rev5-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",
         "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 - 0
package_build_list_host_linux-aarch64.json

@@ -26,6 +26,7 @@
         "OpenMesh-8.1-rev3-linux-aarch64": "Scripts/extras/pull_and_build_from_git.py ../../package-system/OpenMesh --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-rev5-linux-aarch64": "package-system/PhysX/build_package_image.py --platform-name linux-aarch64",
+        "PhysX-5.1.1-rev1-linux-aarch64": "package-system/PhysX5/build_package_image.py --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",
         "python-3.10.5-rev2-linux-aarch64": "package-system/python/build_package_image.py",
@@ -59,6 +60,7 @@
         "OpenMesh-8.1-rev3-linux-aarch64": "package-system/OpenMesh/temp/OpenMesh-linux-aarch64",
         "OpenXR-1.0.22-rev2-linux-aarch64": "package-system/OpenXR/temp/OpenXR-linux-aarch64",
         "PhysX-4.1.2.29882248-rev5-linux-aarch64": "package-system/PhysX-linux-aarch64",
+        "PhysX-5.1.1-rev1-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",
         "python-3.10.5-rev2-linux-aarch64": "package-system/python/linux_aarch64/package",

+ 2 - 0
package_build_list_host_linux.json

@@ -23,6 +23,7 @@
         "OpenXR-1.0.22-rev2-linux": "Scripts/extras/pull_and_build_from_git.py ../../package-system/OpenXR --platform-name Linux --package-root ../../package-system --clean",
         "openimageio-opencolorio-2.3.17-rev2-linux": "package-system/openimageio-opencolorio/build_openimageio.py --package-name=openimageio-opencolorio-2.3.17-rev2-linux --clean",
         "PhysX-4.1.2.29882248-rev5-linux": "package-system/PhysX/build_package_image.py --platform-name linux",
+        "PhysX-5.1.1-rev1-linux": "package-system/PhysX5/build_package_image.py --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",
@@ -67,6 +68,7 @@
         "tiff-4.2.0.15-rev3-linux": "package-system/tiff-linux",
         "python-3.10.5-rev2-linux": "package-system/python/linux_x64/package",
         "PhysX-4.1.2.29882248-rev5-linux": "package-system/PhysX-linux",
+        "PhysX-5.1.1-rev1-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 - 0
package_build_list_host_windows.json

@@ -43,6 +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-rev5-android": "package-system/PhysX/build_package_image.py --platform android",
         "PhysX-4.1.2.29882248-rev5-windows": "package-system/PhysX/build_package_image.py --platform windows",
+        "PhysX-5.1.1-rev1-android": "package-system/PhysX5/build_package_image.py --platform android",
+        "PhysX-5.1.1-rev1-windows": "package-system/PhysX5/build_package_image.py --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",
@@ -109,6 +111,8 @@
     "OpenXR-1.0.22-rev1-windows": "package-system/OpenXR-windows",
     "PhysX-4.1.2.29882248-rev5-android": "package-system/PhysX-android",
     "PhysX-4.1.2.29882248-rev5-windows": "package-system/PhysX-windows",
+    "PhysX-5.1.1-rev1-android": "package-system/PhysX5/temp/PhysX5-android",
+    "PhysX-5.1.1-rev1-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",