#
# Build NvCloth
#


SET(GW_DEPS_ROOT $ENV{GW_DEPS_ROOT})
#FIND_PACKAGE(PxShared REQUIRED)
FIND_PACKAGE(CUDA 8 REQUIRED)
MESSAGE("Found CUDA:" ${CUDA_INCLUDE_DIRS})


SET(NVCLOTH_UNIT_TESTS_PLATFORM_INCLUDES PRIVATE ${CUDA_INCLUDE_DIRS})


SET(NVCLOTH_UNIT_TESTS_COMPILE_DEFS

	NV_CLOTH_IMPORT=PX_DLL_EXPORT
	NV_CLOTH_ENABLE_DX11=1
	NV_CLOTH_ENABLE_CUDA=1
	USE_CUDA=1
	USE_DX11=1

	$<$<CONFIG:debug>:${NVCLOTH_UNIT_TESTS_WINDOWS_DEBUG_COMPILE_DEFS};PX_PHYSX_DLL_NAME_POSTFIX=DEBUG;>
	$<$<CONFIG:checked>:${NVCLOTH_UNIT_TESTS_WINDOWS_CHECKED_COMPILE_DEFS};PX_PHYSX_DLL_NAME_POSTFIX=CHECKED;>
	$<$<CONFIG:profile>:${NVCLOTH_UNIT_TESTS_WINDOWS_PROFILE_COMPILE_DEFS};PX_PHYSX_DLL_NAME_POSTFIX=PROFILE;>
	$<$<CONFIG:release>:${NVCLOTH_UNIT_TESTS_WINDOWS_RELEASE_COMPILE_DEFS};>
)



SET(NVCLOTH_UNIT_TESTS_LIBTYPE SHARED)

# include common NvCloth settings
INCLUDE(../common/NvClothUnitTests.cmake)


if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
FIND_PATH(		DX_LIB_DIR d3d11.lib
				HINTS 
				${GW_DEPS_ROOT}/sw/tools/sdk/WinSDK/8.1/Lib/winv6.3/um/x64/
				${GW_DEPS_ROOT}/Externals/WinSDK/8.1/Lib/winv6.3/um/x64/
				)
ELSE()
FIND_PATH(		DX_LIB_DIR d3d11.lib
				HINTS 
				${GW_DEPS_ROOT}/sw/tools/sdk/WinSDK/8.1/Lib/winv6.3/um/x86/
				${GW_DEPS_ROOT}/Externals/WinSDK/8.1/Lib/winv6.3/um/x86
				)
ENDIF()

# Add linked libraries
TARGET_LINK_LIBRARIES(NvClothUnitTests PUBLIC PxFoundation)
TARGET_LINK_LIBRARIES(NvClothUnitTests PUBLIC ${CUDA_CUDA_LIBRARY})
TARGET_LINK_LIBRARIES(NvClothUnitTests PUBLIC GoogleTest)
TARGET_LINK_LIBRARIES(NvClothUnitTests PUBLIC NvCloth)
TARGET_LINK_LIBRARIES(NvClothUnitTests PUBLIC ${DX_LIB_DIR}/d3d11.lib)


SET_TARGET_PROPERTIES(NvClothUnitTests PROPERTIES 
	LINK_FLAGS_DEBUG "/DELAYLOAD:nvcuda.dll /MAP /DELAYLOAD:PxFoundationDEBUG_${LIBPATH_SUFFIX}.dll /DEBUG"
	LINK_FLAGS_CHECKED "/DELAYLOAD:nvcuda.dll /MAP /DELAYLOAD:PxFoundationCHECKED_${LIBPATH_SUFFIX}.dll"
	LINK_FLAGS_PROFILE "/DELAYLOAD:nvcuda.dll /MAP /DELAYLOAD:PxFoundationPROFILE_${LIBPATH_SUFFIX}.dll /INCREMENTAL:NO /DEBUG"
	LINK_FLAGS_RELEASE "/DELAYLOAD:nvcuda.dll /MAP /DELAYLOAD:PxFoundation_${LIBPATH_SUFFIX}.dll /INCREMENTAL:NO"
)
