[build] Add LeakSanitizer option to CMake (#158686)

Pull Request resolved: https://github.com/pytorch/pytorch/pull/158686
Approved by: https://github.com/eellison
This commit is contained in:
Benjamin Glass
2025-09-09 15:09:58 +00:00
committed by PyTorch MergeBot
parent af60398c3a
commit bdbe931d58
5 changed files with 22 additions and 3 deletions

View File

@ -1830,6 +1830,12 @@ if(BUILD_TEST)
target_link_libraries(${test_name}_${CPU_CAPABILITY} Sanitizer::undefined)
endif()
endif()
if(USE_LSAN AND TARGET Sanitizer::leak)
target_link_libraries(${test_name}_${CPU_CAPABILITY} Sanitizer::leak)
endif()
if(USE_TSAN AND TARGET Sanitizer::thread)
target_link_libraries(${test_name}_${CPU_CAPABILITY} Sanitizer::thread)
endif()
else()
add_executable(${test_name}_${CPU_CAPABILITY} "${test_src}")
target_link_libraries(${test_name}_${CPU_CAPABILITY} torch_library sleef gtest_main)