diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake --- a/llvm/cmake/modules/AddLLVM.cmake +++ b/llvm/cmake/modules/AddLLVM.cmake @@ -2007,10 +2007,29 @@ ${strip_command} ) else() + if(LLVM_EXTERNALIZE_DEBUGINFO_EXTENSION) + set(file_ext ${LLVM_EXTERNALIZE_DEBUGINFO_EXTENSION}) + else() + set(file_ext debug) + endif() + + set(output_name "$.${file_ext}") + + if(LLVM_EXTERNALIZE_DEBUGINFO_OUTPUT_DIR) + set(output_path "${LLVM_EXTERNALIZE_DEBUGINFO_OUTPUT_DIR}/${output_name}") + # If an output dir is specified, it must be manually mkdir'd on Linux, + # as that directory needs to exist before we can pipe to a file in it. + add_custom_command(TARGET ${name} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E make_directory ${LLVM_EXTERNALIZE_DEBUGINFO_OUTPUT_DIR} + ) + else() + set(output_path "${output_name}") + endif() + add_custom_command(TARGET ${name} POST_BUILD - COMMAND ${CMAKE_OBJCOPY} --only-keep-debug $ $.debug + COMMAND ${CMAKE_OBJCOPY} --only-keep-debug $ ${output_path} ${strip_command} -R .gnu_debuglink - COMMAND ${CMAKE_OBJCOPY} --add-gnu-debuglink=$.debug $ + COMMAND ${CMAKE_OBJCOPY} --add-gnu-debuglink=${output_path} $ ) endif() endfunction()