Skip to content

Commit 1792d1d

Browse files
committed
rationalize ISO_Fortran_binding.h check
1 parent 7e8b184 commit 1792d1d

3 files changed

Lines changed: 55 additions & 44 deletions

File tree

‎CMakeLists.txt‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ endif()
2929
if(ffilesystem_fortran)
3030
enable_language(Fortran)
3131

32-
include(cmake/iso_fortran_binding.cmake)
32+
if(ffilesystem_iso_fortran_binding)
33+
include(cmake/iso_fortran_binding.cmake)
34+
endif()
3335
endif()
3436

3537
# --- RPATH handling for transitive dependencies

‎cmake/iso_fortran_binding.cmake‎

Lines changed: 51 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,57 @@
1-
if(ffilesystem_iso_fortran_binding)
2-
if(CMAKE_C_COMPILER_ID STREQUAL "AppleClang" AND CMAKE_Fortran_COMPILER_ID STREQUAL "LLVMFlang")
3-
find_program(brew_exe NAMES brew)
4-
if(brew_exe)
5-
execute_process(COMMAND ${brew_exe} --prefix flang
6-
OUTPUT_VARIABLE flang_prefix
7-
OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
8-
endif()
9-
find_path(ffilesystem_ISO_Fortran_binding_path NAMES ISO_Fortran_binding.h
10-
HINTS ${flang_prefix}/include
11-
PATH_SUFFIXES flang)
12-
if(ffilesystem_ISO_Fortran_binding_path)
13-
set(CMAKE_REQUIRED_INCLUDES ${ffilesystem_ISO_Fortran_binding_path})
1+
# AppleClang needs a hint to find Flang ISO_Fortran_binding.h since they are distinct compiler vendors
2+
if(NOT DEFINED ffilesystem_ISO_Fortran_binding_path AND
3+
CMAKE_C_COMPILER_ID STREQUAL "AppleClang" AND CMAKE_Fortran_COMPILER_ID STREQUAL "LLVMFlang")
4+
5+
6+
set(_flang_ifb_hint)
7+
8+
find_program(brew_exe NAMES brew)
9+
if(brew_exe)
10+
execute_process(COMMAND ${brew_exe} --prefix flang
11+
OUTPUT_VARIABLE flang_prefix
12+
OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET
13+
RESULT_VARIABLE _ret
14+
)
15+
if(_ret EQUAL 0)
16+
set(_flang_ifb_hint HINTS ${flang_prefix}/include NO_DEFAULT_PATH)
1417
endif()
1518
endif()
1619

17-
check_include_file("ISO_Fortran_binding.h" ffilesystem_ifb_ok)
18-
if(ffilesystem_ifb_ok)
19-
if(NOT DEFINED ffilesystem_HAVE_ISO_FORTRAN_BINDING)
20-
21-
message(CHECK_START "checking that ISO_Fortran_binding.h is usable for <string> interoperability")
22-
23-
try_run(ffilesystem_ifb_run ffilesystem_ifb_build
24-
SOURCES ${CMAKE_CURRENT_LIST_DIR}/ifb.c ${CMAKE_CURRENT_LIST_DIR}/ifb.f90
25-
CMAKE_FLAGS -DINCLUDE_DIRECTORIES=${CMAKE_REQUIRED_INCLUDES}
26-
COMPILE_OUTPUT_VARIABLE _ifb_build
27-
RUN_OUTPUT_STDOUT_VARIABLE _ifb_code
28-
RUN_OUTPUT_STDERR_VARIABLE _ifb_error
29-
)
30-
31-
string(STRIP "${_ifb_code}" _ifb_code)
32-
string(STRIP "${_ifb_error}" _ifb_error)
33-
34-
if(NOT ffilesystem_ifb_build)
35-
message(CHECK_FAIL "failed to compile ISO_Fortran_binding.h ${ffilesystem_ifb_build}
36-
${_ifb_build}")
37-
elseif(NOT ffilesystem_ifb_run EQUAL 0)
38-
message(CHECK_FAIL "failed to test ISO_Fortran_binding.h ${ffilesystem_ifb_run}
39-
${_ifb_code}
40-
${_ifb_error}")
41-
else()
42-
set(ffilesystem_HAVE_ISO_FORTRAN_BINDING true CACHE STRING "ISO_Fortran_binding.h test code")
43-
message(CHECK_PASS "OK: ${_ifb_code}")
44-
endif()
20+
find_path(ffilesystem_ISO_Fortran_binding_path
21+
NAMES ISO_Fortran_binding.h
22+
${_ifb_hint}
23+
PATH_SUFFIXES flang
24+
)
4525

46-
endif()
26+
if(ffilesystem_ISO_Fortran_binding_path)
27+
set(CMAKE_REQUIRED_INCLUDES ${ffilesystem_ISO_Fortran_binding_path})
28+
endif()
29+
endif()
30+
31+
check_include_file("ISO_Fortran_binding.h" ffilesystem_ifb_ok)
32+
if(ffilesystem_ifb_ok AND NOT DEFINED ffilesystem_HAVE_ISO_FORTRAN_BINDING)
33+
message(CHECK_START "check ISO_Fortran_binding.h for C++ <string> interoperability")
34+
35+
try_run(ffilesystem_ifb_run ffilesystem_ifb_build
36+
SOURCES ${CMAKE_CURRENT_LIST_DIR}/ifb.c ${CMAKE_CURRENT_LIST_DIR}/ifb.f90
37+
CMAKE_FLAGS -DINCLUDE_DIRECTORIES=${CMAKE_REQUIRED_INCLUDES}
38+
COMPILE_OUTPUT_VARIABLE _ifb_build
39+
RUN_OUTPUT_STDOUT_VARIABLE _ifb_code
40+
RUN_OUTPUT_STDERR_VARIABLE _ifb_error
41+
)
42+
43+
string(STRIP "${_ifb_code}" _ifb_code)
44+
string(STRIP "${_ifb_error}" _ifb_error)
45+
46+
if(NOT ffilesystem_ifb_build)
47+
message(CHECK_FAIL "failed to compile ISO_Fortran_binding.h ${ffilesystem_ifb_build}
48+
${_ifb_build}")
49+
elseif(NOT ffilesystem_ifb_run EQUAL 0)
50+
message(CHECK_FAIL "failed to run with ISO_Fortran_binding.h ${ffilesystem_ifb_run}
51+
${_ifb_code}
52+
${_ifb_error}")
53+
else()
54+
set(ffilesystem_HAVE_ISO_FORTRAN_BINDING true CACHE STRING "ISO_Fortran_binding.h test code")
55+
message(CHECK_PASS "OK")
4756
endif()
4857
endif()

‎cmake/stdcpp.cmake‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ if(ffilesystem_stdcpp_run EQUAL 0)
2929
message(VERBOSE "GNU libstdc++ ${ffilesystem_stdcpp_version} is new enough to not need -lstdc++")
3030
endif()
3131
else()
32-
message(VERBOSE "Did not determine GNU libstdc++ version ${ffilesystem_stdcpp_version}")
32+
message(VERBOSE "libstdc++ version ${ffilesystem_stdcpp_version}")
3333
endif()
3434
endif()
3535

0 commit comments

Comments
 (0)