@@ -31,7 +31,7 @@ function(add_public_eudslpygen_target target eudslpygen_output)
3131 set_target_properties (${target} PROPERTIES FOLDER "${subproject_title} /Eudslpygenning" )
3232endfunction ()
3333
34- function (eudslpygen target inputFile outputFileName )
34+ function (eudslpygen target inputFile)
3535 set (EUDSLPYGEN_TARGET_DEFINITIONS ${inputFile} )
3636 # Get the current set of include paths for this source file.
3737 cmake_parse_arguments (ARG "" "" "DEPENDS;EXTRA_INCLUDES;NAMESPACES" ${ARGN} )
@@ -52,35 +52,41 @@ function(eudslpygen target inputFile outputFileName)
5252 # Filter out empty items before prepending each entry with -I
5353 list (REMOVE_ITEM eudslpygen_includes "" )
5454 list (TRANSFORM eudslpygen_includes PREPEND -I)
55+
56+ set (_gen_target_dir "${CMAKE_CURRENT_BINARY_DIR} /generated/${target} " )
57+ file (MAKE_DIRECTORY ${_gen_target_dir} )
58+ set (fullGenFile "${_gen_target_dir} /${target} .cpp.gen" )
59+ file (RELATIVE_PATH fullGenFile_rel "${CMAKE_BINARY_DIR} " "${fullGenFile} " )
60+ set (_depfile ${fullGenFile} .d)
5561
5662 # hack but most of the time we're loading headers that are downstream of tds anyway
5763 # this could be smarter by asking people to list td targets or something but that's too onerous
5864 file (GLOB_RECURSE global_tds "${MLIR_INCLUDE_DIR} /mlir/*.td" )
5965 # use cc -MM to collect all transitive headers
60- set (_depfile ${CMAKE_CURRENT_BINARY_DIR} / ${outputFileName} .d)
61- file (RELATIVE_PATH outputFileName_rel
62- " ${CMAKE_BINARY_DIR} " " ${CMAKE_CURRENT_BINARY_DIR} / ${outputFileName} " )
63- set (clang_command ${CMAKE_CXX_COMPILER} -v -xc++ "-std=c++ ${CMAKE_CXX_STANDARD} " -MM ${EUDSLPYGEN_TARGET_DEFINITIONS_ABSOLUTE }
64- ${eudslpygen_includes} -MT ${outputFileName_rel} -o ${_depfile} )
66+ set (clang_command ${CMAKE_CXX_COMPILER} -v -xc++ "-std=c++ ${CMAKE_CXX_STANDARD} "
67+ -MM ${EUDSLPYGEN_TARGET_DEFINITIONS_ABSOLUTE}
68+ -MT ${fullGenFile_rel}
69+ ${eudslpygen_includes }
70+ -o ${_depfile} )
6571 execute_process (COMMAND ${clang_command} RESULT_VARIABLE had_error COMMAND_ECHO STDERR)
6672 if (had_error OR NOT EXISTS "${_depfile} " )
67- set (additional_cmdline -o "${outputFileName_rel } " )
73+ set (additional_cmdline -o "${fullGenFile_rel } " )
6874 else ()
6975 # Use depfile instead of globbing arbitrary *.td(s) for Ninja.
7076 if (CMAKE_GENERATOR MATCHES "Ninja" )
7177 # Make output path relative to build.ninja, assuming located on ${CMAKE_BINARY_DIR}.
7278 # CMake emits build targets as relative paths but Ninja doesn't identify
7379 # absolute path (in *.d) as relative path (in build.ninja)
7480 # Note that eudslpygen is executed on ${CMAKE_BINARY_DIR} as working directory.
75- set (additional_cmdline -o "${outputFileName_rel } " DEPFILE "${_depfile} " )
81+ set (additional_cmdline -o "${fullGenFile_rel } " DEPFILE "${_depfile} " )
7682 else ()
7783 # the length of the first line in the depfile...
78- string (LENGTH "${outputFileName_rel } : \\ " depfile_offset)
84+ string (LENGTH "${fullGenFile_rel } : \\ " depfile_offset)
7985 file (READ ${_depfile} local_headers OFFSET ${depfile_offset} )
8086 string (REPLACE "\\ " ";" local_headers "${local_headers} " )
8187 string (REGEX REPLACE "[ \t\r\n ]" "" local_headers "${local_headers} " )
8288 list (REMOVE_ITEM local_headers "" )
83- set (additional_cmdline -o "${outputFileName_rel } " )
89+ set (additional_cmdline -o "${fullGenFile_rel } " )
8490 endif ()
8591 endif ()
8692
@@ -106,24 +112,39 @@ function(eudslpygen target inputFile outputFileName)
106112 string (REPLACE " " ";" eudslpygen_defines "${LLVM_DEFINITIONS} " )
107113 list (JOIN ARG_NAMESPACES "," namespaces)
108114
109- add_custom_command (OUTPUT ${CMAKE_CURRENT_BINARY_DIR} /${outputFileName}
110- COMMAND ${eudslpygen_exe} ${EUDSLPYGEN_TARGET_DEFINITIONS_ABSOLUTE} -I${CMAKE_CURRENT_SOURCE_DIR}
111- -namespaces=${namespaces}
112- ${eudslpygen_includes}
113- ${eudslpygen_defines}
114- ${additional_cmdline}
115+ add_custom_command (OUTPUT ${fullGenFile}
116+ COMMAND ${eudslpygen_exe} ${EUDSLPYGEN_TARGET_DEFINITIONS_ABSOLUTE}
117+ -I${CMAKE_CURRENT_SOURCE_DIR}
118+ -namespaces=${namespaces}
119+ ${eudslpygen_includes}
120+ ${eudslpygen_defines}
121+ ${additional_cmdline}
115122 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
116123 # The file in EUDSLPYGEN_TARGET_DEFINITIONS may be not in the current
117124 # directory and local_headers may not contain it, so we must
118125 # explicitly list it here:
119126 DEPENDS ${ARG_DEPENDS} ${eudslpygen_depends} ${local_headers} ${global_tds}
120- COMMENT "EUDSLPY: Generating ${outputFileName} ..."
127+ COMMENT "EUDSLPY: Generating ${fullGenFile} ..."
128+ )
129+
130+ add_custom_command (OUTPUT "${fullGenFile} .sharded.cpp"
131+ COMMAND ${Python_EXECUTABLE} ${CMAKE_CURRENT_FUNCTION_LIST_DIR} /make_generated_registration.py
132+ ${fullGenFile} -t ${target} -I ${ARG_EXTRA_INCLUDES} ${EUDSLPYGEN_TARGET_DEFINITIONS_ABSOLUTE}
133+ WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
134+ DEPENDS ${fullGenFile}
135+ COMMENT "EUDSLPY: Generating ${fullGenFile} .sharded.cpp..."
121136 )
122137
138+ # this is the specific thing connected the dependencies...
139+ set_property (DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${fullGenFile} .sharded.cpp" )
140+ file (GLOB _generated_shards "${_gen_target_dir} /*.shard.*" )
141+ list (APPEND _generated_shards "${fullGenFile} .sharded.cpp" )
142+ set (${target} _GENERATED_SHARDS ${_generated_shards} PARENT_SCOPE)
143+
123144 # `make clean' must remove all those generated files:
124145 # TODO(max): clean up dep files
125- set_property (DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${outputFileName } )
126- set_source_files_properties (${CMAKE_CURRENT_BINARY_DIR} /${outputFileName } PROPERTIES
146+ set_property (DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${fullGenFile } )
147+ set_source_files_properties (${CMAKE_CURRENT_BINARY_DIR} /${fullGenFile } PROPERTIES
127148 GENERATED 1)
128149
129150 # Append the includes used for this file to the pdll_compilation_commands
@@ -134,7 +155,7 @@ function(eudslpygen target inputFile outputFileName)
134155 " includes: \" ${CMAKE_CURRENT_SOURCE_DIR} ;${eudslpygen_includes} \"\n "
135156 )
136157
137- add_public_eudslpygen_target(${target} "${CMAKE_CURRENT_BINARY_DIR} / ${outputFileName } " )
158+ add_public_eudslpygen_target(${target} "${fullGenFile} .sharded.cpp; ${_generated_shards } " )
138159endfunction ()
139160
140161macro (add_eudslpygen target project)
0 commit comments