File: workaround_thread.cmake

package info (click to toggle)
gridtools 2.3.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 29,480 kB
  • sloc: cpp: 228,792; python: 17,561; javascript: 9,164; ansic: 4,101; sh: 850; makefile: 231; f90: 201
file content (26 lines) | stat: -rw-r--r-- 1,231 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# FindThreads improperly passes -pthread to nvcc instead of e.g. -Xcompiler=-pthread.
# (see: https://gitlab.kitware.com/cmake/cmake/issues/18008)
# Fixed in CMake 3.13.0.

function(_fix_threads_flags)
    if(${CMAKE_VERSION} VERSION_LESS "3.13.0")
        if(TARGET Threads::Threads)
            get_property(_languages GLOBAL PROPERTY ENABLED_LANGUAGES)
            if("CUDA" IN_LIST _languages)
                get_property(_threads_options TARGET Threads::Threads PROPERTY INTERFACE_COMPILE_OPTIONS)
                if(_threads_options STREQUAL "-pthread")
                    set_property(TARGET Threads::Threads
                        PROPERTY INTERFACE_COMPILE_OPTIONS
                        $<$<COMPILE_LANGUAGE:CUDA>:-Xcompiler=-pthread>
                        $<$<NOT:$<COMPILE_LANGUAGE:CUDA>>:-pthread>)
                endif()
                get_property(_threads_options_linker TARGET Threads::Threads PROPERTY INTERFACE_LINK_LIBRARIES)
                if(_threads_options_linker STREQUAL "-pthread")
                    set_property(TARGET Threads::Threads
                        PROPERTY INTERFACE_LINK_LIBRARIES -lpthread)
                endif()
            endif()
        endif()
    endif()
endfunction()