diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..7cd810d44 --- /dev/null +++ b/.gitignore @@ -0,0 +1,39 @@ +# Generated files (placed in source tree) +PxConfig.h + +#GitHub C++ gitignore +# Compiled Object files +*.slo +*.lo +*.o +*.obj +# Precompiled Headers +*.gch +*.pch +# Compiled Dynamic libraries +*.so +*.dylib +*.dll +# Fortran module files +*.mod +# Compiled Static libraries +*.lai +*.la +*.a +*.lib +# Executables +*.exe +*.out +*.app + +#EDITORS# +*.swp +*.swo +*.orig +*.*.orig +Session.vim +.eclimrc +*.project +*.cproject +*.ycm_extra_conf.pyc + diff --git a/README.md b/README.md index f7d6aadaf..3818295f5 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,121 @@ # NVIDIA PhysX SDK 4.1 +# Improved CMake integration (contributed by @phcerdan) +- Provide PhysXConfig.cmake and exported targets file for build and install tree. +- Other projects can use find_package(PhysX) where PhysX_DIR can be a build tree or an install tree. +- The implementation only adds two new CMakeLists.txt that do not collide with +the existing build procedure of Nvidia. Instead of using python and the generate_projects scripts, now it solely uses CMake in a standard way. +- This allows PhysX to be used with modern standards of CMake, making it compatible + with FetchContent (add_subdirectory) and ExternalProject (find_package) commands. +- Snippets and Samples have not been integrated into the new build procedure. +- But added a simpler project to show find_package(PhysX) usage. +- The original build procedure is maintained compatible for easier integration with future upstream changes from NVidia. + +## Example of CMake usage + +# Build and optionally install PhysX with just CMake: +```bash +mkdir PhysX; cd PhysX +git clone https://github.com/phcerdan/PhysX src +mkdir build; cd build; +cmake -GNinja -DCMAKE_BUILD_TYPE:STRING=release -DCMAKE_INSTALL_PREFIX:PATH=/tmp/physx ../src +ninja install +``` + +# Your project using PhysX (example added) + +```cmake +find_package(PhysX REQUIRED) +add_executable(main main.cpp) +target_link_libraries(main PRIVATE PhysX::PhysXCommon PhysX::PhysXExtensions) +``` + +You can also use FetchContent, or ExternalProjects for handling PhysX automatically. + +When building your project, just provide `PhysX_DIR` to where the PhysXConfig.cmake is located (it could be from a build or an install tree) +```bash +cmake -GNinja -DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo -DPhysX_DIR:PATH=/tmp/physx/PhysX/bin/cmake/physx ../src +``` + +## Using FetchContent (building at configure time) + +For now, the `CONFIGURATION_TYPES` of Nvidia PhysX are not default. +In order to "map" the standard CMake build/config types between a project and PhysX +we have to do extra work. +The following `CMake` gist configure and build PhysX using the variable `PHYSX_CONFIG_TYPE` (default to `release`) +to build PhysX with the chosen config type. +Also provides a install script to install PhysX with the project. +TODO(phcerdan): this installation script might require more flexibility and testing. +See [conversation](https://discourse.cmake.org/t/mapping-cmake-build-type-and-cmake-configuration-types-between-project-subdirectories/192/2) +that inspired this approach (thanks to @craig.scott) + +```cmake + # Fetch physx (CMake phcerdan branch) + include(FetchContent) + FetchContent_Declare( + physx + GIT_REPOSITORY https://github.com/phcerdan/PhysX + GIT_TAG cmake_for_easier_integration + ) + FetchContent_GetProperties(physx) + if(NOT physx_POPULATED) + message(STATUS " Populating PhysX...") + FetchContent_Populate(physx) + message(STATUS " Configuring PhysX...") + execute_process( + COMMAND ${CMAKE_COMMAND} + -S ${physx_SOURCE_DIR}/physx/ + -B ${physx_BINARY_DIR} + -DCMAKE_GENERATOR=${CMAKE_GENERATOR} + -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX} + WORKING_DIRECTORY ${physx_BINARY_DIR} + COMMAND_ECHO STDOUT + # OUTPUT_FILE ${physx_BINARY_DIR}/configure_output.log + # ERROR_FILE ${physx_BINARY_DIR}/configure_output.log + RESULT_VARIABLE result_config + ) + if(result_config) + message(FATAL_ERROR "Failed PhysX configuration") + # see configuration log at:\n ${physx_BINARY_DIR}/configure_output.log") + endif() + # PhysX is always on release mode, but can be explicitly changed by user: + set(PHYSX_CONFIG_TYPE "release" CACHE INTERNAL "Config/build type for PhysX") + message(STATUS "Building PhysX... with CONFIG: ${PHYSX_CONFIG_TYPE}") + execute_process( + COMMAND ${CMAKE_COMMAND} + --build ${physx_BINARY_DIR} + --config ${PHYSX_CONFIG_TYPE} + WORKING_DIRECTORY ${physx_BINARY_DIR} + COMMAND_ECHO STDOUT + # OUTPUT_FILE ${physx_BINARY_DIR}/build_output.log + # ERROR_FILE ${physx_BINARY_DIR}/build_output.log + RESULT_VARIABLE result_build + ) + message(STATUS " PhysX build complete") + if(result_build) + message(FATAL_ERROR "Failed PhysX build") + # see build log at:\n ${physx_BINARY_DIR}/build_output.log") + endif() + # add_subdirectory(${physx_SOURCE_DIR}/physx ${physx_BINARY_DIR}) + endif() + # create rule to install PhysX when installing this project + install (CODE " + execute_process( + COMMAND ${CMAKE_COMMAND} + --build ${physx_BINARY_DIR} + --config ${PHYSX_CONFIG_TYPE} + --target install + WORKING_DIRECTORY ${physx_BINARY_DIR} + COMMAND_ECHO STDOUT + )") + # find_package works + find_package(PhysX REQUIRED + PATHS ${physx_BINARY_DIR}/sdk_source_bin + NO_DEFAULT_PATH + ) +``` + + Copyright (c) 2019 NVIDIA Corporation. All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/externals/cmakemodules/GetCompilerAndPlatform.cmake b/externals/cmakemodules/GetCompilerAndPlatform.cmake index efaee8805..7b712d19d 100644 --- a/externals/cmakemodules/GetCompilerAndPlatform.cmake +++ b/externals/cmakemodules/GetCompilerAndPlatform.cmake @@ -117,9 +117,10 @@ FUNCTION (GetPlatformBinName PLATFORM_BIN_NAME LIBPATH_SUFFIX) ELSEIF(TARGET_BUILD_PLATFORM STREQUAL "android") SET(RETVAL "android.${ANDROID_ABI}.fp-soft") ELSEIF(TARGET_BUILD_PLATFORM STREQUAL "linux") - IF (${CMAKE_LIBRARY_ARCHITECTURE} STREQUAL "x86_64-unknown-linux-gnu" OR ${CMAKE_LIBRARY_ARCHITECTURE} STREQUAL "x86_64-linux-gnu") + IF (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang") SET(RETVAL "linux.clang") - ELSEIF(${CMAKE_LIBRARY_ARCHITECTURE} STREQUAL "aarch64-unknown-linux-gnueabi" OR ${CMAKE_LIBRARY_ARCHITECTURE} STREQUAL "aarch64-linux-gnu") + ELSEIF(${CMAKE_CXX_COMPILER_ID} MATCHES "^ARM.*" + OR ${CMAKE_CXX_COMPILER} MATCHES "arm") SET(RETVAL "linux.aarch64") ENDIF() ENDIF() diff --git a/externals/cmakemodules/NvidiaBuildOptions.cmake b/externals/cmakemodules/NvidiaBuildOptions.cmake index 46cb7d637..b53e4cadd 100644 --- a/externals/cmakemodules/NvidiaBuildOptions.cmake +++ b/externals/cmakemodules/NvidiaBuildOptions.cmake @@ -227,4 +227,4 @@ FUNCTION(StripPackmanVersion IN_VERSION _OUTPUT_VERSION) OUT_V2 ${OUT_V}) SET(${_OUTPUT_VERSION} ${OUT_V2} PARENT_SCOPE) -ENDFUNCTION(StripPackmanVersion) \ No newline at end of file +ENDFUNCTION(StripPackmanVersion) diff --git a/physx/CMakeLists.txt b/physx/CMakeLists.txt new file mode 100644 index 000000000..9297f8f37 --- /dev/null +++ b/physx/CMakeLists.txt @@ -0,0 +1,195 @@ +## +## Redistribution and use in source and binary forms, with or without +## modification, are permitted provided that the following conditions +## are met: +## * Redistributions of source code must retain the above copyright +## notice, this list of conditions and the following disclaimer. +## * Redistributions in binary form must reproduce the above copyright +## notice, this list of conditions and the following disclaimer in the +## documentation and/or other materials provided with the distribution. +## * Neither the name of NVIDIA CORPORATION nor the names of its +## contributors may be used to endorse or promote products derived +## from this software without specific prior written permission. +## +## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY +## EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +## PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +## EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +## PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +## PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +## OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +## +## Copyright (c) 2018-2019 NVIDIA Corporation. All rights reserved. +## Copyright (c) 2019 Pablo Hernandez-Cerdan + +cmake_minimum_required(VERSION 3.13) +# Change options for CMAKE_BUILD_TYPE and set default. +# Same values than CMAKE_CONFIGURATION_TYPES +# From https://gitlab.kitware.com/cmake/cmake/issues/19401 +get_property(multiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) +if(DEFINED CMAKE_BUILD_TYPE) + # Because CMAKE_BUILD_TYPE is not standard for this project, we will restore the original + # after configuring this project + set(RESTORE_CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE}) + if(${CMAKE_BUILD_TYPE} STREQUAL "Release") + set(CMAKE_BUILD_TYPE "release" CACHE STRING "Choose the type of build.") + else if(${CMAKE_BUILD_TYPE} STREQUAL "RelWithDebInfo") + set(CMAKE_BUILD_TYPE "profile" CACHE STRING "Choose the type of build.") + else if(${CMAKE_BUILD_TYPE} STREQUAL "Debug") + set(CMAKE_BUILD_TYPE "debug" CACHE STRING "Choose the type of build.") + endif() +endif() +if(NOT multiConfig AND NOT DEFINED CMAKE_BUILD_TYPE) + set(default_build_type "release") + message(STATUS "Setting build type to '${default_build_type}' as none was specified.") + set(CMAKE_BUILD_TYPE ${default_build_type} CACHE STRING "Choose the type of build.") + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS + "release" "profile" "checked" "debug") +endif() + +file(READ "version.txt" PHYSX_VERSION) +project(PhysX + LANGUAGES C CXX + VERSION ${PHYSX_VERSION}) +message(STATUS "PhysX VERSION: ${PHYSX_VERSION}") +cmake_policy(SET CMP0057 NEW) # Enable IN_LIST +cmake_policy(SET CMP0077 NEW) # option() does nothing when variable is alredy set + +# PhysXSDK options: +option(PX_BUILDSNIPPETS "Generate the snippets" OFF) +option(PX_BUILDPUBLICSAMPLES "Generate the samples" OFF) +option(PX_CMAKE_SUPPRESS_REGENERATION "Disable zero_check projects" OFF) +# PhysX options: +option(PX_SCALAR_MATH "Disable SIMD math" OFF) +option(PX_GENERATE_STATIC_LIBRARIES "Generate static libraries" OFF) +if(NOT DEFINED BUILD_SHARED_LIBS) + if(PX_GENERATE_STATIC_LIBRARIES) + set(BUILD_SHARED_LIBS OFF) + else() + set(BUILD_SHARED_LIBS ON) + endif() +else() + if(BUILD_SHARED_LIBS EQUAL PX_GENERATE_STATIC_LIBRARIES) + message(FATAL_ERROR "Contradictory options: BUILD_SHARED_LIBS and PX_GENERATE_STATIC_LIBRARIES have both the same value: ${BUILD_SHARED_LIBS}") + endif() +endif() +message(STATUS "BUILD_SHARED_LIBS: ${BUILD_SHARED_LIBS}") +message(STATUS " PX_GENERATE_STATIC_LIBRARIES: ${PX_GENERATE_STATIC_LIBRARIES}") +option(PX_EXPORT_LOWLEVEL_PDB "Export low level pdb's" OFF) +option(PX_GENERATE_GPU_PROJECTS_ONLY "Generate GPU projects only. (Untested)" OFF) +mark_as_advanced(PX_GENERATE_GPU_PROJECTS_ONLY) + +set(PUBLIC_RELEASE OFF) +# Enable folder properties +set_property(GLOBAL PROPERTY USE_FOLDERS ON) + +if(CMAKE_CONFIGURATION_TYPES) + set(CMAKE_CONFIGURATION_TYPES debug checked profile release) + set(CMAKE_CONFIGURATION_TYPES "${CMAKE_CONFIGURATION_TYPES}" CACHE STRING + "Reset config to what we need" + FORCE) + + set(CMAKE_SHARED_LINKER_FLAGS_CHECKED "") + set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "") + +endif() + +# Disable zero_check projects. The default for Switch and XboxOne is ON. +if(PX_CMAKE_SUPPRESS_REGENERATION) + set(CMAKE_SUPPRESS_REGENERATION TRUE) +endif() + +### Set PHYSX_ROOT_DIR to PROJECT_SOURCE_DIR +if(DEFINED PHYSX_ROOT_DIR) + message(WARNING "PHYSX_ROOT_DIR is externally defined, but it will be overwritten in this CMakeLists. DEPRECATED") + message("PHYSX_ROOT_DIR (externally set --not used--): ${PHYSX_ROOT_DIR}") + message("PHYSX_ROOT_DIR (currently set): ${PROJECT_SOURCE_DIR}") +endif() +set(PHYSX_ROOT_DIR ${PROJECT_SOURCE_DIR}) + +### Set TARGET_BUILD_PLATFORM using CMAKE_SYSTEM_NAME +# for compatibility with current CMake files, +# for cross-complation, CMAKE_SYSTEM_NAME can be set when running cmake +if(DEFINED TARGET_BUILD_PLATFORM) + if(TARGET_BUILD_PLATFORM STREQUAL "switch" OR + TARGET_BUILD_PLATFORM STREQUAL "playstation" OR + TARGET_BUILD_PLATFORM STREQUAL "ios") + message(FATAL_ERROR "switch, playstation and ios builds are not valid because have not been tested. Use official repository for these.") + endif() + message(INFO "TARGET_BUILD_PLATFORM (externally set --not used--): ${TARGET_BUILD_PLATFORM}") +endif() + +set(TARGET_BUILD_PLATFORM "") +if(CMAKE_SYSTEM_NAME STREQUAL "Windows") + set(TARGET_BUILD_PLATFORM "windows") +elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") + set(TARGET_BUILD_PLATFORM "linux") +elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin") + set(TARGET_BUILD_PLATFORM "mac") +elseif(CMAKE_SYSTEM_NAME STREQUAL "Android") + set(TARGET_BUILD_PLATFORM "android") +endif() + +### Set CMake folders +set(CMAKEMODULES_PATH ${PROJECT_SOURCE_DIR}/../externals/cmakemodules/ + CACHE INTERNAL "Path to CMakeModules") +set(CMAKEMODULES_NAME "CMakeModules" CACHE INTERNAL "CMakeModules name") +set(CMAKEMODULES_VERSION "1.27" CACHE INTERNAL "CMakeModules version from generation batch") +# CMAKE_MODULE_PATH is empty by default +list(APPEND CMAKE_MODULE_PATH ${CMAKEMODULES_PATH}) + +### Set platform specific files +set(PROJECT_CMAKE_FILES_DIR source/compiler/cmake) +set(PROJECT_CMAKE_FILES_ABSOLUTE_DIR ${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}) +# The following files define all the flags specific to platforms, compilers and build configurations. +# The file is included in the source/ subdirectory +set(PLATFORM_CMAKELISTS "${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/${TARGET_BUILD_PLATFORM}/CMakeLists.txt") + +set(CMAKE_POSITION_INDEPENDENT_CODE ON) + +# INSTALL PATHS +# XXX(phcerdan) CMAKE_INSTALL_PREFIX by definition has to point to the root folder of the installation +# but the upstream python configuration adds PhysX to the CMAKE_INSTALL_PREFIX, which is not standard, +# and then hack it to install PxShared in parallel to PhysX. Solved here: +set(PHYSX_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}/PhysX CACHE INTERNAL "Install path to install PhysX") +set(PXSHARED_PATH ${PROJECT_SOURCE_DIR}/../pxshared CACHE INTERNAL "Path to PxShared source") +set(PXSHARED_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}/PxShared CACHE INTERNAL "Path to install PxShared") + +# Set PX_ROOT_LIB_DIR (used in cmake files) +string(TOLOWER ${CMAKE_C_COMPILER_ID} compiler_id) +# No need to add TARGET_BUILD_PLATFORM and compiler_id in the folder structure +# set(PX_ROOT_LIB_DIR "${PHYSX_INSTALL_PREFIX}/bin/${TARGET_BUILD_PLATFORM}\.${compiler_id}") +set(PX_ROOT_LIB_DIR "${PHYSX_INSTALL_PREFIX}/bin") + +# We add CMakeLists.txt in the source folders, following standard CMake practices +# Add PhysX SDK Source code to solution +set(BUILD_SOURCE_FOLDER ${CMAKE_CURRENT_BINARY_DIR}/sdk_source_bin) +add_subdirectory(source ${BUILD_SOURCE_FOLDER}) + +# TODO(phcerdan) Snippets and Samples are not integrated with the new CMake procedure +# But check the project_using_physx for hints on how to integrate it. +if(PX_BUILDSNIPPETS) + # Add Snippets projects into the solution + add_subdirectory(${PHYSX_ROOT_DIR}/snippets/compiler/cmake ${CMAKE_CURRENT_BINARY_DIR}/sdk_snippets_bin) + + message("Added Snippets") +endif() + +if(PX_BUILDPUBLICSAMPLES) + if(CMAKE_SYSTEM_NAME STREQUAL "Windows" OR + CMAKE_SYSTEM_NAME STREQUAL "Linux") + # Add samples projects into the solution + add_subdirectory(${PHYSX_ROOT_DIR}/samples/compiler/cmake ${CMAKE_CURRENT_BINARY_DIR}/sdk_samples_bin) + + message("Added Samples") + endif() +endif() +# Restore the CMAKE_BUILD_TYPE +if(DEFINED RESTORE_CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE ${RESTORE_CMAKE_BUILD_TYPE} CACHE STRING "Choose the type of build.") +endif() + diff --git a/physx/buildtools/presets/public/linux.xml b/physx/buildtools/presets/public/linux.xml index 8c5160c78..02a208213 100644 --- a/physx/buildtools/presets/public/linux.xml +++ b/physx/buildtools/presets/public/linux.xml @@ -7,6 +7,6 @@ - + - \ No newline at end of file + diff --git a/physx/compiler/public/CMakeLists.txt b/physx/compiler/public/CMakeLists.txt index bd85eeeec..0697926ba 100644 --- a/physx/compiler/public/CMakeLists.txt +++ b/physx/compiler/public/CMakeLists.txt @@ -93,4 +93,4 @@ ENDIF() IF(TARGET_BUILD_PLATFORM STREQUAL "switch") FILE(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/ALL_BUILD.vcxproj.user" INPUT "${CMAKE_MODULE_PATH}/switch/Microsoft.Cpp.${NX_TARGET_DEVKIT}.user.props" CONDITION 1) FILE(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/INSTALL.vcxproj.user" INPUT "${CMAKE_MODULE_PATH}/switch/Microsoft.Cpp.${NX_TARGET_DEVKIT}.user.props" CONDITION 1) -ENDIF() \ No newline at end of file +ENDIF() diff --git a/physx/source/CMakeLists.txt b/physx/source/CMakeLists.txt new file mode 100644 index 000000000..596ee4f62 --- /dev/null +++ b/physx/source/CMakeLists.txt @@ -0,0 +1,129 @@ +MESSAGE(STATUS "PhysX Build Platform: " ${TARGET_BUILD_PLATFORM}) +MESSAGE(STATUS " CXX Compiler: " ${CMAKE_CXX_COMPILER}) + +# Avoid including NvidiaBuildOptions: {{{ +option(NV_USE_STATIC_WINCRT "Use the statically linked windows CRT" ON) +mark_as_advanced(NV_USE_STATIC_WINCRT) +option(NV_USE_DEBUG_WINCRT "Use the debug version of the CRT" OFF) +mark_as_advanced(NV_USE_DEBUG_WINCRT) +set(NV_USE_GAMEWORKS_OUTPUT_DIRS ON) + +include(GetCompilerAndPlatform) +if(CMAKE_SIZEOF_VOID_P EQUAL 8) + set(LIBPATH_SUFFIX "64") + # Set default exe suffix. Unset on platforms that don't need it. Include underscore since it's optional + set(EXE_SUFFIX "_64") + set(RESOURCE_LIBPATH_SUFFIX "x64") +else() + set(LIBPATH_SUFFIX "32") + # Set default exe suffix. Unset on platforms that don't need it. Include underscore since it's optional + set(EXE_SUFFIX "_32") + set(RESOURCE_LIBPATH_SUFFIX "x86") +endif() +# Set the WINCRT_DEBUG and WINCRT_NDEBUG variables for use in project compile settings +# Really only relevant to windows +set(DISABLE_ITERATOR_DEBUGGING "/D \"_HAS_ITERATOR_DEBUGGING=0\" /D \"_ITERATOR_DEBUG_LEVEL=0\"") +set(DISABLE_ITERATOR_DEBUGGING_CUDA "-D_HAS_ITERATOR_DEBUGGING=0 -D_ITERATOR_DEBUG_LEVEL=0") +set(CRT_DEBUG_FLAG "/D \"_DEBUG\"") +set(CRT_NDEBUG_FLAG "/D \"NDEBUG\"") +# Need a different format for CUDA +set(CUDA_DEBUG_FLAG "-DNDEBUG ${DISABLE_ITERATOR_DEBUGGING_CUDA}") +set(CUDA_NDEBUG_FLAG "-DNDEBUG") +IF(NV_USE_STATIC_WINCRT) + SET(WINCRT_NDEBUG "/MT ${DISABLE_ITERATOR_DEBUGGING} ${CRT_NDEBUG_FLAG}" CACHE INTERNAL "Windows CRT build setting") + SET(CUDA_CRT_COMPILE_OPTIONS_NDEBUG "/MT") + + IF (NV_USE_DEBUG_WINCRT) + SET(CUDA_DEBUG_FLAG "-D_DEBUG") + SET(WINCRT_DEBUG "/MTd ${CRT_DEBUG_FLAG}" CACHE INTERNAL "Windows CRT build setting") + SET(CUDA_CRT_COMPILE_OPTIONS_DEBUG "/MTd") + ELSE() + SET(WINCRT_DEBUG "/MT ${DISABLE_ITERATOR_DEBUGGING} ${CRT_NDEBUG_FLAG}" CACHE INTERNAL "Windows CRT build setting") + SET(CUDA_CRT_COMPILE_OPTIONS_DEBUG "/MT") + ENDIF() +ELSE() + SET(WINCRT_NDEBUG "/MD ${DISABLE_ITERATOR_DEBUGGING} ${CRT_NDEBUG_FLAG}") + SET(CUDA_CRT_COMPILE_OPTIONS_NDEBUG "/MD") + + IF(NV_USE_DEBUG_WINCRT) + SET(CUDA_DEBUG_FLAG "-D_DEBUG") + SET(WINCRT_DEBUG "/MDd ${CRT_DEBUG_FLAG}" CACHE INTERNAL "Windows CRT build setting") + SET(CUDA_CRT_COMPILE_OPTIONS_DEBUG "/MDd") + ELSE() + SET(WINCRT_DEBUG "/MD ${DISABLE_ITERATOR_DEBUGGING} ${CRT_NDEBUG_FLAG}" CACHE INTERNAL "Windows CRT build setting") + SET(CUDA_CRT_COMPILE_OPTIONS_DEBUG "/MD") + ENDIF() +ENDIF() + +# platform_bin_name is of type linux.clang, win.x86_64.vc140 etc. +GetPlatformBinName(PLATFORM_BIN_NAME ${LIBPATH_SUFFIX}) +message(STATUS "PLATFORM_BIN_NAME: ${PLATFORM_BIN_NAME}") +# }}} End NvidiaBuildOptions replacement + +set(physx_build_targets_file "${CMAKE_CURRENT_BINARY_DIR}/PhysXTargets.cmake") +set(install_cmake_dir "${PX_ROOT_LIB_DIR}/cmake/physx") + +# Include the platform specific CMakeLists +message(STATUS "PLATFORM_CMAKELISTS: ${PLATFORM_CMAKELISTS}") +include(${PLATFORM_CMAKELISTS}) + +# generate PxPhysXConfig.h header that will contain PhysX configuration defines like PX_PHYSX_STATIC_LIB +# XXX(phcerdan) the template is actually empty? Maybe populated after? No harm having an empty header meanwhile. +SET(HEADER_GUARD_NAME "CONFIG") +SET(HEADER_CONTENT "") +configure_file(${CMAKEMODULES_PATH}/template/PxIncludeTemplate.h ${PHYSX_ROOT_DIR}/include/PxConfig.h) + +### Move libPhysXGPU from source tree to build and install tree: +# libPhysXGPU libraries are in the repository (/bin) but the CUDA code is not open +# XXX(phcerdan) Nvdia does not provides GNU (gcc) GPU libaries, only clang. +# I guess both compilers are ABI compatible, but not explicitly tested in this codebase +# GCC in linux is not an option right now upstream + +## Copy the folder containing libPhysXGPU to the build and install folder for the current CONFIG +# Build tree +add_custom_command(TARGET PhysX POST_BUILD + COMMAND "${CMAKE_COMMAND}" -E copy_directory + ${PROJECT_SOURCE_DIR}/bin/${PLATFORM_BIN_NAME}/$/ + "${CMAKE_CURRENT_BINARY_DIR}/" + COMMENT "Copying libPhysXGPU from the appropiate source folder to the build directory.") +# Install tree +install(FILES ${PROJECT_SOURCE_DIR}/bin/${PLATFORM_BIN_NAME}/$ + DESTINATION ${PHYSX_INSTALL_PREFIX}/bin/) + +# Introduced based on upstream version: 4.1.1.27006925 +include(CMakePackageConfigHelpers) +write_basic_package_version_file( + ${CMAKE_CURRENT_BINARY_DIR}/PhysXConfigVersion.cmake + VERSION ${PHYSX_VERSION} + COMPATIBILITY SameMajorVersion) + +# Build tree +# TODO Export every target to build tree in each cmake//CMakeLists.txt file +set(PhysX_TARGETS_FILE ${physx_build_targets_file}) +configure_package_config_file( + ${PROJECT_CMAKE_FILES_ABSOLUTE_DIR}/PhysXConfig.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/PhysXConfig.cmake + INSTALL_DESTINATION ${install_cmake_dir} + PATH_VARS PhysX_TARGETS_FILE + # NO_CHECK_REQUIRED_COMPONENTS_MACRO # PhysX does not provide components + INSTALL_PREFIX ${CMAKE_CURRENT_BINARY_DIR} + ) + +# Install tree +install (EXPORT PhysX + NAMESPACE PhysX:: + FILE PhysXTargets.cmake + DESTINATION ${install_cmake_dir} ) + +set(PhysX_TARGETS_FILE ${CMAKE_INSTALL_PREFIX}/${install_cmake_dir}/PhysXTargets.cmake) +configure_package_config_file( + ${PROJECT_CMAKE_FILES_ABSOLUTE_DIR}/PhysXConfig.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/cmake/PhysXConfig.cmake + INSTALL_DESTINATION ${install_cmake_dir} + PATH_VARS PhysX_TARGETS_FILE + # NO_CHECK_REQUIRED_COMPONENTS_MACRO # PhysX does not provide components + ) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/cmake/PhysXConfig.cmake + ${CMAKE_CURRENT_BINARY_DIR}/PhysXConfigVersion.cmake + DESTINATION ${install_cmake_dir}) + diff --git a/physx/source/compiler/cmake/CMakeLists.txt b/physx/source/compiler/cmake/CMakeLists.txt index 4c70f65e8..3c343e196 100644 --- a/physx/source/compiler/cmake/CMakeLists.txt +++ b/physx/source/compiler/cmake/CMakeLists.txt @@ -69,6 +69,11 @@ MESSAGE("Using CXX Compiler: " ${CMAKE_CXX_COMPILER}) INCLUDE(NvidiaBuildOptions) +# In the presets configuration, CMAKE_INSTALL_PREFIX already contains PhysX folder. +# But then, the PXSHARED_INSTALL_PREFIX is hacked replacing PhysX for PxShared +# This variable is set to be compatible with the non-python (only CMake) build: "Install path to PhysX" +SET(PHYSX_INSTALL_PREFIX ".") + IF (NOT EXISTS ${PXSHARED_PATH}) IF (NOT EXISTS $ENV{PM_PxShared_PATH}) MESSAGE(FATAL_ERROR "Trying to set PxShared path, but PM_PxShared_PATH is not valid: '$ENV{PM_PxShared_PATH}'.") @@ -77,9 +82,7 @@ IF (NOT EXISTS ${PXSHARED_PATH}) STRING(REPLACE "\\" "/" PXSHARED_PATH_TMP ${PXSHARED_PATH_TMP}) SET(PXSHARED_PATH ${PXSHARED_PATH_TMP} CACHE INTERNAL "Path to PxShared") - - STRING(REGEX REPLACE "/PhysX$" "/PxShared" PXSHARED_INSTALL_PREFIX_TMP ${CMAKE_INSTALL_PREFIX}) - SET(PXSHARED_INSTALL_PREFIX ${PXSHARED_INSTALL_PREFIX_TMP} CACHE INTERNAL "Path to PxShared") + SET(PXSHARED_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}/PxShared CACHE INTERNAL "Install path to PxShared") ENDIF() IF(CMAKE_CONFIGURATION_TYPES) @@ -136,4 +139,4 @@ IF(PX_GENERATE_SOURCE_DISTRO) FOREACH(FILE_NAME ${SOURCE_DISTRO_FILE_LIST}) FILE(APPEND "${CMAKE_CURRENT_BINARY_DIR}/source_distro_list.txt" "${FILE_NAME}\n") ENDFOREACH() -ENDIF() \ No newline at end of file +ENDIF() diff --git a/physx/source/compiler/cmake/FastXml.cmake b/physx/source/compiler/cmake/FastXml.cmake index 49eda4f5f..a8dc9301f 100644 --- a/physx/source/compiler/cmake/FastXml.cmake +++ b/physx/source/compiler/cmake/FastXml.cmake @@ -51,6 +51,7 @@ ADD_LIBRARY(FastXml ${FASTXML_LIBTYPE} ${FASTXML_HEADERS} ${FASTXML_SOURCE} ) +ADD_LIBRARY(PhysX::FastXml ALIAS FastXml) GET_TARGET_PROPERTY(PHYSXFOUNDATION_INCLUDES PhysXFoundation INTERFACE_INCLUDE_DIRECTORIES) @@ -82,7 +83,7 @@ IF(FASTXML_COMPILE_PDB_NAME_DEBUG) ) ENDIF() -INSTALL(FILES ${FASTXML_HEADERS} DESTINATION source/fastxml/include) +INSTALL(FILES ${FASTXML_HEADERS} DESTINATION ${PHYSX_INSTALL_PREFIX}/source/fastxml/include) IF(PX_GENERATE_SOURCE_DISTRO) LIST(APPEND SOURCE_DISTRO_FILE_LIST ${FASTXML_HEADERS}) diff --git a/physx/source/compiler/cmake/LowLevel.cmake b/physx/source/compiler/cmake/LowLevel.cmake index 6249635cf..03b766c04 100644 --- a/physx/source/compiler/cmake/LowLevel.cmake +++ b/physx/source/compiler/cmake/LowLevel.cmake @@ -145,6 +145,7 @@ ADD_LIBRARY(LowLevel ${LOWLEVEL_LIBTYPE} ${LL_SOFTWARE_HEADERS} ${LL_SOFTWARE_SOURCE} ) +ADD_LIBRARY(PhysX::LowLevel ALIAS LowLevel) GET_TARGET_PROPERTY(PHYSXFOUNDATION_INCLUDES PhysXFoundation INTERFACE_INCLUDE_DIRECTORIES) diff --git a/physx/source/compiler/cmake/LowLevelAABB.cmake b/physx/source/compiler/cmake/LowLevelAABB.cmake index 2155adf45..cf4868830 100644 --- a/physx/source/compiler/cmake/LowLevelAABB.cmake +++ b/physx/source/compiler/cmake/LowLevelAABB.cmake @@ -69,6 +69,7 @@ ADD_LIBRARY(LowLevelAABB ${LOWLEVELAABB_LIBTYPE} ${LLAABB_HEADERS} ${LLAABB_SOURCE} ) +ADD_LIBRARY(PhysX::LowLevelAABB ALIAS LowLevelAABB) GET_TARGET_PROPERTY(PHYSXFOUNDATION_INCLUDES PhysXFoundation INTERFACE_INCLUDE_DIRECTORIES) diff --git a/physx/source/compiler/cmake/LowLevelDynamics.cmake b/physx/source/compiler/cmake/LowLevelDynamics.cmake index d306ed5cc..23b119fb9 100644 --- a/physx/source/compiler/cmake/LowLevelDynamics.cmake +++ b/physx/source/compiler/cmake/LowLevelDynamics.cmake @@ -137,6 +137,7 @@ ADD_LIBRARY(LowLevelDynamics ${LOWLEVELDYNAMICS_LIBTYPE} ${LLDYNAMICS_SOURCE} ${LLDYNAMICS_INTERNAL_INCLUDES} ) +ADD_LIBRARY(PhysX::LowLevelDynamics ALIAS LowLevelDynamics) GET_TARGET_PROPERTY(PHYSXFOUNDATION_INCLUDES PhysXFoundation INTERFACE_INCLUDE_DIRECTORIES) diff --git a/physx/source/compiler/cmake/PhysX.cmake b/physx/source/compiler/cmake/PhysX.cmake index 1ebce750a..2de96d0b3 100644 --- a/physx/source/compiler/cmake/PhysX.cmake +++ b/physx/source/compiler/cmake/PhysX.cmake @@ -254,15 +254,16 @@ ADD_LIBRARY(PhysX ${PHYSX_LIBTYPE} ${PHYSX_PLATFORM_SRC_FILES} ) +ADD_LIBRARY(PhysX::PhysX ALIAS PhysX) # Add the headers to the install -INSTALL(FILES ${PHYSX_HEADERS} DESTINATION include) -INSTALL(FILES ${PHYSX_COMMON_HEADERS} DESTINATION include/common) -INSTALL(FILES ${PHYSX_PVD_HEADERS} DESTINATION include/pvd) -INSTALL(FILES ${PHYSX_COLLISION_HEADERS} DESTINATION include/collision) -INSTALL(FILES ${PHYSX_SOLVER_HEADERS} DESTINATION include/solver) +INSTALL(FILES ${PHYSX_HEADERS} DESTINATION ${PHYSX_INSTALL_PREFIX}/include) +INSTALL(FILES ${PHYSX_COMMON_HEADERS} DESTINATION ${PHYSX_INSTALL_PREFIX}/include/common) +INSTALL(FILES ${PHYSX_PVD_HEADERS} DESTINATION ${PHYSX_INSTALL_PREFIX}/include/pvd) +INSTALL(FILES ${PHYSX_COLLISION_HEADERS} DESTINATION ${PHYSX_INSTALL_PREFIX}/include/collision) +INSTALL(FILES ${PHYSX_SOLVER_HEADERS} DESTINATION ${PHYSX_INSTALL_PREFIX}/include/solver) # install the custom config file -INSTALL(FILES ${PHYSX_ROOT_DIR}/include/PxConfig.h DESTINATION include) +INSTALL(FILES ${PHYSX_ROOT_DIR}/include/PxConfig.h DESTINATION ${PHYSX_INSTALL_PREFIX}/include) TARGET_INCLUDE_DIRECTORIES(PhysX PRIVATE ${PHYSX_PLATFORM_INCLUDES} diff --git a/physx/source/compiler/cmake/PhysXCharacterKinematic.cmake b/physx/source/compiler/cmake/PhysXCharacterKinematic.cmake index 1fc51a2d7..afe4a23f4 100644 --- a/physx/source/compiler/cmake/PhysXCharacterKinematic.cmake +++ b/physx/source/compiler/cmake/PhysXCharacterKinematic.cmake @@ -76,8 +76,9 @@ ADD_LIBRARY(PhysXCharacterKinematic ${PHYSXCHARACTERKINEMATIC_LIBTYPE} ${PHYSXCCT_HEADERS} ${PHYSXCCT_SOURCE} ) +ADD_LIBRARY(PhysX::PhysXCharacterKinematic ALIAS PhysXCharacterKinematic) -INSTALL(FILES ${PHYSXCCT_HEADERS} DESTINATION include/characterkinematic) +INSTALL(FILES ${PHYSXCCT_HEADERS} DESTINATION ${PHYSX_INSTALL_PREFIX}/include/characterkinematic) TARGET_INCLUDE_DIRECTORIES(PhysXCharacterKinematic diff --git a/physx/source/compiler/cmake/PhysXCommon.cmake b/physx/source/compiler/cmake/PhysXCommon.cmake index ca36ec0c6..d637bcc05 100644 --- a/physx/source/compiler/cmake/PhysXCommon.cmake +++ b/physx/source/compiler/cmake/PhysXCommon.cmake @@ -488,14 +488,15 @@ ADD_LIBRARY(PhysXCommon ${PHYSXCOMMON_LIBTYPE} ${PHYSXCOMMON_GU_PCM_SOURCE} ${PHYSXCOMMON_GU_SWEEP_SOURCE} ) +ADD_LIBRARY(PhysX::PhysXCommon ALIAS PhysXCommon) -INSTALL(FILES ${PHYSXCOMMON_GEOMETRY_HEADERS} DESTINATION include/geometry) -INSTALL(FILES ${PHYSXCOMMON_GEOMUTILS_HEADERS} DESTINATION include/geomutils) +INSTALL(FILES ${PHYSXCOMMON_GEOMETRY_HEADERS} DESTINATION ${PHYSX_INSTALL_PREFIX}/include/geometry) +INSTALL(FILES ${PHYSXCOMMON_GEOMUTILS_HEADERS} DESTINATION ${PHYSX_INSTALL_PREFIX}/include/geomutils) TARGET_INCLUDE_DIRECTORIES(PhysXCommon PRIVATE ${PXCOMMON_PLATFORM_INCLUDES} - PUBLIC ${PHYSX_ROOT_DIR}/include + PUBLIC $$ PRIVATE ${PHYSX_SOURCE_DIR}/common/include PRIVATE ${PHYSX_SOURCE_DIR}/common/src diff --git a/physx/source/compiler/cmake/PhysXConfig.cmake.in b/physx/source/compiler/cmake/PhysXConfig.cmake.in new file mode 100644 index 000000000..036190032 --- /dev/null +++ b/physx/source/compiler/cmake/PhysXConfig.cmake.in @@ -0,0 +1,8 @@ +@PACKAGE_INIT@ + +include(CMakeFindDependencyMacro) + +get_filename_component(PhysX_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) +if(NOT TARGET PhysX) + include ("${PhysX_CMAKE_DIR}/PhysXTargets.cmake") +endif() diff --git a/physx/source/compiler/cmake/PhysXCooking.cmake b/physx/source/compiler/cmake/PhysXCooking.cmake index 765122b3b..37ede0b3f 100644 --- a/physx/source/compiler/cmake/PhysXCooking.cmake +++ b/physx/source/compiler/cmake/PhysXCooking.cmake @@ -115,8 +115,9 @@ ADD_LIBRARY(PhysXCooking ${PHYSXCOOKING_LIBTYPE} ${PHYSXCOOKING_PLATFORM_SRC_FILES} ) +ADD_LIBRARY(PhysX::PhysXCooking ALIAS PhysXCooking) -INSTALL(FILES ${PHYSX_COOKING_HEADERS} DESTINATION include/cooking) +INSTALL(FILES ${PHYSX_COOKING_HEADERS} DESTINATION ${PHYSX_INSTALL_PREFIX}/include/cooking) # Target specific compile options @@ -128,19 +129,19 @@ TARGET_INCLUDE_DIRECTORIES(PhysXCooking PRIVATE ${PHYSX_SOURCE_DIR}/common/include PRIVATE ${PHYSX_SOURCE_DIR}/common/src - PUBLIC ${PHYSX_SOURCE_DIR}/geomutils/include - PUBLIC ${PHYSX_SOURCE_DIR}/geomutils/src - PUBLIC ${PHYSX_SOURCE_DIR}/geomutils/src/contact - PUBLIC ${PHYSX_SOURCE_DIR}/geomutils/src/common - PUBLIC ${PHYSX_SOURCE_DIR}/geomutils/src/convex - PUBLIC ${PHYSX_SOURCE_DIR}/geomutils/src/distance - PUBLIC ${PHYSX_SOURCE_DIR}/geomutils/src/sweep - PUBLIC ${PHYSX_SOURCE_DIR}/geomutils/src/gjk - PUBLIC ${PHYSX_SOURCE_DIR}/geomutils/src/intersection - PUBLIC ${PHYSX_SOURCE_DIR}/geomutils/src/mesh - PUBLIC ${PHYSX_SOURCE_DIR}/geomutils/src/hf - PUBLIC ${PHYSX_SOURCE_DIR}/geomutils/src/pcm - PUBLIC ${PHYSX_SOURCE_DIR}/geomutils/src/ccd + PRIVATE ${PHYSX_SOURCE_DIR}/geomutils/include + PRIVATE ${PHYSX_SOURCE_DIR}/geomutils/src + PRIVATE ${PHYSX_SOURCE_DIR}/geomutils/src/contact + PRIVATE ${PHYSX_SOURCE_DIR}/geomutils/src/common + PRIVATE ${PHYSX_SOURCE_DIR}/geomutils/src/convex + PRIVATE ${PHYSX_SOURCE_DIR}/geomutils/src/distance + PRIVATE ${PHYSX_SOURCE_DIR}/geomutils/src/sweep + PRIVATE ${PHYSX_SOURCE_DIR}/geomutils/src/gjk + PRIVATE ${PHYSX_SOURCE_DIR}/geomutils/src/intersection + PRIVATE ${PHYSX_SOURCE_DIR}/geomutils/src/mesh + PRIVATE ${PHYSX_SOURCE_DIR}/geomutils/src/hf + PRIVATE ${PHYSX_SOURCE_DIR}/geomutils/src/pcm + PRIVATE ${PHYSX_SOURCE_DIR}/geomutils/src/ccd PRIVATE ${PHYSX_SOURCE_DIR}/physxcooking/src PRIVATE ${PHYSX_SOURCE_DIR}/physxcooking/src/mesh diff --git a/physx/source/compiler/cmake/PhysXExtensions.cmake b/physx/source/compiler/cmake/PhysXExtensions.cmake index 6fb10fc5b..15b47f7db 100644 --- a/physx/source/compiler/cmake/PhysXExtensions.cmake +++ b/physx/source/compiler/cmake/PhysXExtensions.cmake @@ -220,9 +220,10 @@ ADD_LIBRARY(PhysXExtensions ${PHYSXEXTENSIONS_LIBTYPE} ${PHYSX_EXTENSIONS_SERIALIZATION_FILE_SOURCE} ${PHYSX_EXTENSIONS_SERIALIZATION_BINARY_SOURCE} ) +ADD_LIBRARY(PhysX::PhysXExtensions ALIAS PhysXExtensions) -INSTALL(FILES ${PHYSX_EXTENSIONS_HEADERS} DESTINATION include/extensions) -INSTALL(FILES ${PHYSX_FILEBUF_HEADERS} DESTINATION include/filebuf) +INSTALL(FILES ${PHYSX_EXTENSIONS_HEADERS} DESTINATION ${PHYSX_INSTALL_PREFIX}/include/extensions) +INSTALL(FILES ${PHYSX_FILEBUF_HEADERS} DESTINATION ${PHYSX_INSTALL_PREFIX}/include/filebuf) TARGET_INCLUDE_DIRECTORIES(PhysXExtensions diff --git a/physx/source/compiler/cmake/PhysXFoundation.cmake b/physx/source/compiler/cmake/PhysXFoundation.cmake index 8190e24a6..c712191ac 100644 --- a/physx/source/compiler/cmake/PhysXFoundation.cmake +++ b/physx/source/compiler/cmake/PhysXFoundation.cmake @@ -143,11 +143,12 @@ ADD_LIBRARY(PhysXFoundation ${PHYSXFOUNDATION_LIBTYPE} ${PXSHARED_HEADERS} ${PXSHARED_PLATFORM_HEADERS} ) +ADD_LIBRARY(PhysX::PhysXFoundation ALIAS PhysXFoundation) # Add the headers to the install -INSTALL(FILES ${PHYSXFOUNDATION_HEADERS} DESTINATION include) -INSTALL(FILES ${PHYSXFOUNDATION_HEADERS_2} DESTINATION include/foundation) -INSTALL(FILES ${PHYSXFOUNDATION_SOURCE_HEADERS} DESTINATION source/foundation/include) +INSTALL(FILES ${PHYSXFOUNDATION_HEADERS} DESTINATION ${PHYSX_INSTALL_PREFIX}/include) +INSTALL(FILES ${PHYSXFOUNDATION_HEADERS_2} DESTINATION ${PHYSX_INSTALL_PREFIX}/include/foundation) +INSTALL(FILES ${PHYSXFOUNDATION_SOURCE_HEADERS} DESTINATION ${PHYSX_INSTALL_PREFIX}/source/foundation/include) INSTALL(FILES ${PXSHARED_HEADERS} DESTINATION ${PXSHARED_INSTALL_PREFIX}/include/foundation) TARGET_INCLUDE_DIRECTORIES(PhysXFoundation @@ -156,11 +157,11 @@ TARGET_INCLUDE_DIRECTORIES(PhysXFoundation PRIVATE ${LL_SOURCE_DIR}/include PRIVATE ${PHYSXFOUNDATION_PLATFORM_INCLUDES} - INTERFACE $$ - INTERFACE $$ + INTERFACE $$ + INTERFACE $$ # FIXME: This is really terrible! Don't export src directories - INTERFACE $$ + INTERFACE $$ ) TARGET_COMPILE_DEFINITIONS(PhysXFoundation diff --git a/physx/source/compiler/cmake/PhysXPvdSDK.cmake b/physx/source/compiler/cmake/PhysXPvdSDK.cmake index 21b217023..c8b0ddd3c 100644 --- a/physx/source/compiler/cmake/PhysXPvdSDK.cmake +++ b/physx/source/compiler/cmake/PhysXPvdSDK.cmake @@ -132,6 +132,7 @@ ADD_LIBRARY(PhysXPvdSDK ${PHYSXPVDSDK_LIBTYPE} ${PHYSXPVDSDK_PLATFORM_FILES} ) +ADD_LIBRARY(PhysX::PhysXPvdSDK ALIAS PhysXPvdSDK) TARGET_INCLUDE_DIRECTORIES(PhysXPvdSDK PRIVATE ${PHYSXPVDSDK_PLATFORM_INCLUDES} diff --git a/physx/source/compiler/cmake/PhysXTask.cmake b/physx/source/compiler/cmake/PhysXTask.cmake index 8b9e763aa..d3fd1046d 100644 --- a/physx/source/compiler/cmake/PhysXTask.cmake +++ b/physx/source/compiler/cmake/PhysXTask.cmake @@ -52,8 +52,9 @@ ADD_LIBRARY(PhysXTask ${PHYSXTASK_LIBTYPE} ${PHYSXTASK_HEADERS} ${PHYSXTASK_SOURCE} ) +ADD_LIBRARY(PhysX::PhysXTask ALIAS PhysXTask) -INSTALL(FILES ${PHYSXTASK_HEADERS} DESTINATION include/task) +INSTALL(FILES ${PHYSXTASK_HEADERS} DESTINATION ${PHYSX_INSTALL_PREFIX}/include/task) GET_TARGET_PROPERTY(PHYSXFOUNDATION_INCLUDES PhysXFoundation INTERFACE_INCLUDE_DIRECTORIES) diff --git a/physx/source/compiler/cmake/PhysXVehicle.cmake b/physx/source/compiler/cmake/PhysXVehicle.cmake index 538c74c24..d431b423e 100644 --- a/physx/source/compiler/cmake/PhysXVehicle.cmake +++ b/physx/source/compiler/cmake/PhysXVehicle.cmake @@ -100,8 +100,9 @@ ADD_LIBRARY(PhysXVehicle ${PHYSXVEHICLE_LIBTYPE} ${PHYSX_VEHICLE_METADATA_HEADERS} ${PHYSX_VEHICLE_METADATA_SOURCE} ) +ADD_LIBRARY(PhysX::PhysXVehicle ALIAS PhysXVehicle) -INSTALL(FILES ${PHYSX_VEHICLE_HEADERS} DESTINATION include/vehicle) +INSTALL(FILES ${PHYSX_VEHICLE_HEADERS} DESTINATION ${PHYSX_INSTALL_PREFIX}/include/vehicle) TARGET_INCLUDE_DIRECTORIES(PhysXVehicle PRIVATE ${PHYSXVEHICLE_PLATFORM_INCLUDES} diff --git a/physx/source/compiler/cmake/SceneQuery.cmake b/physx/source/compiler/cmake/SceneQuery.cmake index 0ebde60aa..e647f8d9e 100644 --- a/physx/source/compiler/cmake/SceneQuery.cmake +++ b/physx/source/compiler/cmake/SceneQuery.cmake @@ -81,6 +81,7 @@ ADD_LIBRARY(SceneQuery ${SCENEQUERY_LIBTYPE} ${SCENEQUERY_HEADERS} ${SCENEQUERY_SOURCE} ) +ADD_LIBRARY(PhysX::SceneQuery ALIAS SceneQuery) # Target specific compile options diff --git a/physx/source/compiler/cmake/SimulationController.cmake b/physx/source/compiler/cmake/SimulationController.cmake index bb8342c96..d0c3e83a2 100644 --- a/physx/source/compiler/cmake/SimulationController.cmake +++ b/physx/source/compiler/cmake/SimulationController.cmake @@ -123,6 +123,7 @@ ADD_LIBRARY(SimulationController ${SIMULATIONCONTROLLER_LIBTYPE} ${SIMULATIONCONTROLLER_HEADERS} ${SIMULATIONCONTROLLER_SOURCE} ) +ADD_LIBRARY(PhysX::SimulationController ALIAS SimulationController) GET_TARGET_PROPERTY(PHYSXFOUNDATION_INCLUDES PhysXFoundation INTERFACE_INCLUDE_DIRECTORIES) diff --git a/physx/source/compiler/cmake/android/CMakeLists.txt b/physx/source/compiler/cmake/android/CMakeLists.txt index d0874b3cb..97f0d3b7e 100644 --- a/physx/source/compiler/cmake/android/CMakeLists.txt +++ b/physx/source/compiler/cmake/android/CMakeLists.txt @@ -80,21 +80,21 @@ SET(CMAKE_RELEASE_POSTFIX "${CMAKE_RELEASE_POSTFIX}") # Include all of the projects -INCLUDE(PhysXFoundation.cmake) -INCLUDE(LowLevel.cmake) -INCLUDE(LowLevelAABB.cmake) -INCLUDE(LowLevelDynamics.cmake) -INCLUDE(PhysX.cmake) -INCLUDE(PhysXCharacterKinematic.cmake) -INCLUDE(PhysXCommon.cmake) -INCLUDE(PhysXCooking.cmake) -INCLUDE(PhysXExtensions.cmake) -INCLUDE(PhysXVehicle.cmake) -INCLUDE(PhysXPvdSDK.cmake) -INCLUDE(PhysXTask.cmake) -INCLUDE(SceneQuery.cmake) -INCLUDE(SimulationController.cmake) -INCLUDE(FastXml.cmake) +INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/PhysXFoundation.cmake) +INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/LowLevel.cmake) +INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/LowLevelAABB.cmake) +INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/LowLevelDynamics.cmake) +INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/PhysX.cmake) +INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/PhysXCharacterKinematic.cmake) +INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/PhysXCommon.cmake) +INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/PhysXCooking.cmake) +INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/PhysXExtensions.cmake) +INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/PhysXVehicle.cmake) +INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/PhysXPvdSDK.cmake) +INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/PhysXTask.cmake) +INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/SceneQuery.cmake) +INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/SimulationController.cmake) +INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/FastXml.cmake) # Set folder PhysX SDK to all common SDK source projects SET_PROPERTY(TARGET PhysX PROPERTY FOLDER "PhysX SDK") @@ -111,4 +111,4 @@ SET_PROPERTY(TARGET SimulationController PROPERTY FOLDER "PhysX SDK") SET_PROPERTY(TARGET FastXml PROPERTY FOLDER "PhysX SDK") SET_PROPERTY(TARGET PhysXPvdSDK PROPERTY FOLDER "PhysX SDK") SET_PROPERTY(TARGET PhysXTask PROPERTY FOLDER "PhysX SDK") -SET_PROPERTY(TARGET PhysXFoundation PROPERTY FOLDER "PhysX SDK") \ No newline at end of file +SET_PROPERTY(TARGET PhysXFoundation PROPERTY FOLDER "PhysX SDK") diff --git a/physx/source/compiler/cmake/android/PhysXFoundation.cmake b/physx/source/compiler/cmake/android/PhysXFoundation.cmake index 0d23ba916..4f83ddd57 100644 --- a/physx/source/compiler/cmake/android/PhysXFoundation.cmake +++ b/physx/source/compiler/cmake/android/PhysXFoundation.cmake @@ -84,8 +84,8 @@ SET(PHYSXFOUNDATION_PLATFORM_SOURCE_HEADERS_3 ${LL_SOURCE_DIR}/include/unix/neon/PsUnixNeonInlineAoS.h ) -INSTALL(FILES ${PHYSXFOUNDATION_PLATFORM_SOURCE_HEADERS} DESTINATION source/foundation/include/unix) -INSTALL(FILES ${PHYSXFOUNDATION_PLATFORM_SOURCE_HEADERS_3} DESTINATION source/foundation/include/unix/neon) +INSTALL(FILES ${PHYSXFOUNDATION_PLATFORM_SOURCE_HEADERS} DESTINATION ${PHYSX_INSTALL_PREFIX}/source/foundation/include/unix) +INSTALL(FILES ${PHYSXFOUNDATION_PLATFORM_SOURCE_HEADERS_3} DESTINATION ${PHYSX_INSTALL_PREFIX}/source/foundation/include/unix/neon) INSTALL(FILES ${PXSHARED_PLATFORM_HEADERS} DESTINATION ${PXSHARED_INSTALL_PREFIX}/include/foundation/unix) diff --git a/physx/source/compiler/cmake/ios/CMakeLists.txt b/physx/source/compiler/cmake/ios/CMakeLists.txt index 9d713c91c..1a54b87e7 100644 --- a/physx/source/compiler/cmake/ios/CMakeLists.txt +++ b/physx/source/compiler/cmake/ios/CMakeLists.txt @@ -58,21 +58,21 @@ SET(PHYSX_IOS_RELEASE_COMPILE_DEFS "NDEBUG;PX_SUPPORT_PVD=0" CACHE INTERNAL "Rel # Include all of the projects -INCLUDE(PhysXFoundation.cmake) -INCLUDE(LowLevel.cmake) -INCLUDE(LowLevelAABB.cmake) -INCLUDE(LowLevelDynamics.cmake) -INCLUDE(PhysX.cmake) -INCLUDE(PhysXCharacterKinematic.cmake) -INCLUDE(PhysXCommon.cmake) -INCLUDE(PhysXCooking.cmake) -INCLUDE(PhysXExtensions.cmake) -INCLUDE(PhysXVehicle.cmake) -INCLUDE(PhysXPvdSDK.cmake) -INCLUDE(PhysXTask.cmake) -INCLUDE(SceneQuery.cmake) -INCLUDE(SimulationController.cmake) -INCLUDE(FastXml.cmake) +INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/PhysXFoundation.cmake) +INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/LowLevel.cmake) +INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/LowLevelAABB.cmake) +INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/LowLevelDynamics.cmake) +INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/PhysX.cmake) +INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/PhysXCharacterKinematic.cmake) +INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/PhysXCommon.cmake) +INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/PhysXCooking.cmake) +INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/PhysXExtensions.cmake) +INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/PhysXVehicle.cmake) +INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/PhysXPvdSDK.cmake) +INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/PhysXTask.cmake) +INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/SceneQuery.cmake) +INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/SimulationController.cmake) +INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/FastXml.cmake) # Set folder PhysX SDK to all common SDK source projects SET_PROPERTY(TARGET PhysX PROPERTY FOLDER "PhysX SDK") @@ -89,4 +89,4 @@ SET_PROPERTY(TARGET SimulationController PROPERTY FOLDER "PhysX SDK") SET_PROPERTY(TARGET FastXml PROPERTY FOLDER "PhysX SDK") SET_PROPERTY(TARGET PhysXPvdSDK PROPERTY FOLDER "PhysX SDK") SET_PROPERTY(TARGET PhysXTask PROPERTY FOLDER "PhysX SDK") -SET_PROPERTY(TARGET PhysXFoundation PROPERTY FOLDER "PhysX SDK") \ No newline at end of file +SET_PROPERTY(TARGET PhysXFoundation PROPERTY FOLDER "PhysX SDK") diff --git a/physx/source/compiler/cmake/ios/PhysXFoundation.cmake b/physx/source/compiler/cmake/ios/PhysXFoundation.cmake index a79662e7e..b4fc3fb02 100644 --- a/physx/source/compiler/cmake/ios/PhysXFoundation.cmake +++ b/physx/source/compiler/cmake/ios/PhysXFoundation.cmake @@ -73,8 +73,8 @@ SET(PHYSXFOUNDATION_PLATFORM_SOURCE_HEADERS ) SOURCE_GROUP("src\\include\\unix" FILES ${PHYSXFOUNDATION_PLATFORM_SOURCE_HEADERS}) -INSTALL(FILES ${PHYSXFOUNDATION_PLATFORM_SOURCE_HEADERS} DESTINATION source/foundation/include/unix) -INSTALL(FILES ${PHYSXFOUNDATION_NEON_FILES} DESTINATION source/foundation/include/unix/neon) +INSTALL(FILES ${PHYSXFOUNDATION_PLATFORM_SOURCE_HEADERS} DESTINATION ${PHYSX_INSTALL_PREFIX}/source/foundation/include/unix) +INSTALL(FILES ${PHYSXFOUNDATION_NEON_FILES} DESTINATION ${PHYSX_INSTALL_PREFIX}/source/foundation/include/unix/neon) INSTALL(FILES ${PXSHARED_PLATFORM_HEADERS} DESTINATION ${PXSHARED_INSTALL_PREFIX}/include/foundation/unix) SET(PHYSXFOUNDATION_PLATFORM_FILES diff --git a/physx/source/compiler/cmake/linux/CMakeLists.txt b/physx/source/compiler/cmake/linux/CMakeLists.txt index 13acf52ea..31fe9fb76 100644 --- a/physx/source/compiler/cmake/linux/CMakeLists.txt +++ b/physx/source/compiler/cmake/linux/CMakeLists.txt @@ -33,9 +33,9 @@ SET(GCC_WARNINGS "-Wall -Werror -Wno-invalid-offsetof -Wno-uninitialized") IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") # using Clang - SET(PHYSX_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fno-rtti -fno-exceptions -ffunction-sections -fdata-sections -fstrict-aliasing ${CLANG_WARNINGS}" CACHE INTERAL "PhysX CXX") + SET(PHYSX_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fno-rtti -fno-exceptions -ffunction-sections -fdata-sections -fstrict-aliasing ${CLANG_WARNINGS}" CACHE INTERNAL "PhysX CXX") ELSEIF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") - SET(PHYSX_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fno-rtti -fno-exceptions -ffunction-sections -fdata-sections -fno-strict-aliasing ${GCC_WARNINGS}" CACHE INTERAL "PhysX CXX") + SET(PHYSX_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fno-rtti -fno-exceptions -ffunction-sections -fdata-sections -fno-strict-aliasing ${GCC_WARNINGS}" CACHE INTERNAL "PhysX CXX") ENDIF() # Build debug info for all configurations @@ -70,27 +70,27 @@ SET(PHYSX_LINUX_RELEASE_COMPILE_DEFS "NDEBUG;PX_SUPPORT_PVD=0" CACHE INTERNAL "R # Include all of the projects IF(PX_GENERATE_GPU_PROJECTS_ONLY) - INCLUDE(PhysXCommon.cmake) - INCLUDE(PhysXFoundation.cmake) + INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/PhysXCommon.cmake) + INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/PhysXFoundation.cmake) SET_PROPERTY(TARGET PhysXCommon PROPERTY FOLDER "PhysX SDK") SET_PROPERTY(TARGET PhysXFoundation PROPERTY FOLDER "PhysX SDK") ELSE() - INCLUDE(PhysXFoundation.cmake) - INCLUDE(LowLevel.cmake) - INCLUDE(LowLevelAABB.cmake) - INCLUDE(LowLevelDynamics.cmake) - INCLUDE(PhysX.cmake) - INCLUDE(PhysXCharacterKinematic.cmake) - INCLUDE(PhysXCommon.cmake) - INCLUDE(PhysXCooking.cmake) - INCLUDE(PhysXExtensions.cmake) - INCLUDE(PhysXVehicle.cmake) - INCLUDE(SceneQuery.cmake) - INCLUDE(SimulationController.cmake) - INCLUDE(FastXml.cmake) - INCLUDE(PhysXPvdSDK.cmake) - INCLUDE(PhysXTask.cmake) + INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/PhysXFoundation.cmake) + INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/LowLevel.cmake) + INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/LowLevelAABB.cmake) + INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/LowLevelDynamics.cmake) + INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/PhysX.cmake) + INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/PhysXCharacterKinematic.cmake) + INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/PhysXCommon.cmake) + INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/PhysXCooking.cmake) + INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/PhysXExtensions.cmake) + INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/PhysXVehicle.cmake) + INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/SceneQuery.cmake) + INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/SimulationController.cmake) + INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/FastXml.cmake) + INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/PhysXPvdSDK.cmake) + INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/PhysXTask.cmake) # Set folder PhysX SDK to all common SDK source projects SET_PROPERTY(TARGET PhysX PROPERTY FOLDER "PhysX SDK") @@ -113,8 +113,14 @@ ELSE() INSTALL( TARGETS ${PHYSXDISTRO_LIBS} - EXPORT PhysXSDK + EXPORT PhysX DESTINATION $<$:${PX_ROOT_LIB_DIR}/debug>$<$:${PX_ROOT_LIB_DIR}/release>$<$:${PX_ROOT_LIB_DIR}/checked>$<$:${PX_ROOT_LIB_DIR}/profile> ) + if(DEFINED physx_build_targets_file) + # export to the build tree + export( TARGETS ${PHYSXDISTRO_LIBS} + NAMESPACE PhysX:: + FILE ${physx_build_targets_file}) + endif() ENDIF() diff --git a/physx/source/compiler/cmake/linux/PhysX.cmake b/physx/source/compiler/cmake/linux/PhysX.cmake index 48a4e53a7..4c3d71ba9 100644 --- a/physx/source/compiler/cmake/linux/PhysX.cmake +++ b/physx/source/compiler/cmake/linux/PhysX.cmake @@ -61,8 +61,8 @@ SET(PHYSX_PLATFORM_SRC_FILES ${PHYSX_PLATFORM_OBJECT_FILES} ) -INSTALL(FILES ${PHYSX_GPU_HEADERS} DESTINATION include/gpu) -INSTALL(FILES ${PHYSX_CUDACONTEXT_MANAGER_GPU_HEADERS} DESTINATION include/cudamanager) +INSTALL(FILES ${PHYSX_GPU_HEADERS} DESTINATION ${PHYSX_INSTALL_PREFIX}/include/gpu) +INSTALL(FILES ${PHYSX_CUDACONTEXT_MANAGER_GPU_HEADERS} DESTINATION ${PHYSX_INSTALL_PREFIX}/include/cudamanager) IF(PX_GENERATE_STATIC_LIBRARIES) SET(PHYSX_LIBTYPE STATIC) @@ -87,7 +87,7 @@ IF(NV_USE_GAMEWORKS_OUTPUT_DIRS) ELSE() SET(BITNESS_STRING "32") ENDIF() - SET(PHYSX_GPU_SHARED_LIB_NAME_DEF PX_PHYSX_GPU_SHARED_LIB_NAME=libPhysXGpu_${BITNESS_STRING}.so) + SET(PX_PHYSX_GPU_SHARED_LIB_NAME libPhysXGpu_${BITNESS_STRING}.so) ELSE() SET(CONFIG_STRING $<$:DEBUG>$<$:CHECKED>$<$:PROFILE>) IF(CMAKE_SIZEOF_VOID_P EQUAL 8) @@ -95,8 +95,9 @@ ELSE() ELSE() SET(BITNESS_STRING "x86") ENDIF() - SET(PHYSX_GPU_SHARED_LIB_NAME_DEF PX_PHYSX_GPU_SHARED_LIB_NAME=libPhysXGpu${CONFIG_STRING}_${BITNESS_STRING}.so) + SET(PX_PHYSX_GPU_SHARED_LIB_NAME libPhysXGpu${CONFIG_STRING}_${BITNESS_STRING}.so) ENDIF() +SET(PHYSX_GPU_SHARED_LIB_NAME_DEF PX_PHYSX_GPU_SHARED_LIB_NAME=${PX_PHYSX_GPU_SHARED_LIB_NAME}) SET(PHYSX_COMPILE_DEFS # Common to all configurations diff --git a/physx/source/compiler/cmake/linux/PhysXCharacterKinematic.cmake b/physx/source/compiler/cmake/linux/PhysXCharacterKinematic.cmake index acde32c9d..55191cebe 100644 --- a/physx/source/compiler/cmake/linux/PhysXCharacterKinematic.cmake +++ b/physx/source/compiler/cmake/linux/PhysXCharacterKinematic.cmake @@ -41,7 +41,7 @@ SET(PHYSXCHARACTERKINEMATICS_COMPILE_DEFS $<$:${PHYSX_LINUX_RELEASE_COMPILE_DEFS};> ) -SET(PHYSXCHARACTERKINEMATIC_LIBTYPE STATIC) +SET(PHYSXCHARACTERKINEMATIC_LIBTYPE STATIC) # enable -fPIC so we can link static libs with the editor diff --git a/physx/source/compiler/cmake/linux/PhysXExtensions.cmake b/physx/source/compiler/cmake/linux/PhysXExtensions.cmake index 9ab26651f..3d3be0ffc 100644 --- a/physx/source/compiler/cmake/linux/PhysXExtensions.cmake +++ b/physx/source/compiler/cmake/linux/PhysXExtensions.cmake @@ -45,7 +45,7 @@ SET(PHYSXEXTENSIONS_PLATFORM_SRC_FILES SET(PHYSXEXTENSIONS_COMPILE_DEFS # Common to all configurations - ${PHYSX_LINUX_COMPILE_DEFS};PX_PHYSX_STATIC_LIB; + ${PHYSX_LINUX_COMPILE_DEFS};${PXCOMMON_LIBTYPE_DEFS}; $<$:${PHYSX_LINUX_DEBUG_COMPILE_DEFS};> $<$:${PHYSX_LINUX_CHECKED_COMPILE_DEFS};> @@ -53,4 +53,4 @@ SET(PHYSXEXTENSIONS_COMPILE_DEFS $<$:${PHYSX_LINUX_RELEASE_COMPILE_DEFS};> ) -SET(PHYSXEXTENSIONS_LIBTYPE STATIC) \ No newline at end of file +SET(PHYSXEXTENSIONS_LIBTYPE STATIC) diff --git a/physx/source/compiler/cmake/linux/PhysXFoundation.cmake b/physx/source/compiler/cmake/linux/PhysXFoundation.cmake index ad7dc776f..0ef022540 100644 --- a/physx/source/compiler/cmake/linux/PhysXFoundation.cmake +++ b/physx/source/compiler/cmake/linux/PhysXFoundation.cmake @@ -81,9 +81,9 @@ SET(PHYSXFOUNDATION_PLATFORM_SOURCE_HEADERS ) SOURCE_GROUP("src\\include\\unix" FILES ${PHYSXFOUNDATION_PLATFORM_SOURCE_HEADERS}) -INSTALL(FILES ${PHYSXFOUNDATION_PLATFORM_SOURCE_HEADERS} DESTINATION source/foundation/include/unix) -INSTALL(FILES ${PHYSXFOUNDATION_NEON_FILES} DESTINATION source/foundation/include/unix/neon) -INSTALL(FILES ${PHYSXFOUNDATION_SSE2_FILES} DESTINATION source/foundation/include/unix/sse2) +INSTALL(FILES ${PHYSXFOUNDATION_PLATFORM_SOURCE_HEADERS} DESTINATION ${PHYSX_INSTALL_PREFIX}/source/foundation/include/unix) +INSTALL(FILES ${PHYSXFOUNDATION_NEON_FILES} DESTINATION ${PHYSX_INSTALL_PREFIX}/source/foundation/include/unix/neon) +INSTALL(FILES ${PHYSXFOUNDATION_SSE2_FILES} DESTINATION ${PHYSX_INSTALL_PREFIX}/source/foundation/include/unix/sse2) INSTALL(FILES ${PXSHARED_PLATFORM_HEADERS} DESTINATION ${PXSHARED_INSTALL_PREFIX}/include/foundation/unix) SET(PHYSXFOUNDATION_PLATFORM_FILES diff --git a/physx/source/compiler/cmake/linux/PhysXPvdSDK.cmake b/physx/source/compiler/cmake/linux/PhysXPvdSDK.cmake index d59d11995..57d5f6280 100644 --- a/physx/source/compiler/cmake/linux/PhysXPvdSDK.cmake +++ b/physx/source/compiler/cmake/linux/PhysXPvdSDK.cmake @@ -34,7 +34,7 @@ SET(PHYSXPVDSDK_LIBTYPE STATIC) # Use generator expressions to set config specific preprocessor definitions SET(PHYSXPVDSDK_COMPILE_DEFS # Common to all configurations - ${PHYSX_LINUX_COMPILE_DEFS};PX_PHYSX_STATIC_LIB; + ${PHYSX_LINUX_COMPILE_DEFS};${PXCOMMON_LIBTYPE_DEFS}; $<$:${PHYSX_LINUX_DEBUG_COMPILE_DEFS};> $<$:${PHYSX_LINUX_CHECKED_COMPILE_DEFS};> diff --git a/physx/source/compiler/cmake/linux/PhysXVehicle.cmake b/physx/source/compiler/cmake/linux/PhysXVehicle.cmake index 9b0745f97..5715d45f0 100644 --- a/physx/source/compiler/cmake/linux/PhysXVehicle.cmake +++ b/physx/source/compiler/cmake/linux/PhysXVehicle.cmake @@ -33,7 +33,7 @@ SET(PHYSXVEHICLE_COMPILE_DEFS # Common to all configurations - ${PHYSX_LINUX_COMPILE_DEFS};PX_PHYSX_STATIC_LIB + ${PHYSX_LINUX_COMPILE_DEFS};${PXCOMMON_LIBTYPE_DEFS}; $<$:${PHYSX_LINUX_DEBUG_COMPILE_DEFS};> $<$:${PHYSX_LINUX_CHECKED_COMPILE_DEFS};> diff --git a/physx/source/compiler/cmake/mac/CMakeLists.txt b/physx/source/compiler/cmake/mac/CMakeLists.txt index a5c6dedc9..ba87ae9c0 100644 --- a/physx/source/compiler/cmake/mac/CMakeLists.txt +++ b/physx/source/compiler/cmake/mac/CMakeLists.txt @@ -65,21 +65,21 @@ SET(PHYSX_MAC_RELEASE_COMPILE_DEFS "NDEBUG;PX_SUPPORT_PVD=0" CACHE INTERNAL "Rel # Include all of the projects -INCLUDE(PhysXFoundation.cmake) -INCLUDE(LowLevel.cmake) -INCLUDE(LowLevelAABB.cmake) -INCLUDE(LowLevelDynamics.cmake) -INCLUDE(PhysX.cmake) -INCLUDE(PhysXCharacterKinematic.cmake) -INCLUDE(PhysXCommon.cmake) -INCLUDE(PhysXCooking.cmake) -INCLUDE(PhysXExtensions.cmake) -INCLUDE(PhysXVehicle.cmake) -INCLUDE(PhysXPvdSDK.cmake) -INCLUDE(PhysXTask.cmake) -INCLUDE(SceneQuery.cmake) -INCLUDE(SimulationController.cmake) -INCLUDE(FastXml.cmake) +INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/PhysXFoundation.cmake) +INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/LowLevel.cmake) +INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/LowLevelAABB.cmake) +INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/LowLevelDynamics.cmake) +INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/PhysX.cmake) +INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/PhysXCharacterKinematic.cmake) +INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/PhysXCommon.cmake) +INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/PhysXCooking.cmake) +INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/PhysXExtensions.cmake) +INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/PhysXVehicle.cmake) +INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/PhysXPvdSDK.cmake) +INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/PhysXTask.cmake) +INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/SceneQuery.cmake) +INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/SimulationController.cmake) +INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/FastXml.cmake) # Set folder PhysX SDK to all common SDK source projects SET_PROPERTY(TARGET PhysX PROPERTY FOLDER "PhysX SDK") @@ -97,3 +97,21 @@ SET_PROPERTY(TARGET FastXml PROPERTY FOLDER "PhysX SDK") SET_PROPERTY(TARGET PhysXPvdSDK PROPERTY FOLDER "PhysX SDK") SET_PROPERTY(TARGET PhysXTask PROPERTY FOLDER "PhysX SDK") SET_PROPERTY(TARGET PhysXFoundation PROPERTY FOLDER "PhysX SDK") + +IF(PX_GENERATE_STATIC_LIBRARIES) + SET(PHYSXDISTRO_LIBS PhysXFoundation PhysX PhysXCharacterKinematic PhysXPvdSDK PhysXCommon PhysXCooking PhysXExtensions PhysXVehicle) +ELSE() + SET(PHYSXDISTRO_LIBS PhysXFoundation PhysX PhysXCharacterKinematic PhysXPvdSDK PhysXCommon PhysXCooking PhysXExtensions PhysXVehicle PhysXTask) +ENDIF() + +INSTALL( + TARGETS ${PHYSXDISTRO_LIBS} + EXPORT PhysX + DESTINATION $<$:${PX_ROOT_LIB_DIR}/debug>$<$:${PX_ROOT_LIB_DIR}/release>$<$:${PX_ROOT_LIB_DIR}/checked>$<$:${PX_ROOT_LIB_DIR}/profile> + ) +if(DEFINED physx_build_targets_file) + # export to the build tree + export( TARGETS ${PHYSXDISTRO_LIBS} + NAMESPACE PhysX:: + FILE ${physx_build_targets_file}) +endif() diff --git a/physx/source/compiler/cmake/mac/PhysXCharacterKinematic.cmake b/physx/source/compiler/cmake/mac/PhysXCharacterKinematic.cmake index bf25b0cb9..c9ba1b9b2 100644 --- a/physx/source/compiler/cmake/mac/PhysXCharacterKinematic.cmake +++ b/physx/source/compiler/cmake/mac/PhysXCharacterKinematic.cmake @@ -40,4 +40,4 @@ SET(PHYSXCHARACTERKINEMATICS_COMPILE_DEFS $<$:${PHYSX_MAC_RELEASE_COMPILE_DEFS};> ) -SET(PHYSXCHARACTERKINEMATIC_LIBTYPE STATIC) +SET(PHYSXCHARACTERKINEMATIC_LIBTYPE STATIC) diff --git a/physx/source/compiler/cmake/mac/PhysXExtensions.cmake b/physx/source/compiler/cmake/mac/PhysXExtensions.cmake index bbf7e5159..89559c63b 100644 --- a/physx/source/compiler/cmake/mac/PhysXExtensions.cmake +++ b/physx/source/compiler/cmake/mac/PhysXExtensions.cmake @@ -46,7 +46,7 @@ SET(PHYSXEXTENSIONS_PLATFORM_SRC_FILES SET(PHYSXEXTENSIONS_COMPILE_DEFS # Common to all configurations - ${PHYSX_MAC_COMPILE_DEFS};PX_PHYSX_STATIC_LIB; + ${PHYSX_MAC_COMPILE_DEFS};${PXCOMMON_LIBTYPE_DEFS}; $<$:${PHYSX_MAC_DEBUG_COMPILE_DEFS};> $<$:${PHYSX_MAC_CHECKED_COMPILE_DEFS};> @@ -54,4 +54,8 @@ SET(PHYSXEXTENSIONS_COMPILE_DEFS $<$:${PHYSX_MAC_RELEASE_COMPILE_DEFS};> ) -SET(PHYSXEXTENSIONS_LIBTYPE STATIC) +IF(PX_GENERATE_STATIC_LIBRARIES) + SET(PHYSXEXTENSIONS_LIBTYPE STATIC) +ELSE() + SET(PHYSXEXTENSIONS_LIBTYPE SHARED) +ENDIF() diff --git a/physx/source/compiler/cmake/mac/PhysXFoundation.cmake b/physx/source/compiler/cmake/mac/PhysXFoundation.cmake index bdaae87a3..0974ec8fd 100644 --- a/physx/source/compiler/cmake/mac/PhysXFoundation.cmake +++ b/physx/source/compiler/cmake/mac/PhysXFoundation.cmake @@ -77,9 +77,9 @@ SET(PHYSXFOUNDATION_PLATFORM_SOURCE_HEADERS ) SOURCE_GROUP("src\\include\\unix" FILES ${PHYSXFOUNDATION_PLATFORM_SOURCE_HEADERS}) -INSTALL(FILES ${PHYSXFOUNDATION_PLATFORM_SOURCE_HEADERS} DESTINATION source/foundation/include/unix) -INSTALL(FILES ${PHYSXFOUNDATION_NEON_FILES} DESTINATION source/foundation/include/unix/neon) -INSTALL(FILES ${PHYSXFOUNDATION_SSE2_FILES} DESTINATION source/foundation/include/unix/sse2) +INSTALL(FILES ${PHYSXFOUNDATION_PLATFORM_SOURCE_HEADERS} DESTINATION ${PHYSX_INSTALL_PREFIX}/source/foundation/include/unix) +INSTALL(FILES ${PHYSXFOUNDATION_NEON_FILES} DESTINATION ${PHYSX_INSTALL_PREFIX}/source/foundation/include/unix/neon) +INSTALL(FILES ${PHYSXFOUNDATION_SSE2_FILES} DESTINATION ${PHYSX_INSTALL_PREFIX}/source/foundation/include/unix/sse2) INSTALL(FILES ${PXSHARED_PLATFORM_HEADERS} DESTINATION ${PXSHARED_INSTALL_PREFIX}/include/foundation/unix) SET(PHYSXFOUNDATION_PLATFORM_FILES diff --git a/physx/source/compiler/cmake/mac/PhysXVehicle.cmake b/physx/source/compiler/cmake/mac/PhysXVehicle.cmake index 2e4d10cf3..3e873c80b 100644 --- a/physx/source/compiler/cmake/mac/PhysXVehicle.cmake +++ b/physx/source/compiler/cmake/mac/PhysXVehicle.cmake @@ -33,7 +33,7 @@ SET(PHYSXVEHICLE_COMPILE_DEFS # Common to all configurations - ${PHYSX_MAC_COMPILE_DEFS};PX_PHYSX_STATIC_LIB + ${PHYSX_MAC_COMPILE_DEFS};${PXCOMMON_LIBTYPE_DEFS}; $<$:${PHYSX_MAC_DEBUG_COMPILE_DEFS};> $<$:${PHYSX_MAC_CHECKED_COMPILE_DEFS};> diff --git a/physx/source/compiler/cmake/uwp/CMakeLists.txt b/physx/source/compiler/cmake/uwp/CMakeLists.txt index 2abab31f9..70fafe7de 100644 --- a/physx/source/compiler/cmake/uwp/CMakeLists.txt +++ b/physx/source/compiler/cmake/uwp/CMakeLists.txt @@ -80,21 +80,21 @@ SET(PHYSX_UWP_PROFILE_COMPILE_DEFS "PX_PROFILE=1;${NVTX_FLAG};PX_SUPPORT_PVD=1" SET(PHYSX_UWP_RELEASE_COMPILE_DEFS "PX_SUPPORT_PVD=0" CACHE INTERNAL "Release PhysX preprocessor definitions") # Include all of the projects -INCLUDE(PhysXFoundation.cmake) -INCLUDE(LowLevel.cmake) -INCLUDE(LowLevelAABB.cmake) -INCLUDE(LowLevelDynamics.cmake) -INCLUDE(PhysX.cmake) -INCLUDE(PhysXCharacterKinematic.cmake) -INCLUDE(PhysXCommon.cmake) -INCLUDE(PhysXCooking.cmake) -INCLUDE(PhysXExtensions.cmake) -INCLUDE(PhysXVehicle.cmake) -INCLUDE(PhysXPvdSDK.cmake) -INCLUDE(PhysXTask.cmake) -INCLUDE(SceneQuery.cmake) -INCLUDE(SimulationController.cmake) -INCLUDE(FastXml.cmake) +INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/PhysXFoundation.cmake) +INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/LowLevel.cmake) +INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/LowLevelAABB.cmake) +INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/LowLevelDynamics.cmake) +INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/PhysX.cmake) +INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/PhysXCharacterKinematic.cmake) +INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/PhysXCommon.cmake) +INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/PhysXCooking.cmake) +INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/PhysXExtensions.cmake) +INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/PhysXVehicle.cmake) +INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/PhysXPvdSDK.cmake) +INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/PhysXTask.cmake) +INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/SceneQuery.cmake) +INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/SimulationController.cmake) +INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/FastXml.cmake) # Set folder PhysX SDK to all common SDK source projects SET_PROPERTY(TARGET PhysX PROPERTY FOLDER "PhysX SDK") @@ -117,9 +117,15 @@ SET(PHYSXDISTRO_LIBS PhysXFoundation PhysX PhysXCharacterKinematic PhysXPvdSDK P INSTALL( TARGETS ${PHYSXDISTRO_LIBS} - EXPORT PhysXSDK + EXPORT PhysX DESTINATION $<$:${PX_ROOT_LIB_DIR}/debug>$<$:${PX_ROOT_LIB_DIR}/release>$<$:${PX_ROOT_LIB_DIR}/checked>$<$:${PX_ROOT_LIB_DIR}/profile> ) +if(DEFINED physx_build_targets_file) + # export to the build tree + export( TARGETS ${PHYSXDISTRO_LIBS} + NAMESPACE PhysX:: + FILE ${physx_build_targets_file}) +endif() IF(PX_GENERATE_STATIC_LIBRARIES) STRING(APPEND HEADER_CONTENT "#define PX_PHYSX_STATIC_LIB\n") diff --git a/physx/source/compiler/cmake/uwp/PhysXFoundation.cmake b/physx/source/compiler/cmake/uwp/PhysXFoundation.cmake index a81f8187c..b07736701 100644 --- a/physx/source/compiler/cmake/uwp/PhysXFoundation.cmake +++ b/physx/source/compiler/cmake/uwp/PhysXFoundation.cmake @@ -87,9 +87,9 @@ SET(PHYSXFOUNDATION_PLATFORM_SOURCE_HEADERS_3 ) SOURCE_GROUP("src\\include\\unix\\neon" FILES ${PHYSXFOUNDATION_PLATFORM_SOURCE_HEADERS_3}) -INSTALL(FILES ${PHYSXFOUNDATION_PLATFORM_SOURCE_HEADERS} DESTINATION source/foundation/include/windows) -INSTALL(FILES ${PHYSXFOUNDATION_PLATFORM_SOURCE_HEADERS_2} DESTINATION source/foundation/include/unix) -INSTALL(FILES ${PHYSXFOUNDATION_PLATFORM_SOURCE_HEADERS_3} DESTINATION source/foundation/include/unix/neon) +INSTALL(FILES ${PHYSXFOUNDATION_PLATFORM_SOURCE_HEADERS} DESTINATION ${PHYSX_INSTALL_PREFIX}/source/foundation/include/windows) +INSTALL(FILES ${PHYSXFOUNDATION_PLATFORM_SOURCE_HEADERS_2} DESTINATION ${PHYSX_INSTALL_PREFIX}/source/foundation/include/unix) +INSTALL(FILES ${PHYSXFOUNDATION_PLATFORM_SOURCE_HEADERS_3} DESTINATION ${PHYSX_INSTALL_PREFIX}/source/foundation/include/unix/neon) INSTALL(FILES ${PXSHARED_PLATFORM_HEADERS} DESTINATION ${PXSHARED_INSTALL_PREFIX}/include/foundation/windows) SET(PHYSXFOUNDATION_PLATFORM_FILES @@ -133,4 +133,4 @@ ELSE() DESTINATION $<$:${PX_ROOT_LIB_DIR}/debug>$<$:${PX_ROOT_LIB_DIR}/release>$<$:${PX_ROOT_LIB_DIR}/checked>$<$:${PX_ROOT_LIB_DIR}/profile> OPTIONAL) ENDIF() -SET(PLATFORM_COMPILE_FLAGS "/ZW") \ No newline at end of file +SET(PLATFORM_COMPILE_FLAGS "/ZW") diff --git a/physx/source/compiler/cmake/windows/CMakeLists.txt b/physx/source/compiler/cmake/windows/CMakeLists.txt index c772333b0..ad85c5bb6 100644 --- a/physx/source/compiler/cmake/windows/CMakeLists.txt +++ b/physx/source/compiler/cmake/windows/CMakeLists.txt @@ -145,27 +145,27 @@ ENDIF() # Include all of the projects IF(PX_GENERATE_GPU_PROJECTS_ONLY) - INCLUDE(PhysXFoundation.cmake) - INCLUDE(PhysXCommon.cmake) + INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/PhysXFoundation.cmake) + INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/PhysXCommon.cmake) SET_PROPERTY(TARGET PhysXFoundation PROPERTY FOLDER "PhysX SDK") SET_PROPERTY(TARGET PhysXCommon PROPERTY FOLDER "PhysX SDK") ELSE() - INCLUDE(PhysXFoundation.cmake) - INCLUDE(LowLevel.cmake) - INCLUDE(LowLevelAABB.cmake) - INCLUDE(LowLevelDynamics.cmake) - INCLUDE(PhysX.cmake) - INCLUDE(PhysXCharacterKinematic.cmake) - INCLUDE(PhysXCommon.cmake) - INCLUDE(PhysXCooking.cmake) - INCLUDE(PhysXExtensions.cmake) - INCLUDE(PhysXVehicle.cmake) - INCLUDE(SceneQuery.cmake) - INCLUDE(SimulationController.cmake) - INCLUDE(FastXml.cmake) - INCLUDE(PhysXPvdSDK.cmake) - INCLUDE(PhysXTask.cmake) + INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/PhysXFoundation.cmake) + INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/LowLevel.cmake) + INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/LowLevelAABB.cmake) + INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/LowLevelDynamics.cmake) + INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/PhysX.cmake) + INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/PhysXCharacterKinematic.cmake) + INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/PhysXCommon.cmake) + INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/PhysXCooking.cmake) + INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/PhysXExtensions.cmake) + INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/PhysXVehicle.cmake) + INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/SceneQuery.cmake) + INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/SimulationController.cmake) + INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/FastXml.cmake) + INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/PhysXPvdSDK.cmake) + INCLUDE(${PHYSX_ROOT_DIR}/${PROJECT_CMAKE_FILES_DIR}/PhysXTask.cmake) # Set folder PhysX SDK to all common SDK source projects SET_PROPERTY(TARGET PhysX PROPERTY FOLDER "PhysX SDK") @@ -192,12 +192,17 @@ ELSE() INSTALL( TARGETS ${PHYSXDISTRO_LIBS} - EXPORT PhysXSDK + EXPORT PhysX DESTINATION $<$:${PX_ROOT_LIB_DIR}/debug>$<$:${PX_ROOT_LIB_DIR}/release>$<$:${PX_ROOT_LIB_DIR}/checked>$<$:${PX_ROOT_LIB_DIR}/profile> ) - + if(DEFINED physx_build_targets_file) + # export to the build tree + export( TARGETS ${PHYSXDISTRO_LIBS} + NAMESPACE PhysX:: + FILE ${physx_build_targets_file}) + endif() ENDIF() IF(PX_GENERATE_STATIC_LIBRARIES) STRING(APPEND HEADER_CONTENT "#define PX_PHYSX_STATIC_LIB\n") -ENDIF() \ No newline at end of file +ENDIF() diff --git a/physx/source/compiler/cmake/windows/PhysX.cmake b/physx/source/compiler/cmake/windows/PhysX.cmake index 6abd6f391..761228d73 100644 --- a/physx/source/compiler/cmake/windows/PhysX.cmake +++ b/physx/source/compiler/cmake/windows/PhysX.cmake @@ -104,18 +104,19 @@ SET(PHYSX_PLATFORM_SRC_FILES ${PHYSX_PLATFORM_OBJECT_FILES} ) -INSTALL(FILES ${PHYSX_GPU_HEADERS} DESTINATION include/gpu) -INSTALL(FILES ${PHYSX_CUDACONTEXT_MANAGER_GPU_HEADERS} DESTINATION include/cudamanager) -INSTALL(FILES ${PHYSX_COMMON_WINDOWS_HEADERS} DESTINATION include/common/windows) +INSTALL(FILES ${PHYSX_GPU_HEADERS} DESTINATION ${PHYSX_INSTALL_PREFIX}/include/gpu) +INSTALL(FILES ${PHYSX_CUDACONTEXT_MANAGER_GPU_HEADERS} DESTINATION ${PHYSX_INSTALL_PREFIX}/include/cudamanager) +INSTALL(FILES ${PHYSX_COMMON_WINDOWS_HEADERS} DESTINATION ${PHYSX_INSTALL_PREFIX}/include/common/windows) IF(NV_USE_GAMEWORKS_OUTPUT_DIRS) SET(BITNESS_STRING $<$:64>$<$:32>) - SET(PHYSX_GPU_SHARED_LIB_NAME_DEF PX_PHYSX_GPU_SHARED_LIB_NAME=PhysXGpu_${BITNESS_STRING}.dll) + SET(PX_PHYSX_GPU_SHARED_LIB_NAME PhysXGpu_${BITNESS_STRING}.dll) ELSE() SET(CONFIG_STRING $<$:DEBUG>$<$:CHECKED>$<$:PROFILE>) SET(BITNESS_STRING $<$:x64>$<$:x86>) - SET(PHYSX_GPU_SHARED_LIB_NAME_DEF PX_PHYSX_GPU_SHARED_LIB_NAME=PhysXGpu${CONFIG_STRING}_${BITNESS_STRING}.dll) + SET(PX_PHYSX_GPU_SHARED_LIB_NAME PhysXGpu${CONFIG_STRING}_${BITNESS_STRING}.dll) ENDIF() +SET(PHYSX_GPU_SHARED_LIB_NAME_DEF PX_PHYSX_GPU_SHARED_LIB_NAME=${PX_PHYSX_GPU_SHARED_LIB_NAME}) IF(NOT PX_GENERATE_STATIC_LIBRARIES) SET(PXPHYSX_LIBTYPE_DEFS diff --git a/physx/source/compiler/cmake/windows/PhysXCharacterKinematic.cmake b/physx/source/compiler/cmake/windows/PhysXCharacterKinematic.cmake index 56b51f0aa..9dfed9853 100644 --- a/physx/source/compiler/cmake/windows/PhysXCharacterKinematic.cmake +++ b/physx/source/compiler/cmake/windows/PhysXCharacterKinematic.cmake @@ -29,7 +29,7 @@ # Build PhysXCharacterKinematic # -SET(PHYSXCHARACTERKINEMATIC_LIBTYPE STATIC) +SET(PHYSXCHARACTERKINEMATIC_LIBTYPE STATIC) # Use generator expressions to set config specific preprocessor definitions SET(PHYSXCHARACTERKINEMATICS_COMPILE_DEFS diff --git a/physx/source/compiler/cmake/windows/PhysXFoundation.cmake b/physx/source/compiler/cmake/windows/PhysXFoundation.cmake index a29b8bf24..c9906f3da 100644 --- a/physx/source/compiler/cmake/windows/PhysXFoundation.cmake +++ b/physx/source/compiler/cmake/windows/PhysXFoundation.cmake @@ -74,7 +74,7 @@ SET(PHYSXFOUNDATION_PLATFORM_SOURCE_HEADERS ) SOURCE_GROUP("src\\include\\windows" FILES ${PHYSXFOUNDATION_PLATFORM_SOURCE_HEADERS}) -INSTALL(FILES ${PHYSXFOUNDATION_PLATFORM_SOURCE_HEADERS} DESTINATION source/foundation/include/windows) +INSTALL(FILES ${PHYSXFOUNDATION_PLATFORM_SOURCE_HEADERS} DESTINATION ${PHYSX_INSTALL_PREFIX}/source/foundation/include/windows) INSTALL(FILES ${PXSHARED_PLATFORM_HEADERS} DESTINATION ${PXSHARED_INSTALL_PREFIX}/include/foundation/windows) INSTALL(FILES ${PXSHARED_UNIXPLATFORM_HEADERS} DESTINATION ${PXSHARED_INSTALL_PREFIX}/include/foundation/unix) @@ -117,4 +117,4 @@ IF(PHYSXFOUNDATION_LIBTYPE STREQUAL "SHARED") ELSE() INSTALL(FILES ${PHYSX_ROOT_DIR}/$<$:${PX_ROOT_LIB_DIR}/debug>$<$:${PX_ROOT_LIB_DIR}/release>$<$:${PX_ROOT_LIB_DIR}/checked>$<$:${PX_ROOT_LIB_DIR}/profile>/$<$:${PHYSXFOUNDATION_COMPILE_PDB_NAME_DEBUG}>$<$:${PHYSXFOUNDATION_COMPILE_PDB_NAME_CHECKED}>$<$:${PHYSXFOUNDATION_COMPILE_PDB_NAME_PROFILE}>$<$:${PHYSXFOUNDATION_COMPILE_PDB_NAME_RELEASE}>.pdb DESTINATION $<$:${PX_ROOT_LIB_DIR}/debug>$<$:${PX_ROOT_LIB_DIR}/release>$<$:${PX_ROOT_LIB_DIR}/checked>$<$:${PX_ROOT_LIB_DIR}/profile> OPTIONAL) -ENDIF() \ No newline at end of file +ENDIF() diff --git a/physx/source/compiler/cmake/windows/PhysXPvdSDK.cmake b/physx/source/compiler/cmake/windows/PhysXPvdSDK.cmake index 52e5b018c..e1a83a937 100644 --- a/physx/source/compiler/cmake/windows/PhysXPvdSDK.cmake +++ b/physx/source/compiler/cmake/windows/PhysXPvdSDK.cmake @@ -58,7 +58,7 @@ SET(PHYSXPVDSDK_PLATFORM_LINKED_LIBS ${NV_TOOLS_EXT_LIB}) # Use generator expressions to set config specific preprocessor definitions SET(PHYSXPVDSDK_COMPILE_DEFS # Common to all configurations - ${PHYSX_WINDOWS_COMPILE_DEFS};PX_PHYSX_STATIC_LIB;${PHYSX_LIBTYPE_DEFS};${PHYSXGPU_LIBTYPE_DEFS} + ${PHYSX_WINDOWS_COMPILE_DEFS};${PXCOMMON_LIBTYPE_DEFS};${PHYSX_LIBTYPE_DEFS};${PHYSXGPU_LIBTYPE_DEFS} $<$:${PHYSX_WINDOWS_DEBUG_COMPILE_DEFS};> $<$:${PHYSX_WINDOWS_CHECKED_COMPILE_DEFS};> diff --git a/physx/source/compiler/cmake/windows/PhysXVehicle.cmake b/physx/source/compiler/cmake/windows/PhysXVehicle.cmake index 8c0949222..89f137743 100644 --- a/physx/source/compiler/cmake/windows/PhysXVehicle.cmake +++ b/physx/source/compiler/cmake/windows/PhysXVehicle.cmake @@ -61,4 +61,4 @@ IF(PHYSXVEHICLE_LIBTYPE STREQUAL "SHARED") ELSE() INSTALL(FILES ${PHYSX_ROOT_DIR}/$<$:${PX_ROOT_LIB_DIR}/debug>$<$:${PX_ROOT_LIB_DIR}/release>$<$:${PX_ROOT_LIB_DIR}/checked>$<$:${PX_ROOT_LIB_DIR}/profile>/$<$:${PHYSXVEHICLE_COMPILE_PDB_NAME_DEBUG}>$<$:${PHYSXVEHICLE_COMPILE_PDB_NAME_CHECKED}>$<$:${PHYSXVEHICLE_COMPILE_PDB_NAME_PROFILE}>$<$:${PHYSXVEHICLE_COMPILE_PDB_NAME_RELEASE}>.pdb DESTINATION $<$:${PX_ROOT_LIB_DIR}/debug>$<$:${PX_ROOT_LIB_DIR}/release>$<$:${PX_ROOT_LIB_DIR}/checked>$<$:${PX_ROOT_LIB_DIR}/profile> OPTIONAL) -ENDIF() \ No newline at end of file +ENDIF() diff --git a/physx/source/foundation/include/PsAllocator.h b/physx/source/foundation/include/PsAllocator.h index 38b70fc35..6fa312cb4 100644 --- a/physx/source/foundation/include/PsAllocator.h +++ b/physx/source/foundation/include/PsAllocator.h @@ -35,12 +35,9 @@ #include "PxFoundation.h" #include "Ps.h" +#include #if(PX_WINDOWS_FAMILY || PX_XBOXONE) #include - #include -#endif -#if(PX_APPLE_FAMILY) - #include #endif #include diff --git a/project_using_physx/CMakeLists.txt b/project_using_physx/CMakeLists.txt new file mode 100644 index 000000000..a5a86dda7 --- /dev/null +++ b/project_using_physx/CMakeLists.txt @@ -0,0 +1,41 @@ +cmake_minimum_required(VERSION 3.13) +project(hello_physx) + +find_package(PhysX REQUIRED) + +add_executable(SnippetHelloWorld + ./source/SnippetUtils.cpp + ./source/ClassicMain.cpp + ./source/SnippetHelloWorld.cpp + ) +target_include_directories(SnippetHelloWorld PRIVATE ./include) +target_link_libraries(SnippetHelloWorld PRIVATE + PhysX::PhysXExtensions + PhysX::PhysXCommon) + + +# Render Example +find_package(OpenGL REQUIRED) +find_package(GLUT REQUIRED) + +add_library(SnippetCameraRender + ./source/SnippetCamera.cpp + ./source/SnippetRender.cpp + ) +target_include_directories(SnippetCameraRender PUBLIC ./include) +target_link_libraries(SnippetCameraRender PUBLIC + PhysX::PhysXExtensions + PhysX::PhysXCommon) +target_link_libraries(SnippetCameraRender PUBLIC + ${OPENGL_LIBRARIES} + ${GLUT_LIBRARY} + ) + +add_executable(SnippetHelloWorldRender + ./source/ClassicMain.cpp + ./source/SnippetHelloWorld.cpp + ./source/SnippetHelloWorldRender.cpp + ) +target_compile_definitions(SnippetHelloWorldRender PRIVATE RENDER_SNIPPET) +target_include_directories(SnippetHelloWorldRender PRIVATE ./include) +target_link_libraries(SnippetHelloWorldRender PRIVATE SnippetCameraRender) diff --git a/project_using_physx/include/SnippetCamera.h b/project_using_physx/include/SnippetCamera.h new file mode 100644 index 000000000..d33dc1471 --- /dev/null +++ b/project_using_physx/include/SnippetCamera.h @@ -0,0 +1,62 @@ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// * Neither the name of NVIDIA CORPORATION nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Copyright (c) 2008-2019 NVIDIA Corporation. All rights reserved. +// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved. +// Copyright (c) 2001-2004 NovodeX AG. All rights reserved. + + +#ifndef PHYSX_SNIPPET_CAMERA_H +#define PHYSX_SNIPPET_CAMERA_H + +#include "foundation/PxTransform.h" + +namespace Snippets +{ +class Camera +{ +public: + Camera(const physx::PxVec3 &eye, const physx::PxVec3& dir); + + void handleMouse(int button, int state, int x, int y); + bool handleKey(unsigned char key, int x, int y, float speed = 1.0f); + void handleMotion(int x, int y); + void handleAnalogMove(float x, float y); + + physx::PxVec3 getEye() const; + physx::PxVec3 getDir() const; + physx::PxTransform getTransform() const; +private: + physx::PxVec3 mEye; + physx::PxVec3 mDir; + int mMouseX; + int mMouseY; +}; + + +} + + +#endif //PHYSX_SNIPPET_CAMERA_H diff --git a/project_using_physx/include/SnippetPVD.h b/project_using_physx/include/SnippetPVD.h new file mode 100644 index 000000000..f49e92394 --- /dev/null +++ b/project_using_physx/include/SnippetPVD.h @@ -0,0 +1,36 @@ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// * Neither the name of NVIDIA CORPORATION nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Copyright (c) 2008-2019 NVIDIA Corporation. All rights reserved. +// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved. +// Copyright (c) 2001-2004 NovodeX AG. All rights reserved. + + +#ifndef PHYSX_SNIPPET_PVD_H +#define PHYSX_SNIPPET_PVD_H + +#define PVD_HOST "127.0.0.1" //Set this to the IP address of the system running the PhysX Visual Debugger that you want to connect to. + +#endif //PHYSX_SNIPPET_PVD_H diff --git a/project_using_physx/include/SnippetPrint.h b/project_using_physx/include/SnippetPrint.h new file mode 100644 index 000000000..6d7f6c086 --- /dev/null +++ b/project_using_physx/include/SnippetPrint.h @@ -0,0 +1,42 @@ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// * Neither the name of NVIDIA CORPORATION nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Copyright (c) 2008-2019 NVIDIA Corporation. All rights reserved. +// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved. +// Copyright (c) 2001-2004 NovodeX AG. All rights reserved. + +#ifndef PHYSX_SNIPPET_PRINT_H +#define PHYSX_SNIPPET_PRINT_H + +#include "foundation/PxPreprocessor.h" + +#if PX_XBOXONE +void OutputDebugPrint(const char*, ...); +#define printf OutputDebugPrint +#elif PX_SWITCH +#include "../SnippetCommon/Switch/SwitchSnippetPrint.h" +#endif + +#endif // PHYSX_SNIPPET_PRINT_H diff --git a/project_using_physx/include/SnippetRender.h b/project_using_physx/include/SnippetRender.h new file mode 100644 index 000000000..b9b1852d2 --- /dev/null +++ b/project_using_physx/include/SnippetRender.h @@ -0,0 +1,62 @@ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// * Neither the name of NVIDIA CORPORATION nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Copyright (c) 2008-2019 NVIDIA Corporation. All rights reserved. +// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved. +// Copyright (c) 2001-2004 NovodeX AG. All rights reserved. + + +#ifndef PHYSX_SNIPPET_RENDER_H +#define PHYSX_SNIPPET_RENDER_H + +#include "PxPhysicsAPI.h" +#include "foundation/PxPreprocessor.h" + +#if PX_WINDOWS + #include + #pragma warning(disable: 4505) + #include +#elif PX_LINUX_FAMILY + #include +#elif PX_OSX + #include +#else + #error platform not supported. +#endif + +namespace Snippets +{ + void setupDefaultWindow(const char* name); + void setupDefaultRenderState(); + + void startRender(const physx::PxVec3& cameraEye, const physx::PxVec3& cameraDir, physx::PxReal nearClip = 1.f, physx::PxReal farClip = 10000.f); + void finishRender(); + + void renderActors(physx::PxRigidActor** actors, const physx::PxU32 numActors, bool shadows = false, const physx::PxVec3& color = physx::PxVec3(0.0f, 0.75f, 0.0f)); +// void renderGeoms(const physx::PxU32 nbGeoms, const physx::PxGeometry* geoms, const physx::PxTransform* poses, bool shadows, const physx::PxVec3& color); + void renderGeoms(const physx::PxU32 nbGeoms, const physx::PxGeometryHolder* geoms, const physx::PxTransform* poses, bool shadows, const physx::PxVec3& color); +} + +#endif //PHYSX_SNIPPET_RENDER_H diff --git a/project_using_physx/include/SnippetUtils.h b/project_using_physx/include/SnippetUtils.h new file mode 100644 index 000000000..10a328b70 --- /dev/null +++ b/project_using_physx/include/SnippetUtils.h @@ -0,0 +1,127 @@ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// * Neither the name of NVIDIA CORPORATION nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Copyright (c) 2008-2019 NVIDIA Corporation. All rights reserved. + +#include "foundation/PxSimpleTypes.h" + +#define PX_RELEASE(x) if(x) { x->release(); x = NULL; } + +namespace physx +{ + namespace SnippetUtils + { + /* Increment the specified location. Return the incremented value. */ + PxI32 atomicIncrement(volatile PxI32* val); + + /* Decrement the specified location. Return the decremented value. */ + PxI32 atomicDecrement(volatile PxI32* val); + + //******************************************************************************// + + /* Return the number of physical cores (does not include hyper-threaded cores), returns 0 on failure. */ + PxU32 getNbPhysicalCores(); + + //******************************************************************************// + + /* Return the id of a thread. */ + PxU32 getThreadId(); + + //******************************************************************************// + + /* Return the current time */ + PxU64 getCurrentTimeCounterValue(); + + /* Convert to milliseconds an elapsed time computed from the difference of the times returned from two calls to getCurrentTimeCounterValue. */ + PxReal getElapsedTimeInMilliseconds(const PxU64 elapsedTime); + + /* Convert to microseconds an elapsed time computed from the difference of the times returned from two calls to getCurrentTimeCounterValue. */ + PxReal getElapsedTimeInMicroSeconds(const PxU64 elapsedTime); + + //******************************************************************************// + + struct Sync; + + /* Create a sync object. Returns a unique handle to the sync object so that it may be addressed through syncWait etc. */ + Sync* syncCreate(); + + /* Wait indefinitely until the specified sync object is signaled. */ + void syncWait(Sync* sync); + + /* Signal the specified synchronization object, waking all threads waiting on it. */ + void syncSet(Sync* sync); + + /** Reset the specified synchronization object. */ + void syncReset(Sync* sync); + + /* Release the specified sync object so that it may be reused with syncCreate. */ + void syncRelease(Sync* sync); + + //******************************************************************************// + + struct Thread; + + /* Prototype of callback passed to threadCreate. */ + typedef void (*ThreadEntryPoint)(void*); + + /* Create a thread object and return a unique handle to the thread object so that it may be addressed through threadStart etc. + entryPoint implements ThreadEntryPoint and data will be passed as a function argument, POSIX-style. */ + Thread* threadCreate(ThreadEntryPoint entryPoint, void* data); + + /* Cleanly shut down the specified thread. Called in the context of the spawned thread. */ + void threadQuit(Thread* thread); + + /* Stop the specified thread. Signals the spawned thread that it should stop, so the + thread should check regularly. */ + void threadSignalQuit(Thread* thread); + + /* Wait for the specified thread to stop. Should be called in the context of the spawning + thread. Returns false if the thread has not been started.*/ + bool threadWaitForQuit(Thread* thread); + + /* Check whether the thread is signalled to quit. Called in the context of the + spawned thread. */ + bool threadQuitIsSignalled(Thread* thread); + + /* Release the specified thread object so that it may be reused with threadCreate. */ + void threadRelease(Thread* thread); + + //******************************************************************************// + + struct Mutex; + + /* Create a mutex object and return a unique handle to the mutex object so that it may be addressed through mutexLock etc. */ + Mutex* mutexCreate(); + + /* Acquire (lock) the specified mutex. If the mutex is already locked by another thread, this method blocks until the mutex is unlocked.*/ + void mutexLock(Mutex* mutex); + + /* Release (unlock) the specified mutex, the calling thread must have previously called lock() or method will error. */ + void mutexUnlock(Mutex* mutex); + + /* Release the specified mutex so that it may be reused with mutexCreate. */ + void mutexRelease(Mutex* mutex); + } +} diff --git a/project_using_physx/source/ClassicMain.cpp b/project_using_physx/source/ClassicMain.cpp new file mode 100644 index 000000000..58e1befb5 --- /dev/null +++ b/project_using_physx/source/ClassicMain.cpp @@ -0,0 +1,35 @@ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// * Neither the name of NVIDIA CORPORATION nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Copyright (c) 2008-2019 NVIDIA Corporation. All rights reserved. +// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved. +// Copyright (c) 2001-2004 NovodeX AG. All rights reserved. + +extern int snippetMain(int, const char*const*); + +int main(int argc, char** argv) +{ + return snippetMain(argc, argv); +} diff --git a/project_using_physx/source/SnippetCamera.cpp b/project_using_physx/source/SnippetCamera.cpp new file mode 100644 index 000000000..3baacf4ef --- /dev/null +++ b/project_using_physx/source/SnippetCamera.cpp @@ -0,0 +1,122 @@ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// * Neither the name of NVIDIA CORPORATION nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Copyright (c) 2008-2019 NVIDIA Corporation. All rights reserved. +// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved. +// Copyright (c) 2001-2004 NovodeX AG. All rights reserved. + + + +#include "SnippetCamera.h" +#include +#include "foundation/PxMat33.h" + +using namespace physx; + +namespace Snippets +{ + +Camera::Camera(const PxVec3& eye, const PxVec3& dir) +{ + mEye = eye; + mDir = dir.getNormalized(); + mMouseX = 0; + mMouseY = 0; +} + +void Camera::handleMouse(int button, int state, int x, int y) +{ + PX_UNUSED(state); + PX_UNUSED(button); + mMouseX = x; + mMouseY = y; +} + +bool Camera::handleKey(unsigned char key, int x, int y, float speed) +{ + PX_UNUSED(x); + PX_UNUSED(y); + + PxVec3 viewY = mDir.cross(PxVec3(0,1,0)).getNormalized(); + switch(toupper(key)) + { + case 'W': mEye += mDir*2.0f*speed; break; + case 'S': mEye -= mDir*2.0f*speed; break; + case 'A': mEye -= viewY*2.0f*speed; break; + case 'D': mEye += viewY*2.0f*speed; break; + default: return false; + } + return true; +} + +void Camera::handleAnalogMove(float x, float y) +{ + PxVec3 viewY = mDir.cross(PxVec3(0,1,0)).getNormalized(); + mEye += mDir*y; + mEye += viewY*x; +} + +void Camera::handleMotion(int x, int y) +{ + int dx = mMouseX - x; + int dy = mMouseY - y; + + PxVec3 viewY = mDir.cross(PxVec3(0,1,0)).getNormalized(); + + PxQuat qx(PxPi * dx / 180.0f, PxVec3(0,1,0)); + mDir = qx.rotate(mDir); + PxQuat qy(PxPi * dy / 180.0f, viewY); + mDir = qy.rotate(mDir); + + mDir.normalize(); + + mMouseX = x; + mMouseY = y; +} + +PxTransform Camera::getTransform() const +{ + PxVec3 viewY = mDir.cross(PxVec3(0,1,0)); + + if(viewY.normalize()<1e-6f) + return PxTransform(mEye); + + PxMat33 m(mDir.cross(viewY), viewY, -mDir); + return PxTransform(mEye, PxQuat(m)); +} + +PxVec3 Camera::getEye() const +{ + return mEye; +} + +PxVec3 Camera::getDir() const +{ + return mDir; +} + + +} + diff --git a/project_using_physx/source/SnippetHelloWorld.cpp b/project_using_physx/source/SnippetHelloWorld.cpp new file mode 100644 index 000000000..3ac5f8c87 --- /dev/null +++ b/project_using_physx/source/SnippetHelloWorld.cpp @@ -0,0 +1,170 @@ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// * Neither the name of NVIDIA CORPORATION nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Copyright (c) 2008-2019 NVIDIA Corporation. All rights reserved. +// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved. +// Copyright (c) 2001-2004 NovodeX AG. All rights reserved. + +// **************************************************************************** +// This snippet illustrates simple use of physx +// +// It creates a number of box stacks on a plane, and if rendering, allows the +// user to create new stacks and fire a ball from the camera position +// **************************************************************************** + +#include + +#include "PxPhysicsAPI.h" + +#include "SnippetPrint.h" +#include "SnippetPVD.h" +#include "SnippetUtils.h" +// #define PX_RELEASE(x) if(x) { x->release(); x = NULL; } + +using namespace physx; + +PxDefaultAllocator gAllocator; +PxDefaultErrorCallback gErrorCallback; + +PxFoundation* gFoundation = NULL; +PxPhysics* gPhysics = NULL; + +PxDefaultCpuDispatcher* gDispatcher = NULL; +PxScene* gScene = NULL; + +PxMaterial* gMaterial = NULL; + +PxPvd* gPvd = NULL; + +PxReal stackZ = 10.0f; + +PxRigidDynamic* createDynamic(const PxTransform& t, const PxGeometry& geometry, const PxVec3& velocity=PxVec3(0)) +{ + PxRigidDynamic* dynamic = PxCreateDynamic(*gPhysics, t, geometry, *gMaterial, 10.0f); + dynamic->setAngularDamping(0.5f); + dynamic->setLinearVelocity(velocity); + gScene->addActor(*dynamic); + return dynamic; +} + +void createStack(const PxTransform& t, PxU32 size, PxReal halfExtent) +{ + PxShape* shape = gPhysics->createShape(PxBoxGeometry(halfExtent, halfExtent, halfExtent), *gMaterial); + for(PxU32 i=0; icreateRigidDynamic(t.transform(localTm)); + body->attachShape(*shape); + PxRigidBodyExt::updateMassAndInertia(*body, 10.0f); + gScene->addActor(*body); + } + } + shape->release(); +} + +void initPhysics(bool interactive) +{ + gFoundation = PxCreateFoundation(PX_PHYSICS_VERSION, gAllocator, gErrorCallback); + + gPvd = PxCreatePvd(*gFoundation); + PxPvdTransport* transport = PxDefaultPvdSocketTransportCreate(PVD_HOST, 5425, 10); + gPvd->connect(*transport,PxPvdInstrumentationFlag::eALL); + + gPhysics = PxCreatePhysics(PX_PHYSICS_VERSION, *gFoundation, PxTolerancesScale(),true,gPvd); + + PxSceneDesc sceneDesc(gPhysics->getTolerancesScale()); + sceneDesc.gravity = PxVec3(0.0f, -9.81f, 0.0f); + gDispatcher = PxDefaultCpuDispatcherCreate(2); + sceneDesc.cpuDispatcher = gDispatcher; + sceneDesc.filterShader = PxDefaultSimulationFilterShader; + gScene = gPhysics->createScene(sceneDesc); + + PxPvdSceneClient* pvdClient = gScene->getScenePvdClient(); + if(pvdClient) + { + pvdClient->setScenePvdFlag(PxPvdSceneFlag::eTRANSMIT_CONSTRAINTS, true); + pvdClient->setScenePvdFlag(PxPvdSceneFlag::eTRANSMIT_CONTACTS, true); + pvdClient->setScenePvdFlag(PxPvdSceneFlag::eTRANSMIT_SCENEQUERIES, true); + } + gMaterial = gPhysics->createMaterial(0.5f, 0.5f, 0.6f); + + PxRigidStatic* groundPlane = PxCreatePlane(*gPhysics, PxPlane(0,1,0,0), *gMaterial); + gScene->addActor(*groundPlane); + + for(PxU32 i=0;i<5;i++) + createStack(PxTransform(PxVec3(0,0,stackZ-=10.0f)), 10, 2.0f); + + if(!interactive) + createDynamic(PxTransform(PxVec3(0,40,100)), PxSphereGeometry(10), PxVec3(0,-50,-100)); +} + +void stepPhysics(bool /*interactive*/) +{ + gScene->simulate(1.0f/60.0f); + gScene->fetchResults(true); +} + +void cleanupPhysics(bool /*interactive*/) +{ + PX_RELEASE(gScene); + PX_RELEASE(gDispatcher); + PX_RELEASE(gPhysics); + if(gPvd) + { + PxPvdTransport* transport = gPvd->getTransport(); + gPvd->release(); gPvd = NULL; + PX_RELEASE(transport); + } + PX_RELEASE(gFoundation); + + printf("SnippetHelloWorld done.\n"); +} + +void keyPress(unsigned char key, const PxTransform& camera) +{ + switch(toupper(key)) + { + case 'B': createStack(PxTransform(PxVec3(0,0,stackZ-=10.0f)), 10, 2.0f); break; + case ' ': createDynamic(camera, PxSphereGeometry(3.0f), camera.rotate(PxVec3(0,0,-1))*200); break; + } +} + +int snippetMain(int, const char*const*) +{ +#ifdef RENDER_SNIPPET + extern void renderLoop(); + renderLoop(); +#else + static const PxU32 frameCount = 100; + initPhysics(false); + for(PxU32 i=0; i + +#include "PxPhysicsAPI.h" + +#include "SnippetRender.h" +#include "SnippetCamera.h" + +using namespace physx; + +extern void initPhysics(bool interactive); +extern void stepPhysics(bool interactive); +extern void cleanupPhysics(bool interactive); +extern void keyPress(unsigned char key, const PxTransform& camera); + + +namespace +{ +Snippets::Camera* sCamera; + +void motionCallback(int x, int y) +{ + sCamera->handleMotion(x, y); +} + +void keyboardCallback(unsigned char key, int x, int y) +{ + if(key==27) + exit(0); + + if(!sCamera->handleKey(key, x, y)) + keyPress(key, sCamera->getTransform()); +} + +void mouseCallback(int button, int state, int x, int y) +{ + sCamera->handleMouse(button, state, x, y); +} + +void idleCallback() +{ + glutPostRedisplay(); +} + +void renderCallback() +{ + stepPhysics(true); + + Snippets::startRender(sCamera->getEye(), sCamera->getDir()); + + PxScene* scene; + PxGetPhysics().getScenes(&scene,1); + PxU32 nbActors = scene->getNbActors(PxActorTypeFlag::eRIGID_DYNAMIC | PxActorTypeFlag::eRIGID_STATIC); + if(nbActors) + { + std::vector actors(nbActors); + scene->getActors(PxActorTypeFlag::eRIGID_DYNAMIC | PxActorTypeFlag::eRIGID_STATIC, reinterpret_cast(&actors[0]), nbActors); + Snippets::renderActors(&actors[0], static_cast(actors.size()), true); + } + + Snippets::finishRender(); +} + +void exitCallback(void) +{ + delete sCamera; + cleanupPhysics(true); +} +} + +void renderLoop() +{ + sCamera = new Snippets::Camera(PxVec3(50.0f, 50.0f, 50.0f), PxVec3(-0.6f,-0.2f,-0.7f)); + + Snippets::setupDefaultWindow("PhysX Snippet HelloWorld"); + Snippets::setupDefaultRenderState(); + + glutIdleFunc(idleCallback); + glutDisplayFunc(renderCallback); + glutKeyboardFunc(keyboardCallback); + glutMouseFunc(mouseCallback); + glutMotionFunc(motionCallback); + motionCallback(0,0); + + atexit(exitCallback); + + initPhysics(true); + glutMainLoop(); +} +#endif diff --git a/project_using_physx/source/SnippetRender.cpp b/project_using_physx/source/SnippetRender.cpp new file mode 100644 index 000000000..1abaa284b --- /dev/null +++ b/project_using_physx/source/SnippetRender.cpp @@ -0,0 +1,440 @@ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// * Neither the name of NVIDIA CORPORATION nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Copyright (c) 2008-2019 NVIDIA Corporation. All rights reserved. +// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved. +// Copyright (c) 2001-2004 NovodeX AG. All rights reserved. + +#include "SnippetRender.h" + +#define MAX_NUM_ACTOR_SHAPES 128 + +using namespace physx; + +static float gCylinderData[]={ + 1.0f,0.0f,1.0f,1.0f,0.0f,1.0f,1.0f,0.0f,0.0f,1.0f,0.0f,0.0f, + 0.866025f,0.500000f,1.0f,0.866025f,0.500000f,1.0f,0.866025f,0.500000f,0.0f,0.866025f,0.500000f,0.0f, + 0.500000f,0.866025f,1.0f,0.500000f,0.866025f,1.0f,0.500000f,0.866025f,0.0f,0.500000f,0.866025f,0.0f, + -0.0f,1.0f,1.0f,-0.0f,1.0f,1.0f,-0.0f,1.0f,0.0f,-0.0f,1.0f,0.0f, + -0.500000f,0.866025f,1.0f,-0.500000f,0.866025f,1.0f,-0.500000f,0.866025f,0.0f,-0.500000f,0.866025f,0.0f, + -0.866025f,0.500000f,1.0f,-0.866025f,0.500000f,1.0f,-0.866025f,0.500000f,0.0f,-0.866025f,0.500000f,0.0f, + -1.0f,-0.0f,1.0f,-1.0f,-0.0f,1.0f,-1.0f,-0.0f,0.0f,-1.0f,-0.0f,0.0f, + -0.866025f,-0.500000f,1.0f,-0.866025f,-0.500000f,1.0f,-0.866025f,-0.500000f,0.0f,-0.866025f,-0.500000f,0.0f, + -0.500000f,-0.866025f,1.0f,-0.500000f,-0.866025f,1.0f,-0.500000f,-0.866025f,0.0f,-0.500000f,-0.866025f,0.0f, + 0.0f,-1.0f,1.0f,0.0f,-1.0f,1.0f,0.0f,-1.0f,0.0f,0.0f,-1.0f,0.0f, + 0.500000f,-0.866025f,1.0f,0.500000f,-0.866025f,1.0f,0.500000f,-0.866025f,0.0f,0.500000f,-0.866025f,0.0f, + 0.866026f,-0.500000f,1.0f,0.866026f,-0.500000f,1.0f,0.866026f,-0.500000f,0.0f,0.866026f,-0.500000f,0.0f, + 1.0f,0.0f,1.0f,1.0f,0.0f,1.0f,1.0f,0.0f,0.0f,1.0f,0.0f,0.0f +}; + +#define MAX_NUM_MESH_VEC3S 1024 +static PxVec3 gVertexBuffer[MAX_NUM_MESH_VEC3S]; + +static void renderGeometry(const PxGeometry& geom) +{ + switch(geom.getType()) + { + case PxGeometryType::eBOX: + { + const PxBoxGeometry& boxGeom = static_cast(geom); + glScalef(boxGeom.halfExtents.x, boxGeom.halfExtents.y, boxGeom.halfExtents.z); + glutSolidCube(2); + } + break; + + case PxGeometryType::eSPHERE: + { + const PxSphereGeometry& sphereGeom = static_cast(geom); + glutSolidSphere(GLdouble(sphereGeom.radius), 10, 10); + } + break; + + case PxGeometryType::eCAPSULE: + { + const PxCapsuleGeometry& capsuleGeom = static_cast(geom); + const PxF32 radius = capsuleGeom.radius; + const PxF32 halfHeight = capsuleGeom.halfHeight; + + //Sphere + glPushMatrix(); + glTranslatef(halfHeight, 0.0f, 0.0f); + glScalef(radius,radius,radius); + glutSolidSphere(1, 10, 10); + glPopMatrix(); + + //Sphere + glPushMatrix(); + glTranslatef(-halfHeight, 0.0f, 0.0f); + glScalef(radius,radius,radius); + glutSolidSphere(1, 10, 10); + glPopMatrix(); + + //Cylinder + glPushMatrix(); + glTranslatef(-halfHeight, 0.0f, 0.0f); + glScalef(2.0f*halfHeight, radius,radius); + glRotatef(90.0f,0.0f,1.0f,0.0f); + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_NORMAL_ARRAY); + glVertexPointer(3, GL_FLOAT, 2*3*sizeof(float), gCylinderData); + glNormalPointer(GL_FLOAT, 2*3*sizeof(float), gCylinderData+3); + glDrawArrays(GL_TRIANGLE_STRIP, 0, 13*2); + glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_NORMAL_ARRAY); + glPopMatrix(); + } + break; + + case PxGeometryType::eCONVEXMESH: + { + const PxConvexMeshGeometry& convexGeom = static_cast(geom); + + //Compute triangles for each polygon. + const PxVec3& scale = convexGeom.scale.scale; + PxConvexMesh* mesh = convexGeom.convexMesh; + const PxU32 nbPolys = mesh->getNbPolygons(); + const PxU8* polygons = mesh->getIndexBuffer(); + const PxVec3* verts = mesh->getVertices(); + PxU32 nbVerts = mesh->getNbVertices(); + PX_UNUSED(nbVerts); + + PxU32 numTotalTriangles = 0; + for(PxU32 i = 0; i < nbPolys; i++) + { + PxHullPolygon data; + mesh->getPolygonData(i, data); + + const PxU32 nbTris = PxU32(data.mNbVerts - 2); + const PxU8 vref0 = polygons[data.mIndexBase + 0]; + PX_ASSERT(vref0 < nbVerts); + for(PxU32 j=0;j(geom); + + const PxTriangleMesh& mesh = *triGeom.triangleMesh; + const PxVec3 scale = triGeom.scale.scale; + + const PxU32 triangleCount = mesh.getNbTriangles(); + const PxU32 has16BitIndices = mesh.getTriangleMeshFlags() & PxTriangleMeshFlag::e16_BIT_INDICES; + const void* indexBuffer = mesh.getTriangles(); + + const PxVec3* vertexBuffer = mesh.getVertices(); + + const PxU32* intIndices = reinterpret_cast(indexBuffer); + const PxU16* shortIndices = reinterpret_cast(indexBuffer); + PxU32 numTotalTriangles = 0; + for(PxU32 i=0; i < triangleCount; ++i) + { + PxVec3 triVert[3]; + + if(has16BitIndices) + { + triVert[0] = vertexBuffer[*shortIndices++]; + triVert[1] = vertexBuffer[*shortIndices++]; + triVert[2] = vertexBuffer[*shortIndices++]; + } + else + { + triVert[0] = vertexBuffer[*intIndices++]; + triVert[1] = vertexBuffer[*intIndices++]; + triVert[2] = vertexBuffer[*intIndices++]; + } + + PxVec3 fnormal = (triVert[1] - triVert[0]).cross(triVert[2] - triVert[0]); + fnormal.normalize(); + + if(numTotalTriangles*6 < MAX_NUM_MESH_VEC3S) + { + gVertexBuffer[numTotalTriangles*6 + 0] = fnormal; + gVertexBuffer[numTotalTriangles*6 + 1] = triVert[0]; + gVertexBuffer[numTotalTriangles*6 + 2] = fnormal; + gVertexBuffer[numTotalTriangles*6 + 3] = triVert[1]; + gVertexBuffer[numTotalTriangles*6 + 4] = fnormal; + gVertexBuffer[numTotalTriangles*6 + 5] = triVert[2]; + numTotalTriangles++; + } + } + glPushMatrix(); + glScalef(scale.x, scale.y, scale.z); + glEnableClientState(GL_NORMAL_ARRAY); + glEnableClientState(GL_VERTEX_ARRAY); + glNormalPointer(GL_FLOAT, 2*3*sizeof(float), gVertexBuffer); + glVertexPointer(3, GL_FLOAT, 2*3*sizeof(float), gVertexBuffer+1); + glDrawArrays(GL_TRIANGLES, 0, int(numTotalTriangles * 3)); + glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_NORMAL_ARRAY); + glPopMatrix(); + } + break; + + case PxGeometryType::eINVALID: + case PxGeometryType::eHEIGHTFIELD: + case PxGeometryType::eGEOMETRY_COUNT: + case PxGeometryType::ePLANE: + break; + } +} + +static PX_FORCE_INLINE void renderGeometryHolder(const PxGeometryHolder& h) +{ + renderGeometry(h.any()); +} + +namespace Snippets +{ +static void reshapeCallback(int width, int height) +{ + glViewport(0, 0, width, height); +} + +void setupDefaultWindow(const char *name) +{ + char* namestr = new char[strlen(name)+1]; + strcpy(namestr, name); + int argc = 1; + char* argv[1] = { namestr }; + + glutInit(&argc, argv); + + glutInitWindowSize(512, 512); + glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH); + int mainHandle = glutCreateWindow(name); + glutSetWindow(mainHandle); + glutReshapeFunc(reshapeCallback); + + delete[] namestr; +} + +void setupDefaultRenderState() +{ + // Setup default render states + glClearColor(0.3f, 0.4f, 0.5f, 1.0); + glEnable(GL_DEPTH_TEST); + glEnable(GL_COLOR_MATERIAL); + + // Setup lighting + glEnable(GL_LIGHTING); + PxReal ambientColor[] = { 0.0f, 0.1f, 0.2f, 0.0f }; + PxReal diffuseColor[] = { 1.0f, 1.0f, 1.0f, 0.0f }; + PxReal specularColor[] = { 0.0f, 0.0f, 0.0f, 0.0f }; + PxReal position[] = { 100.0f, 100.0f, 400.0f, 1.0f }; + glLightfv(GL_LIGHT0, GL_AMBIENT, ambientColor); + glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseColor); + glLightfv(GL_LIGHT0, GL_SPECULAR, specularColor); + glLightfv(GL_LIGHT0, GL_POSITION, position); + glEnable(GL_LIGHT0); +} + +void startRender(const PxVec3& cameraEye, const PxVec3& cameraDir, PxReal clipNear, PxReal clipFar) +{ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + // Setup camera + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPerspective(60.0, GLdouble(glutGet(GLUT_WINDOW_WIDTH)) / GLdouble(glutGet(GLUT_WINDOW_HEIGHT)), GLdouble(clipNear), GLdouble(clipFar)); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + gluLookAt(GLdouble(cameraEye.x), GLdouble(cameraEye.y), GLdouble(cameraEye.z), GLdouble(cameraEye.x + cameraDir.x), GLdouble(cameraEye.y + cameraDir.y), GLdouble(cameraEye.z + cameraDir.z), 0.0, 1.0, 0.0); + + glColor4f(0.4f, 0.4f, 0.4f, 1.0f); +} + +void finishRender() +{ + glutSwapBuffers(); +} + +void renderActors(PxRigidActor** actors, const PxU32 numActors, bool shadows, const PxVec3& color) +{ + const PxVec3 shadowDir(0.0f, -0.7071067f, -0.7071067f); + const PxReal shadowMat[]={ 1,0,0,0, -shadowDir.x/shadowDir.y,0,-shadowDir.z/shadowDir.y,0, 0,0,1,0, 0,0,0,1 }; + + PxShape* shapes[MAX_NUM_ACTOR_SHAPES]; + for(PxU32 i=0;igetNbShapes(); + PX_ASSERT(nbShapes <= MAX_NUM_ACTOR_SHAPES); + actors[i]->getShapes(shapes, nbShapes); + const bool sleeping = actors[i]->is() ? actors[i]->is()->isSleeping() : false; + + for(PxU32 j=0;jgetGeometry(); + + if (shapes[j]->getFlags() & PxShapeFlag::eTRIGGER_SHAPE) + glPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); + + // render object + glPushMatrix(); + glMultMatrixf(&shapePose.column0.x); + if(sleeping) + { + const PxVec3 darkColor = color * 0.25f; + glColor4f(darkColor.x, darkColor.y, darkColor.z, 1.0f); + } + else + glColor4f(color.x, color.y, color.z, 1.0f); + renderGeometryHolder(h); + glPopMatrix(); + + glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); + + if(shadows) + { + glPushMatrix(); + glMultMatrixf(shadowMat); + glMultMatrixf(&shapePose.column0.x); + glDisable(GL_LIGHTING); + glColor4f(0.1f, 0.2f, 0.3f, 1.0f); + renderGeometryHolder(h); + glEnable(GL_LIGHTING); + glPopMatrix(); + } + } + } +} + +/*static const PxU32 gGeomSizes[] = { + sizeof(PxSphereGeometry), + sizeof(PxPlaneGeometry), + sizeof(PxCapsuleGeometry), + sizeof(PxBoxGeometry), + sizeof(PxConvexMeshGeometry), + sizeof(PxTriangleMeshGeometry), + sizeof(PxHeightFieldGeometry), +}; + +void renderGeoms(const PxU32 nbGeoms, const PxGeometry* geoms, const PxTransform* poses, bool shadows, const PxVec3& color) +{ + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + const PxVec3 shadowDir(0.0f, -0.7071067f, -0.7071067f); + const PxReal shadowMat[]={ 1,0,0,0, -shadowDir.x/shadowDir.y,0,-shadowDir.z/shadowDir.y,0, 0,0,1,0, 0,0,0,1 }; + + const PxU8* stream = reinterpret_cast(geoms); + for(PxU32 j=0;j(stream); + stream += gGeomSizes[geom.getType()]; + + // render object + glPushMatrix(); + glMultMatrixf(&shapePose.column0.x); + glColor4f(color.x, color.y, color.z, 1.0f); + renderGeometry(geom); + glPopMatrix(); + + if(shadows) + { + glPushMatrix(); + glMultMatrixf(shadowMat); + glMultMatrixf(&shapePose.column0.x); + glDisable(GL_LIGHTING); + glColor4f(0.1f, 0.2f, 0.3f, 1.0f); + renderGeometry(geom); + glEnable(GL_LIGHTING); + glPopMatrix(); + } + } +}*/ + +void renderGeoms(const PxU32 nbGeoms, const PxGeometryHolder* geoms, const PxTransform* poses, bool shadows, const PxVec3& color) +{ + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); +// glPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); + const PxVec3 shadowDir(0.0f, -0.7071067f, -0.7071067f); + const PxReal shadowMat[]={ 1,0,0,0, -shadowDir.x/shadowDir.y,0,-shadowDir.z/shadowDir.y,0, 0,0,1,0, 0,0,0,1 }; + + for(PxU32 j=0;j(Ps::Thread::getId()); + } + + //******************************************************************************// + + PxU64 getCurrentTimeCounterValue() + { + return Ps::Time::getCurrentCounterValue(); + } + + PxReal getElapsedTimeInMilliseconds(const PxU64 elapsedTime) + { + return Ps::Time::getCounterFrequency().toTensOfNanos(elapsedTime)/(100.0f * 1000.0f); + } + + PxReal getElapsedTimeInMicroSeconds(const PxU64 elapsedTime) + { + return Ps::Time::getCounterFrequency().toTensOfNanos(elapsedTime)/(100.0f); + } + + //******************************************************************************// + + struct Sync: public Ps::SyncT {}; + + Sync* syncCreate() + { + return new(gUtilAllocator.allocate(sizeof(Sync), 0, 0, 0)) Sync(); + } + + void syncWait(Sync* sync) + { + sync->wait(); + } + + void syncSet(Sync* sync) + { + sync->set(); + } + + void syncReset(Sync* sync) + { + sync->reset(); + } + + void syncRelease(Sync* sync) + { + sync->~Sync(); + gUtilAllocator.deallocate(sync); + } + + //******************************************************************************// + + struct Thread: public Ps::ThreadT + { + Thread(ThreadEntryPoint entryPoint, void* data): + Ps::ThreadT(), + mEntryPoint(entryPoint), + mData(data) + { + } + + virtual void execute(void) + { + mEntryPoint(mData); + } + + ThreadEntryPoint mEntryPoint; + void* mData; + }; + + Thread* threadCreate(ThreadEntryPoint entryPoint, void* data) + { + Thread* createThread = static_cast(gUtilAllocator.allocate(sizeof(Thread), 0, 0, 0)); + PX_PLACEMENT_NEW(createThread, Thread(entryPoint, data)); + createThread->start(); + return createThread; + } + + void threadQuit(Thread* thread) + { + thread->quit(); + } + + void threadSignalQuit(Thread* thread) + { + thread->signalQuit(); + } + + bool threadWaitForQuit(Thread* thread) + { + return thread->waitForQuit(); + } + + bool threadQuitIsSignalled(Thread* thread) + { + return thread->quitIsSignalled(); + } + + void threadRelease(Thread* thread) + { + thread->~Thread(); + gUtilAllocator.deallocate(thread); + } + + //******************************************************************************// + + struct Mutex: public Ps::MutexT {}; + + Mutex* mutexCreate() + { + return new(gUtilAllocator.allocate(sizeof(Mutex), 0, 0, 0)) Mutex(); + } + + void mutexLock(Mutex* mutex) + { + mutex->lock(); + } + + void mutexUnlock(Mutex* mutex) + { + mutex->unlock(); + } + + void mutexRelease(Mutex* mutex) + { + mutex->~Mutex(); + gUtilAllocator.deallocate(mutex); + } + + +} // namespace physXUtils +} // namespace physx