pytorch/cmake/public/threads.cmake
Nikita Shulga c373387709 Update CMake and use native CUDA language support (#62445)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/62445

PyTorch currently uses the old style of compiling CUDA in CMake which is just a
bunch of scripts in `FindCUDA.cmake`. Newer versions support CUDA natively as
a language just like C++ or C.

Test Plan: Imported from OSS

Reviewed By: ejguan

Differential Revision: D31503350

fbshipit-source-id: 2ee817edc9698531ae1b87eda3ad271ee459fd55
2021-10-11 09:05:48 -07:00

30 lines
778 B
CMake

if(TARGET caffe2::Threads)
return()
endif()
find_package(Threads REQUIRED)
# Threads::Threads doesn't work if the target has CUDA code
if(THREADS_FOUND)
add_library(caffe2::Threads INTERFACE IMPORTED)
if(THREADS_HAVE_PTHREAD_ARG)
set(compile_options
$<$<COMPILE_LANGUAGE:C>:-pthread>
$<$<COMPILE_LANGUAGE:CXX>:-pthread>)
if(USE_CUDA)
list(APPEND compile_options
$<$<COMPILE_LANGUAGE:CUDA>:-Xcompiler -pthread>)
endif()
set_property(TARGET caffe2::Threads
PROPERTY INTERFACE_COMPILE_OPTIONS
${compile_options})
endif()
if(CMAKE_THREAD_LIBS_INIT)
set_property(TARGET caffe2::Threads
PROPERTY INTERFACE_LINK_LIBRARIES "${CMAKE_THREAD_LIBS_INIT}")
endif()
endif()