Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The FindDirectXShaderCompiler for MacOS needs to be updated to use proper library types #201

Open
lemonade-dm opened this issue May 20, 2023 · 0 comments

Comments

@lemonade-dm
Copy link
Contributor

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant