Skip to content

Commit ea3888b

Browse files
committed
fix(build): break cyclic dep between infiniops and torch object lib
`target_link_libraries(infiniops_torch_objs PUBLIC infiniops)` and `target_sources(infiniops PRIVATE $<TARGET_OBJECTS:...>)` form a cycle that cmake rejects on cambricon ("Cyclic dependencies are allowed only among static libraries"). Inherit `infiniops`'s include directories, compile definitions, and compile options via `$<TARGET_PROPERTY>` generator expressions instead of linking, so the object library compiles with the same settings without a back-edge to `infiniops`.
1 parent c739b19 commit ea3888b

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

src/CMakeLists.txt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,9 +353,18 @@ if(WITH_TORCH)
353353
# Build the heavy torch sources as their own object library so
354354
# the Ninja `torch_compile` job pool throttles only those
355355
# compilations and the rest of `infiniops` keeps full
356-
# parallelism.
356+
# parallelism. Inherit infiniops's compile-time settings via
357+
# generator expressions (linking would create a cyclic
358+
# dependency since infiniops then absorbs the object files).
357359
add_library(infiniops_torch_objs OBJECT ${TORCH_SOURCES})
358-
target_link_libraries(infiniops_torch_objs PUBLIC infiniops)
360+
target_include_directories(infiniops_torch_objs PRIVATE
361+
$<TARGET_PROPERTY:infiniops,INCLUDE_DIRECTORIES>
362+
${TORCH_INCLUDE_DIRS}
363+
${PROJECT_SOURCE_DIR}/generated)
364+
target_compile_definitions(infiniops_torch_objs PRIVATE
365+
$<TARGET_PROPERTY:infiniops,COMPILE_DEFINITIONS>)
366+
target_compile_options(infiniops_torch_objs PRIVATE
367+
$<TARGET_PROPERTY:infiniops,COMPILE_OPTIONS>)
359368
if(CMAKE_GENERATOR MATCHES "Ninja")
360369
set_target_properties(infiniops_torch_objs
361370
PROPERTIES JOB_POOL_COMPILE torch_compile)

0 commit comments

Comments
 (0)