File: workaround_thread.cmake

package info (click to toggle)
gridtools 2.0.0-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 21,728 kB
  • sloc: cpp: 45,263; python: 9,383; javascript: 8,445; ansic: 2,564; sh: 509; f90: 370; makefile: 216
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()