Skip to content

Commit 27ede3b

Browse files
committed
[libclc] Make library output directories explicit
These changes were split off from llvm#146503. This commit makes the output directories of libclc artefacts explicit. It creates a variable for the final output directory - LIBCLC_OUTPUT_LIBRARY_DIR - which has not changed. This allows future changes to alter the output directory more simply, such as by pointing it to somewhere inside clang's resource directory. This commit also changes the output directory of each target's intermediate builtins.*.bc files. They are now placed into each respective libclc target's object directory, rather than the top-level libclc binary directory. This should help keep the binary directory a bit tidier.
1 parent 3efa461 commit 27ede3b

File tree

2 files changed

+40
-22
lines changed

2 files changed

+40
-22
lines changed

libclc/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ else()
8484
endif()
8585
endif()
8686

87+
# Setup the paths where libclc runtimes should be stored.
88+
set( LIBCLC_OUTPUT_LIBRARY_DIR ${CMAKE_CURRENT_BINARY_DIR} )
89+
8790
if( EXISTS ${LIBCLC_CUSTOM_LLVM_TOOLS_BINARY_DIR} )
8891
message( WARNING "Using custom LLVM tools to build libclc: "
8992
"${LIBCLC_CUSTOM_LLVM_TOOLS_BINARY_DIR}, "

libclc/cmake/modules/AddLibclc.cmake

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,15 @@ function(link_bc)
120120
endif()
121121

122122
add_custom_command(
123-
OUTPUT ${ARG_TARGET}.bc
124-
COMMAND ${llvm-link_exe} ${link_flags} -o ${ARG_TARGET}.bc ${LINK_INPUT_ARG}
123+
OUTPUT ${LIBCLC_ARCH_OBJFILE_DIR}/${ARG_TARGET}.bc
124+
COMMAND ${llvm-link_exe} ${link_flags} -o ${LIBCLC_ARCH_OBJFILE_DIR}/${ARG_TARGET}.bc ${LINK_INPUT_ARG}
125125
DEPENDS ${llvm-link_target} ${ARG_DEPENDENCIES} ${ARG_INPUTS} ${RSP_FILE}
126+
WORKING_DIRECTORY ${LIBCLC_ARCH_OBJFILE_DIR}
126127
)
127128

128-
add_custom_target( ${ARG_TARGET} ALL DEPENDS ${ARG_TARGET}.bc )
129+
add_custom_target( ${ARG_TARGET} ALL DEPENDS ${LIBCLC_ARCH_OBJFILE_DIR}/${ARG_TARGET}.bc )
129130
set_target_properties( ${ARG_TARGET} PROPERTIES
130-
TARGET_FILE ${CMAKE_CURRENT_BINARY_DIR}/${ARG_TARGET}.bc
131+
TARGET_FILE ${LIBCLC_ARCH_OBJFILE_DIR}/${ARG_TARGET}.bc
131132
FOLDER "libclc/Device IR/Linking"
132133
)
133134
endfunction()
@@ -360,33 +361,39 @@ function(add_libclc_builtin_set)
360361
# llvm-spirv tool.
361362
if( ARG_ARCH STREQUAL spirv OR ARG_ARCH STREQUAL spirv64 )
362363
set( obj_suffix ${ARG_ARCH_SUFFIX}.spv )
363-
add_custom_command( OUTPUT ${obj_suffix}
364-
COMMAND ${llvm-spirv_exe} ${spvflags} -o ${obj_suffix} ${builtins_link_lib}
364+
set( libclc_builtins_lib ${LIBCLC_OUTPUT_LIBRARY_DIR}/${obj_suffix} )
365+
add_custom_command( OUTPUT ${libclc_builtins_lib}
366+
COMMAND ${llvm-spirv_exe} ${spvflags} -o ${libclc_builtins_lib} ${builtins_link_lib}
365367
DEPENDS ${llvm-spirv_target} ${builtins_link_lib} ${builtins_link_lib_tgt}
368+
WORKING_DIRECTORY ${LIBCLC_OUTPUT_LIBRARY_DIR}
366369
)
367370
else()
368371
# Non-SPIR-V targets add an extra step to optimize the bytecode
369372
set( builtins_opt_lib_tgt builtins.opt.${ARG_ARCH_SUFFIX} )
370373

371-
add_custom_command( OUTPUT ${builtins_opt_lib_tgt}.bc
372-
COMMAND ${opt_exe} ${ARG_OPT_FLAGS} -o ${builtins_opt_lib_tgt}.bc
374+
add_custom_command( OUTPUT ${LIBCLC_ARCH_OBJFILE_DIR}/${builtins_opt_lib_tgt}.bc
375+
COMMAND ${opt_exe} ${ARG_OPT_FLAGS} -o ${LIBCLC_ARCH_OBJFILE_DIR}/${builtins_opt_lib_tgt}.bc
373376
${builtins_link_lib}
374377
DEPENDS ${opt_target} ${builtins_link_lib} ${builtins_link_lib_tgt}
378+
WORKING_DIRECTORY ${LIBCLC_ARCH_OBJFILE_DIR}
375379
)
376380
add_custom_target( ${builtins_opt_lib_tgt}
377-
ALL DEPENDS ${builtins_opt_lib_tgt}.bc
381+
ALL DEPENDS ${LIBCLC_ARCH_OBJFILE_DIR}/${builtins_opt_lib_tgt}.bc
378382
)
379383
set_target_properties( ${builtins_opt_lib_tgt} PROPERTIES
380-
TARGET_FILE ${CMAKE_CURRENT_BINARY_DIR}/${builtins_opt_lib_tgt}.bc
384+
TARGET_FILE ${LIBCLC_ARCH_OBJFILE_DIR}/${builtins_opt_lib_tgt}.bc
381385
FOLDER "libclc/Device IR/Opt"
382386
)
383387

384388
set( builtins_opt_lib $<TARGET_PROPERTY:${builtins_opt_lib_tgt},TARGET_FILE> )
385389

386390
set( obj_suffix ${ARG_ARCH_SUFFIX}.bc )
387-
add_custom_command( OUTPUT ${obj_suffix}
388-
COMMAND ${prepare_builtins_exe} -o ${obj_suffix} ${builtins_opt_lib}
389-
DEPENDS ${builtins_opt_lib} ${builtins_opt_lib_tgt} ${prepare_builtins_target} )
391+
set( libclc_builtins_lib ${LIBCLC_OUTPUT_LIBRARY_DIR}/${obj_suffix} )
392+
add_custom_command( OUTPUT ${libclc_builtins_lib}
393+
COMMAND ${prepare_builtins_exe} -o ${libclc_builtins_lib} ${builtins_opt_lib}
394+
DEPENDS ${builtins_opt_lib} ${builtins_opt_lib_tgt} ${prepare_builtins_target}
395+
WORKING_DIRECTORY ${LIBCLC_OUTPUT_LIBRARY_DIR}
396+
)
390397
endif()
391398

392399
# Add a 'prepare' target
@@ -402,7 +409,7 @@ function(add_libclc_builtin_set)
402409
add_dependencies( prepare-${ARG_TRIPLE} prepare-${obj_suffix} )
403410

404411
install(
405-
FILES ${CMAKE_CURRENT_BINARY_DIR}/${obj_suffix}
412+
FILES ${libclc_builtins_lib}
406413
DESTINATION "${CMAKE_INSTALL_DATADIR}/clc"
407414
)
408415

@@ -418,20 +425,28 @@ function(add_libclc_builtin_set)
418425
# * clspv targets don't include all OpenCL builtins
419426
if( NOT ARG_ARCH MATCHES "^(nvptx|clspv)(64)?$" )
420427
add_test( NAME external-calls-${obj_suffix}
421-
COMMAND ./check_external_calls.sh ${CMAKE_CURRENT_BINARY_DIR}/${obj_suffix} ${LLVM_TOOLS_BINARY_DIR}
428+
COMMAND ./check_external_calls.sh ${libclc_builtins_lib} ${LLVM_TOOLS_BINARY_DIR}
422429
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} )
423430
endif()
424431

425432
foreach( a ${ARG_ALIASES} )
426433
set( alias_suffix "${a}-${ARG_TRIPLE}.bc" )
427434
add_custom_command(
428-
OUTPUT ${alias_suffix}
429-
COMMAND ${CMAKE_COMMAND} -E create_symlink ${obj_suffix} ${alias_suffix}
430-
DEPENDS prepare-${obj_suffix} )
431-
add_custom_target( alias-${alias_suffix} ALL DEPENDS ${alias_suffix} )
432-
set_target_properties( alias-${alias_suffix} PROPERTIES FOLDER "libclc/Device IR/Aliases" )
433-
install( FILES ${CMAKE_CURRENT_BINARY_DIR}/${alias_suffix}
434-
DESTINATION "${CMAKE_INSTALL_DATADIR}/clc" )
435+
OUTPUT ${LIBCLC_OUTPUT_LIBRARY_DIR}/${alias_suffix}
436+
COMMAND ${CMAKE_COMMAND} -E create_symlink ${libclc_builtins_lib} ${LIBCLC_OUTPUT_LIBRARY_DIR}/${alias_suffix}
437+
DEPENDS prepare-${obj_suffix}
438+
WORKING_DIRECTORY ${LIBCLC_OUTPUT_LIBRARY_DIR}
439+
)
440+
add_custom_target( alias-${alias_suffix} ALL
441+
DEPENDS ${LIBCLC_OUTPUT_LIBRARY_DIR}/${alias_suffix}
442+
)
443+
set_target_properties( alias-${alias_suffix}
444+
PROPERTIES FOLDER "libclc/Device IR/Aliases"
445+
)
446+
install(
447+
FILES ${LIBCLC_OUTPUT_LIBRARY_DIR}/${alias_suffix}
448+
DESTINATION "${CMAKE_INSTALL_DATADIR}/clc"
449+
)
435450
endforeach( a )
436451
endfunction(add_libclc_builtin_set)
437452

0 commit comments

Comments
 (0)