FindPhysX.cmake.template 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #
  2. # Copyright (c) Contributors to the Open 3D Engine Project.
  3. # For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. #
  5. # SPDX-License-Identifier: Apache-2.0 OR MIT
  6. #
  7. #
  8. set(MY_NAME "PhysX4")
  9. set(TARGET_WITH_NAMESPACE "3rdParty::$${MY_NAME}")
  10. if (TARGET $${TARGET_WITH_NAMESPACE})
  11. return()
  12. endif()
  13. set(_PACKAGE_DIR $${CMAKE_CURRENT_LIST_DIR}/PhysX/static)
  14. set(_PACKAGE_DIR_SHARED $${CMAKE_CURRENT_LIST_DIR}/PhysX/shared)
  15. set($${MY_NAME}_INCLUDE_DIR
  16. $${_PACKAGE_DIR}/include
  17. $${_PACKAGE_DIR}/include/foundation
  18. $${_PACKAGE_DIR}/include/geometry
  19. )
  20. set($${MY_NAME}_COMPILE_DEFINITIONS PX_PHYSX_STATIC_LIB)
  21. # LY_PHYSX_PROFILE_USE_CHECKED_LIBS allows to override what PhysX configuration to use on O3DE profile.
  22. set(LY_PHYSX_PROFILE_USE_CHECKED_LIBS OFF CACHE BOOL "When ON it uses PhysX SDK checked libraries on O3DE profile configuration")
  23. if(LY_PHYSX_PROFILE_USE_CHECKED_LIBS)
  24. set(PHYSX_PROFILE_CONFIG "checked")
  25. else()
  26. set(PHYSX_PROFILE_CONFIG "profile")
  27. endif()
  28. set(PATH_TO_STATIC_LIBS $${_PACKAGE_DIR}/$$<IF:$$<CONFIG:debug>,debug,$$<$$<CONFIG:profile>:$${PHYSX_PROFILE_CONFIG}>>/lib)
  29. set(PATH_TO_SHARED_LIBS $${_PACKAGE_DIR_SHARED}/$$<IF:$$<CONFIG:debug>,debug,$$<$$<CONFIG:profile>:$${PHYSX_PROFILE_CONFIG}>>/bin)
  30. set(PATH_TO_ADDITIONAL_STATIC_LIBS $${_PACKAGE_DIR_SHARED}/$$<IF:$$<CONFIG:debug>,debug,$$<$$<CONFIG:profile>:$${PHYSX_PROFILE_CONFIG}>>/lib)
  31. if(DEFINED CMAKE_IMPORT_LIBRARY_SUFFIX)
  32. set(PATH_TO_IMPORT_LIBS $${PATH_TO_STATIC_LIBS})
  33. set(import_lib_prefix $${CMAKE_IMPORT_LIBRARY_PREFIX})
  34. set(import_lib_suffix $${CMAKE_IMPORT_LIBRARY_SUFFIX})
  35. else()
  36. set(PATH_TO_IMPORT_LIBS $${PATH_TO_SHARED_LIBS})
  37. set(import_lib_prefix $${CMAKE_SHARED_LIBRARY_PREFIX})
  38. set(import_lib_suffix $${CMAKE_SHARED_LIBRARY_SUFFIX})
  39. endif()
  40. set(extra_static_libs
  41. ${EXTRA_STATIC_LIBS}
  42. )
  43. set(extra_shared_libs
  44. ${EXTRA_SHARED_LIBS}
  45. )
  46. # The order of PhysX 5.x static libraries is important for static targets. We will loop through in order and define
  47. # each static library explicitly, while setting their dependency as a chain to ensure the order is preserved
  48. set(IMPORTED_PHYSICS_LIBS
  49. PhysX_static_64
  50. PhysXPvdSDK_static_64
  51. PhysXVehicle_static_64
  52. PhysXCharacterKinematic_static_64
  53. PhysXExtensions_static_64
  54. PhysXCooking_static_64
  55. PhysXCommon_static_64
  56. PhysXFoundation_static_64
  57. )
  58. foreach(PHYSICS_LIB $${IMPORTED_PHYSICS_LIBS})
  59. # Set the individual target names to include a $${MY_NAME} prefix in order to prevent collisions
  60. # with other 3rd party PhysX Packages of different versions while retaining the same actual
  61. # filename
  62. set(PHYSICS_LIB_NAME $${MY_NAME}$${PHYSICS_LIB})
  63. add_library($${PHYSICS_LIB_NAME}::imported STATIC IMPORTED GLOBAL)
  64. # Set the import location (note: generator expressions are not supported as properties here, so each config needs to be explicit for its location)
  65. set_target_properties($${PHYSICS_LIB_NAME}::imported
  66. PROPERTIES
  67. IMPORTED_LOCATION_DEBUG $${_PACKAGE_DIR}/debug/lib/$${CMAKE_STATIC_LIBRARY_PREFIX}$${PHYSICS_LIB}$${CMAKE_STATIC_LIBRARY_SUFFIX}
  68. IMPORTED_LOCATION_PROFILE $${_PACKAGE_DIR}/$${PHYSX_PROFILE_CONFIG}/lib/$${CMAKE_STATIC_LIBRARY_PREFIX}$${PHYSICS_LIB}$${CMAKE_STATIC_LIBRARY_SUFFIX}
  69. IMPORTED_LOCATION_RELEASE $${_PACKAGE_DIR}/lib/$${CMAKE_STATIC_LIBRARY_PREFIX}$${PHYSICS_LIB}$${CMAKE_STATIC_LIBRARY_SUFFIX}
  70. )
  71. # Set the target libraries dependency on any previous lib to build the order chain
  72. target_link_libraries($${PHYSICS_LIB_NAME}::imported INTERFACE
  73. $${PREVIOUS_PHYSICS_LIB}
  74. $${PATH_TO_STATIC_LIBS}/$${CMAKE_STATIC_LIBRARY_PREFIX}$${PHYSICS_LIB}$${CMAKE_STATIC_LIBRARY_SUFFIX}
  75. )
  76. set (PREVIOUS_PHYSICS_LIB $${PHYSICS_LIB_NAME}::imported)
  77. endforeach()
  78. add_library($${MY_NAME}_STATIC_LIBS::imported INTERFACE IMPORTED GLOBAL)
  79. target_link_libraries($${MY_NAME}_STATIC_LIBS::imported INTERFACE
  80. $${PREVIOUS_PHYSICS_LIB}
  81. $${extra_static_libs}
  82. )
  83. # Add any optional shared library dependency as a runtime dependency
  84. if(extra_shared_libs)
  85. set($${MY_NAME}_RUNTIME_DEPENDENCIES
  86. $${extra_shared_libs}
  87. )
  88. endif()
  89. add_library($${TARGET_WITH_NAMESPACE} INTERFACE IMPORTED GLOBAL)
  90. ly_target_include_system_directories(TARGET $${TARGET_WITH_NAMESPACE} INTERFACE $${$${MY_NAME}_INCLUDE_DIR})
  91. target_link_libraries($${TARGET_WITH_NAMESPACE} INTERFACE $${MY_NAME}_STATIC_LIBS::imported)
  92. target_compile_definitions($${TARGET_WITH_NAMESPACE} INTERFACE $${$${MY_NAME}_COMPILE_DEFINITIONS})
  93. if(DEFINED $${MY_NAME}_RUNTIME_DEPENDENCIES)
  94. ly_add_target_files(TARGETS $${TARGET_WITH_NAMESPACE} FILES $${$${MY_NAME}_RUNTIME_DEPENDENCIES})
  95. endif()
  96. set($${MY_NAME}_FOUND True)