#
# Build PhysXCommon
#

FIND_PACKAGE(nvToolsExt REQUIRED)

SET(PHYSX_SOURCE_DIR ${PROJECT_SOURCE_DIR}/../../../)

SET(COMMON_SRC_DIR ${PHYSX_SOURCE_DIR}/Common/src)
SET(GU_SOURCE_DIR ${PHYSX_SOURCE_DIR}/GeomUtils)

SET(PHYSXCOMMON_LIBTYPE SHARED)

SET(PHYSXCOMMON_WINDOWS_HEADERS
	${PHYSX_SOURCE_DIR}/Common/include/windows/CmWindowsLoadLibrary.h
	${PHYSX_SOURCE_DIR}/Common/include/windows/CmWindowsModuleUpdateLoader.h
)
SOURCE_GROUP(common\\include\\windows FILES ${PHYSXCOMMON_WINDOWS_HEADERS})

SET(PHYSXCOMMON_WINDOWS_SOURCE
	${COMMON_SRC_DIR}/windows/CmWindowsModuleUpdateLoader.cpp
	${COMMON_SRC_DIR}/windows/CmWindowsDelayLoadHook.cpp
)
SOURCE_GROUP(common\\src\\windows FILES ${PHYSXCOMMON_WINDOWS_SOURCE})

SET(PHYSXCOMMON_RESOURCE
	${PHYSX_SOURCE_DIR}/compiler/resource_${LIBPATH_SUFFIX}/PhysX3Common.rc)
SOURCE_GROUP(resource FILES ${PHYSXCOMMON_RESOURCE})

SET(PXCOMMON_PLATFORM_SRC_FILES 
	${PHYSXCOMMON_WINDOWS_HEADERS}
	${PHYSXCOMMON_WINDOWS_SOURCE}
	
	${PHYSXCOMMON_RESOURCE}
)

SET(PXCOMMON_PLATFORM_INCLUDES
	${NVTOOLSEXT_INCLUDE_DIRS}
	${PHYSX_SOURCE_DIR}/Common/src/windows
)

SET(PXCOMMON_COMPILE_DEFS
	# Common to all configurations
	${PHYSX_WINDOWS_COMPILE_DEFS};PX_FOUNDATION_DLL=1;PX_PHYSX_COMMON_EXPORTS;

	# Switch platforms here?
	$<$<CONFIG:debug>:${PHYSX_WINDOWS_DEBUG_COMPILE_DEFS};PX_PHYSX_DLL_NAME_POSTFIX=DEBUG>
	$<$<CONFIG:checked>:${PHYSX_WINDOWS_CHECKED_COMPILE_DEFS};PX_PHYSX_DLL_NAME_POSTFIX=CHECKED>
	$<$<CONFIG:profile>:${PHYSX_WINDOWS_PROFILE_COMPILE_DEFS};PX_PHYSX_DLL_NAME_POSTFIX=PROFILE>
	$<$<CONFIG:release>:${PHYSX_WINDOWS_RELEASE_COMPILE_DEFS}>
)

# include common PhysXCommon settings
INCLUDE(../common/PhysXCommon.cmake)

# Do final direct sets after the target has been defined
TARGET_LINK_LIBRARIES(PhysXCommon PUBLIC ${NVTOOLSEXT_LIBRARIES} PxFoundation)
SET_TARGET_PROPERTIES(PhysXCommon PROPERTIES LINK_FLAGS "/MAP"	)
