@@ -4,7 +4,8 @@ include(CheckIncludeFileCXX)
4
4
5
5
# --- abi check: C++ and Fortran compiler ABI compatibility
6
6
7
- function (abi_check)
7
+ block()
8
+
8
9
if (NOT DEFINED abi_compile)
9
10
10
11
message (CHECK_START "checking that C, C++, and Fortran compilers can link" )
@@ -21,32 +22,30 @@ else()
21
22
endif ()
22
23
23
24
# try_run() doesn't adequately detect failed exception handling--it may pass while ctest of the same exe fails
24
- if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.25)
25
- message (CHECK_START "checking that C++ exception handling works" )
26
- try_compile (exception_compile
27
- PROJECT exception
28
- SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR} /exception_check
29
- OUTPUT_VARIABLE abi_output
30
- )
31
- if (abi_output MATCHES "ld: warning: could not create compact unwind for" )
32
- message (CHECK_FAIL "no" )
33
- set (HAVE_CXX_TRYCATCH false CACHE BOOL "C++ exception handling broken" )
34
- message (WARNING "C++ exception handling will not work reliably due to incompatible compilers" )
35
- else ()
36
- message (CHECK_PASS "yes" )
37
- set (HAVE_CXX_TRYCATCH true CACHE BOOL "C++ exception handling works" )
38
- endif ()
39
- endif ()
40
25
26
+ message (CHECK_START "checking that C++ exception handling works" )
27
+ try_compile (exception_compile
28
+ PROJECT exception
29
+ SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR} /exception_check
30
+ OUTPUT_VARIABLE abi_output
31
+ )
32
+ if (abi_output MATCHES "ld: warning: could not create compact unwind for" )
33
+ message (CHECK_FAIL "no" )
34
+ set (HAVE_CXX_TRYCATCH false CACHE BOOL "C++ exception handling broken" )
35
+ message (WARNING "C++ exception handling will not work reliably due to incompatible compilers" )
36
+ else ()
37
+ message (CHECK_PASS "yes" )
38
+ set (HAVE_CXX_TRYCATCH true CACHE BOOL "C++ exception handling works" )
41
39
endif ()
42
40
41
+ endif ()
43
42
44
- endfunction (abi_check)
45
- abi_check()
43
+ endblock()
46
44
47
45
48
46
# --- ISO_Fortran_binding.h header
49
- function (check_iso_fortran_binding)
47
+ block()
48
+
50
49
check_include_file("ISO_Fortran_binding.h" HAVE_ISO_FORTRAN_BINDING_H)
51
50
52
51
# here we assume C and Fortran compilers are from the same vendor
@@ -77,39 +76,73 @@ if(HAVE_ISO_FORTRAN_BINDING_H)
77
76
)
78
77
endif ()
79
78
80
- endfunction ()
81
- check_iso_fortran_binding()
79
+ endblock ()
80
+
82
81
83
- # --- GCC < 12 can't do these
84
82
check_source_compiles(Fortran
85
- "program cstr
86
- use, intrinsic :: iso_c_binding, only : c_char
83
+ "program test
87
84
implicit none
88
- interface
89
- subroutine fun(s) bind(C)
90
- import :: c_char
91
- character(kind=c_char, len=:), pointer, intent(out) :: s
92
- end subroutine
93
- end interface
85
+ real :: a(1)
86
+ print '(L1)', is_contiguous(a)
87
+ end program"
88
+ f08contiguous
89
+ )
90
+
91
+ check_source_compiles(Fortran
92
+ "program abst
93
+
94
+ implicit none
95
+
96
+ type, abstract :: L1
97
+ integer, pointer :: bullseye(:,:)
98
+ end type L1
99
+
100
+ type, extends(L1) :: L2
101
+ integer, pointer :: arrow(:)
102
+ end type L2
103
+
104
+ class(L2), allocatable :: obj
105
+
94
106
end program
95
107
"
108
+ f03abstract
109
+ )
110
+
111
+ include (${CMAKE_CURRENT_LIST_DIR} /f08submod_bind.cmake)
112
+
113
+
114
+ block()
115
+
116
+ set (CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY" )
117
+
118
+ check_source_compiles(Fortran
119
+ "subroutine fun(i) bind(C)
120
+ use, intrinsic :: iso_c_binding
121
+ integer(C_INT), intent(in) :: i
122
+ end subroutine"
123
+ f03bind
124
+ )
125
+
126
+
127
+ # --- GCC < 12 can't do these
128
+ check_source_compiles(Fortran
129
+ "subroutine fun(s) bind(C)
130
+ use, intrinsic :: iso_c_binding
131
+ character(kind=c_char, len=:), pointer, intent(out) :: s
132
+ end subroutine"
96
133
HAVE_C_CHAR_PTR
97
134
)
98
135
99
136
check_source_compiles(Fortran
100
- "program string_view
101
- use, intrinsic :: iso_c_binding, only : c_char
102
- implicit none
103
- interface
104
- subroutine echo_c( str ) bind(C)
105
- import :: c_char
137
+ "subroutine echo_c( str ) bind(C)
138
+ use, intrinsic :: iso_c_binding
106
139
character(kind=c_char, len=:), allocatable, intent(in) :: str
107
- end subroutine
108
- end interface
109
- end program"
140
+ end subroutine"
110
141
HAVE_C_ALLOC_CHAR
111
142
)
112
143
144
+ endblock()
145
+
113
146
# --- fix errors about needing -fPIE
114
147
if (CMAKE_SYSTEM_NAME STREQUAL "Linux" )
115
148
include (CheckPIESupported)
0 commit comments