Imported Upstream version 3.25.0
[platform/upstream/cmake.git] / Tests / CudaOnly / DeviceLTO / CMakeLists.txt
1 cmake_minimum_required(VERSION 3.18)
2 project(DeviceLTO CUDA)
3
4 # Goal:
5 # Verify that we correctly compile with device LTO
6 # Verify that device LTO requirements are propagated to
7 # the final device link line
8
9 add_library(CUDA_dlto STATIC file1.cu file2.cu file3.cu)
10 add_executable(CudaOnlyDeviceLTO main.cu)
11
12 set_target_properties(CUDA_dlto
13                       PROPERTIES
14                       CUDA_ARCHITECTURES "${CMAKE_CUDA_ARCHITECTURES_ALL}"
15                       CUDA_SEPARABLE_COMPILATION ON
16                       POSITION_INDEPENDENT_CODE ON)
17
18 set_target_properties(CudaOnlyDeviceLTO
19                       PROPERTIES
20                       CUDA_SEPARABLE_COMPILATION ON
21                       CUDA_ARCHITECTURES "${CMAKE_CUDA_ARCHITECTURES_ALL}"
22                       )
23
24 target_link_libraries(CudaOnlyDeviceLTO PRIVATE CUDA_dlto)
25
26 include(CheckIPOSupported)
27 check_ipo_supported(LANGUAGES CUDA RESULT ipo_supported)
28 if(ipo_supported)
29   set_target_properties(CUDA_dlto
30                         PROPERTIES
31                         INTERPROCEDURAL_OPTIMIZATION ON)
32
33   # When non-LTO variants (i.e. virtual) are built together with LTO ones the
34   # linker warns about missing device LTO for the virtual architectures.
35   # Ignore these warnings.
36   target_link_options(CudaOnlyDeviceLTO PRIVATE "$<DEVICE_LINK:-w>")
37 endif()