@@ -4,7 +4,8 @@ include(CheckIncludeFileCXX)
44
55# --- abi check: C++ and Fortran compiler ABI compatibility
66
7- function (abi_check)
7+ block()
8+
89if (NOT DEFINED abi_compile)
910
1011 message (CHECK_START "checking that C, C++, and Fortran compilers can link" )
@@ -21,32 +22,30 @@ else()
2122endif ()
2223
2324# 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 ()
4025
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" )
4139endif ()
4240
41+ endif ()
4342
44- endfunction (abi_check)
45- abi_check()
43+ endblock()
4644
4745
4846# --- ISO_Fortran_binding.h header
49- function (check_iso_fortran_binding)
47+ block()
48+
5049check_include_file("ISO_Fortran_binding.h" HAVE_ISO_FORTRAN_BINDING_H)
5150
5251# here we assume C and Fortran compilers are from the same vendor
@@ -77,39 +76,73 @@ if(HAVE_ISO_FORTRAN_BINDING_H)
7776 )
7877endif ()
7978
80- endfunction ()
81- check_iso_fortran_binding()
79+ endblock ()
80+
8281
83- # --- GCC < 12 can't do these
8482check_source_compiles(Fortran
85- "program cstr
86- use, intrinsic :: iso_c_binding, only : c_char
83+ "program test
8784implicit 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+
94106end program
95107"
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"
96133HAVE_C_CHAR_PTR
97134)
98135
99136check_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
106139character(kind=c_char, len=:), allocatable, intent(in) :: str
107- end subroutine
108- end interface
109- end program"
140+ end subroutine"
110141HAVE_C_ALLOC_CHAR
111142)
112143
144+ endblock()
145+
113146# --- fix errors about needing -fPIE
114147if (CMAKE_SYSTEM_NAME STREQUAL "Linux" )
115148 include (CheckPIESupported)
0 commit comments