Skip to content

Commit a9a2b0a

Browse files
committed
[libclc] Enable DEPENDS_EXPLICIT_ONLY if cmake version >= 3.27
Commit 0c21d6b fixed sequential build of libclc on Windows by adding a target for each compile command. This PR conditionally enables DEPENDS_EXPLICIT_ONLY and requires at least cmake version 3.27. DEPENDS_EXPLICIT_ONLY avoids adding too many targets.
1 parent 98f4b77 commit a9a2b0a

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

libclc/cmake/modules/AddLibclc.cmake

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ function(compile_to_bc)
4545
get_filename_component( ARG_OUTPUT_DIR ${ARG_OUTPUT} DIRECTORY )
4646
file( MAKE_DIRECTORY ${ARG_OUTPUT_DIR} )
4747

48+
set( COMMAND_ADDITIONAL_OPTIONS )
49+
if( CMAKE_VERSION VERSION_GREATER_EQUAL "3.27" )
50+
list( APPEND COMMAND_ADDITIONAL_OPTIONS DEPENDS_EXPLICIT_ONLY )
51+
endif()
52+
4853
add_custom_command(
4954
OUTPUT ${ARG_OUTPUT}${TMP_SUFFIX}
5055
COMMAND ${clang_exe}
@@ -64,13 +69,13 @@ function(compile_to_bc)
6469
${ARG_INPUT}
6570
${ARG_DEPENDENCIES}
6671
DEPFILE ${ARG_OUTPUT}.d
72+
${COMMAND_ADDITIONAL_OPTIONS}
6773
)
68-
# FIXME: The target is added to ensure the parallel build of source files.
69-
# However, this may result in a large number of targets.
70-
# Starting with CMake 3.27, DEPENDS_EXPLICIT_ONLY can be used with
71-
# add_custom_command to enable parallel build.
72-
# Refer to https://gitlab.kitware.com/cmake/cmake/-/issues/17097 for details.
73-
add_custom_target( ${ARG_TARGET} DEPENDS ${ARG_OUTPUT}${TMP_SUFFIX} )
74+
# If DEPENDS_EXPLICIT_ONLY isn't available, add target to ensure the parallel
75+
# build of source files on Windows.
76+
if( CMAKE_VERSION VERSION_LESS "3.27" )
77+
add_custom_target( ${ARG_TARGET} DEPENDS ${ARG_OUTPUT}${TMP_SUFFIX} )
78+
endif()
7479

7580
if( ${FILE_EXT} STREQUAL ".ll" )
7681
add_custom_command(
@@ -324,7 +329,9 @@ function(add_libclc_builtin_set)
324329
-I${CMAKE_CURRENT_SOURCE_DIR}/${file_dir}
325330
DEPENDENCIES ${input_file_dep}
326331
)
327-
list( APPEND compile_tgts ${tgt} )
332+
if( CMAKE_VERSION VERSION_LESS "3.27" )
333+
list( APPEND compile_tgts ${tgt} )
334+
endif()
328335

329336
# Collect all files originating in LLVM IR separately
330337
get_filename_component( file_ext ${file} EXT )

0 commit comments

Comments
 (0)