Skip to content

Commit e4a0bb2

Browse files
committed
Fix CUDA detection problem
1 parent 7f6cd80 commit e4a0bb2

File tree

2 files changed

+41
-15
lines changed

2 files changed

+41
-15
lines changed

flang-rt/CMakeLists.txt

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ list(APPEND CMAKE_MODULE_PATH
3131
include(AddFlangRT)
3232
include(GetToolchainDirs)
3333
include(FlangCommon)
34+
include(FlangRTIntrospection)
3435
include(HandleCompilerRT)
3536
include(ExtendPath)
3637
include(CheckFortranSourceCompiles)
@@ -154,21 +155,9 @@ check_cxx_source_compiles(
154155
"
155156
HAVE_DECL_STRERROR_S)
156157

157-
158-
# Look for support of REAL(16), if not already defined via command line.
159-
# NOTE: Does not work with Flang and CMake < 3.24
160-
cmake_push_check_state(RESET)
161-
set(CMAKE_REQUIRED_FLAGS "-ffree-form")
162-
set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY")
163-
check_fortran_source_compiles([[
164-
subroutine test_quadmath
165-
real(16) :: var1
166-
end
167-
]]
168-
FORTRAN_SUPPORTS_REAL16
169-
)
170-
cmake_pop_check_state()
171-
158+
# Look for support of REAL(16), if not already defined via command
159+
# line via -DFORTRAN_SUPPORTS_REAL16=YES/NO
160+
check_fortran_quadmath_support()
172161

173162
# Search for clang_rt.builtins library. Need in addition to msvcrt.
174163
if (WIN32)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#===-- cmake/modules/FlangRTIntrospection.cmake ----------------------------===#
2+
#
3+
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
# See https://llvm.org/LICENSE.txt for license information.
5+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
#
7+
#===------------------------------------------------------------------------===#
8+
9+
10+
# Check whether the Fortran compiler supports real(16)/quadmath types
11+
#
12+
# Implementation notes:
13+
# * FORTRAN_SUPPORTS_REAL16 can be set externally in a bootstrapping-runtimes
14+
# build to ensure consistency of real(16) support between compiler and
15+
# runtime.
16+
#
17+
# * Does not work with Flang and CMake < 3.24
18+
#
19+
# * This is intentionally wrapped in a function to get its own namespace for
20+
# CMAKE_REQUIRED_FLAGS and CMAKE_TRY_COMPILE_TARGET_TYPE. In particular,
21+
# cmake_pop_check_state() does not reset CMAKE_TRY_COMPILE_TARGET_TYPE,
22+
# causing later try_compile invocations to fail. If you see
23+
# enable_language(CUDA) failing because CMAKE_RANLIB is empty, this is the
24+
# reason.
25+
function (check_fortran_quadmath_support)
26+
cmake_push_check_state(RESET)
27+
set(CMAKE_REQUIRED_FLAGS "-ffree-form")
28+
set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY") # Skip link step
29+
check_fortran_source_compiles([[
30+
subroutine test_quadmath
31+
real(16) :: var1
32+
end
33+
]]
34+
FORTRAN_SUPPORTS_REAL16
35+
)
36+
cmake_pop_check_state()
37+
endfunction ()

0 commit comments

Comments
 (0)