Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Physx5 updatePhysX Split support for PhysX5 #241

Merged
merged 12 commits into from
Feb 3, 2024
126 changes: 0 additions & 126 deletions package-system/PhysX5/FindPhysX.cmake

This file was deleted.

116 changes: 116 additions & 0 deletions package-system/PhysX5/FindPhysX5.cmake
Original file line number Diff line number Diff line change
@@ -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")
spham-amzn marked this conversation as resolved.
Show resolved Hide resolved
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)
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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")
Expand All @@ -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
Expand Down
53 changes: 53 additions & 0 deletions package-system/PhysX5/build_fix.patch
Original file line number Diff line number Diff line change
@@ -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
Loading
Loading