[CMake] Create parent directories for TableGen outputs (#25148) I ran into this while building IREE’s Torch frontend with Unix Makefiles. TableGen fails when an output’s parent directory doesn’t exist, so this creates it before generation. --------- Signed-off-by: anutosh491 <andersonbhat491@gmail.com> Signed-off-by: Anutosh Bhat <andersonbhat491@gmail.com> Co-authored-by: Artem Gindinson <gindinson@roofline.ai>
diff --git a/build_tools/cmake/iree_tablegen_library.cmake b/build_tools/cmake/iree_tablegen_library.cmake index d07b884..a301612 100644 --- a/build_tools/cmake/iree_tablegen_library.cmake +++ b/build_tools/cmake/iree_tablegen_library.cmake
@@ -12,7 +12,7 @@ # NAME: Name of the tablegen library target. # TBLGEN: Tablegen executable to use (IREE or MLIR). # TD_FILE: Main .td file to process. -# OUTS: List of output files and their generation flags. +# OUTS: List of output files and their generation flags. Supports nested paths and ensures that directories exist. function(iree_tablegen_library) cmake_parse_arguments( _RULE @@ -76,6 +76,8 @@ endwhile() set(_OUTPUT_FILE ${CMAKE_CURRENT_BINARY_DIR}/${_FILE}) + get_filename_component(_OUTPUT_DIRECTORY "${_OUTPUT_FILE}" DIRECTORY) + file(MAKE_DIRECTORY "${_OUTPUT_DIRECTORY}") # Create add_custom_command with depfile support for Ninja. if(CMAKE_GENERATOR MATCHES "Ninja")