From 2aa6d56dce293e93240a10ea47222b2ca7d3b3e2 Mon Sep 17 00:00:00 2001 From: Stella Laurenzo Date: Sat, 9 Jul 2022 18:35:44 -0700 Subject: [PATCH] Restore Python install behavior from before D128230. In D128230, we accidentally moved the install for Python sources outside of the loop, having one install() per group of files. While it would be nice if we could do this, it means that we flatten the relative directory tree and every source ends up in the root. The right way to do this is to use FILE_SETS, which preserve the relative directory tree, but they are not available until CMake 3.23. Differential Revision: https://reviews.llvm.org/D129434 --- mlir/cmake/modules/AddMLIRPython.cmake | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/mlir/cmake/modules/AddMLIRPython.cmake b/mlir/cmake/modules/AddMLIRPython.cmake index 4d05aca5caf8..706413776b9e 100644 --- a/mlir/cmake/modules/AddMLIRPython.cmake +++ b/mlir/cmake/modules/AddMLIRPython.cmake @@ -567,15 +567,21 @@ function(add_mlir_python_sources_target name) COMMAND "${CMAKE_COMMAND}" -E ${_link_or_copy} "${_src_path}" "${_dest_path}" ) + if(ARG_INSTALL_DIR) + # We have to install each file individually because we need to preserve + # the relative directory structure in the install destination. + # As an example, ${_source_relative_path} may be dialects/math.py + # which would be transformed to ${ARG_INSTALL_DIR}/dialects + # here. This could be moved outside of the loop and cleaned up + # if we used FILE_SETS (introduced in CMake 3.23). + get_filename_component(_install_destination "${ARG_INSTALL_DIR}/${_source_relative_path}" DIRECTORY) + install( + FILES ${_src_path} + DESTINATION "${_install_destination}" + COMPONENT ${ARG_INSTALL_COMPONENT} + ) + endif() endforeach() - - if(ARG_INSTALL_DIR) - install( - FILES ${_src_paths} - DESTINATION "${ARG_INSTALL_DIR}" - COMPONENT ${ARG_INSTALL_COMPONENT} - ) - endif() endforeach() endfunction()