-
Notifications
You must be signed in to change notification settings - Fork 34
Description
The FindDirectShaderCompilerDxc.cmake.Mac script is relying on a call to ly_add_target_files to copy the dxc-3.7 exectuable and libdxcompiler.3.7.dylib to the inside of the AssetProcessor.app bundle.
The issue however is that the libdxcompiler.3.7.dylib gets needs to be copied into the AssetProcessor.app/Contents/Framework directory, but does not because of the ly_add_target_files call which specifies a subdirectory of Builders/DirectXShaderCompiler/lib.
This causes the CMake fixup_bundle command to fail when trying to fixup hthe dxc-3.7 executable.
The proper fix is to have the dxc-3.7 executable be associated with add_executable target type that is IMPORTED and the libdxcompiler.3.7.dylib to be associated with an add_library target type of IMPORTED SHARED.
Here is how the logic should look
set(MY_NAME "DirectXShaderCompilerDxc")
set(TARGET_WITH_NAMESPACE "3rdParty::${MY_NAME}")
if (TARGET ${TARGET_WITH_NAMESPACE})
return()
endif()
set(${MY_NAME}_BINARY_DIR ${CMAKE_CURRENT_LIST_DIR}/${MY_NAME}/bin)
set(${MY_NAME}_LIB_DIR ${CMAKE_CURRENT_LIST_DIR}/${MY_NAME}/lib)
add_library(${TARGET_WITH_NAMESPACE} INTERFACE IMPORTED GLOBAL)
# Add an EXECUTABLE IMPORTED target for the dxc application
add_executable(${TARGET_WITH_NAMESPACE}::dxc IMPORTED GLOBAL)
# Set the IMPORTED target to use the dxc-3.7 has for the output file
set_property(TARGET ${TARGET_WITH_NAMESPACE}::dxc PROPERTY
IMPORTED_LOCATION ${${MY_NAME}_BINARY_DIR}/dxc-3.7)
# Use ly_add_target_files to additionally copy symlinks whenever the EXECUTABLE target is used
ly_add_target_files(TARGETS ${TARGET_WITH_NAMESPACE}::dxc FILES ${${MY_NAME}_BINARY_DIR}/dxc)
# Add a STATIC IMPORTED target for the dxcompiler library
add_library(${TARGET_WITH_NAMESPACE}::dxcompiler SHARED IMPORTED GLOBAL)
# Set the IMPORTED target to use the libdxcompiler-3.7 shared library for the output file
set_property(TARGET ${TARGET_WITH_NAMESPACE}::dxcompiler PROPERTY
IMPORTED_LOCATION ${${MY_NAME}_LIB_DIR}/libdxcompiler.3.7.dylib)
# Use ly_add_target_files to additionally copy the libdxcompiler.dylib symlink next to the SHARED target
ly_add_target_files(TARGETS ${TARGET_WITH_NAMESPACE}::dxcompiler FILES ${${MY_NAME}_LIB_DIR}/libdxcompiler.dylib)
# Update the aggregate ${TARGET_WITH_NAMESPACE} INTERFACE target to depend on both the EXECUTABLE and SHARED library target
target_link_libraries(${TARGET_WITH_NAMESPACE} PUBLIC
${TARGET_WITH_NAMESPACE}::dxc
${TARGET_WITH_NAMESPACE}::dxcompiler)
set(${MY_NAME}_FOUND True)