From 7fea5ec4d7f6275adb30ae42b0362e52977c0049 Mon Sep 17 00:00:00 2001 From: scivision Date: Sat, 9 Mar 2024 22:18:49 -0500 Subject: [PATCH] add checks that Flang f18 doesn't have yet --- CMakeLists.txt | 7 ++++--- cmake/f03abstract.cmake | 19 +++++++++++++++++++ cmake/f03charalloc.cmake | 11 +++++++++++ cmake/f03selectType.cmake | 29 +++++++++++++++++++++++++++++ cmake/f08execute.cmake | 9 +++++++++ cmake/f08kind.cmake | 2 ++ src/system/CMakeLists.txt | 2 ++ test/array/CMakeLists.txt | 2 ++ test/character/CMakeLists.txt | 8 +++++++- test/io/CMakeLists.txt | 4 ++++ test/pointer/CMakeLists.txt | 7 ++++++- test/submodule/CMakeLists.txt | 4 ++++ 12 files changed, 99 insertions(+), 5 deletions(-) create mode 100644 cmake/f03abstract.cmake create mode 100644 cmake/f03charalloc.cmake create mode 100644 cmake/f03selectType.cmake create mode 100644 cmake/f08execute.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 5827c40..373e68d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.19...3.28) +cmake_minimum_required(VERSION 3.19...3.29) if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR) message(FATAL_ERROR "Please specify build directory like: @@ -16,10 +16,11 @@ include(CheckSourceCompiles) # --- compiler checks -foreach(i IN ITEMS f03ieee f03utf8 - f08contig f08kind +foreach(i IN ITEMS f03abstract f03charalloc f03ieee f03utf8 f03selectType + f08contig f08execute f08kind f18abstract f18assumed_rank f18prop f18random f2023rank_integer f2023ternary f2023tokenize f2023real16) + include(cmake/${i}.cmake) endforeach() diff --git a/cmake/f03abstract.cmake b/cmake/f03abstract.cmake new file mode 100644 index 0000000..2894607 --- /dev/null +++ b/cmake/f03abstract.cmake @@ -0,0 +1,19 @@ +check_source_compiles(Fortran +"program abst + +implicit none + +type, abstract :: L1 +integer, pointer :: bullseye(:,:) +end type L1 + +type, extends(L1) :: L2 +integer, pointer :: arrow(:) +end type L2 + +class(L2), allocatable :: obj + +end program +" +f03abstract +) diff --git a/cmake/f03charalloc.cmake b/cmake/f03charalloc.cmake new file mode 100644 index 0000000..6fbb682 --- /dev/null +++ b/cmake/f03charalloc.cmake @@ -0,0 +1,11 @@ +check_source_compiles(Fortran +"program a +implicit none +character(:), allocatable :: x(:) + +character(:), allocatable :: flex(:), scalar + +flex = [character(5) :: 'hi', 'hello'] +end program" +f03charalloc +) diff --git a/cmake/f03selectType.cmake b/cmake/f03selectType.cmake new file mode 100644 index 0000000..5626e0b --- /dev/null +++ b/cmake/f03selectType.cmake @@ -0,0 +1,29 @@ +check_source_compiles(Fortran +" +program selectType +implicit none +real :: r +integer :: i + +call selector(r) +call selector(i) + +contains + +subroutine selector(x) + +class(*), intent(in) :: x + +select type (x) + type is (real) + print *, 'real' + type is (integer) + print *, 'integer' +end select + +end subroutine + +end program +" +f03selectType +) diff --git a/cmake/f08execute.cmake b/cmake/f08execute.cmake new file mode 100644 index 0000000..965ffe8 --- /dev/null +++ b/cmake/f08execute.cmake @@ -0,0 +1,9 @@ +check_source_compiles(Fortran +"program a +implicit none + +call execute_command_line('echo hello') + +end program" +f08execute +) diff --git a/cmake/f08kind.cmake b/cmake/f08kind.cmake index 4fa7371..9df0ff4 100644 --- a/cmake/f08kind.cmake +++ b/cmake/f08kind.cmake @@ -3,6 +3,8 @@ check_source_compiles(Fortran use, intrinsic:: iso_fortran_env, only: real128 use, intrinsic:: ieee_arithmetic, only: ieee_is_nan +real(real128) :: pi128 = 4*atan(1.0_real128) + print *, huge(0._real128) print *, ieee_is_nan(0._real128) diff --git a/src/system/CMakeLists.txt b/src/system/CMakeLists.txt index b3caad5..78a7fd7 100644 --- a/src/system/CMakeLists.txt +++ b/src/system/CMakeLists.txt @@ -2,6 +2,7 @@ set_property(DIRECTORY PROPERTY LABELS system) add_library(osdet OBJECT os_detect.f90) +if(f08execute) find_package(Python COMPONENTS Interpreter) add_executable(callpython call_python_script.f90) @@ -12,3 +13,4 @@ find_program(FFPLAY NAMES ffplay) add_executable(playsound play_sound.f90) add_test(NAME PlaySound COMMAND playsound ${CMAKE_CURRENT_SOURCE_DIR}/bell.aac) set_property(TEST PlaySound PROPERTY DISABLED $>) +endif() diff --git a/test/array/CMakeLists.txt b/test/array/CMakeLists.txt index f4caed2..3273ebe 100644 --- a/test/array/CMakeLists.txt +++ b/test/array/CMakeLists.txt @@ -1,7 +1,9 @@ set_property(DIRECTORY PROPERTY LABELS array) +if(f03selectType) add_executable(rotflip test_rot90.f90 ${PROJECT_SOURCE_DIR}/src/array/rot90.f90) add_test(NAME RotFlip COMMAND rotflip) +endif() add_executable(auto_allocate_array auto_allocate.f90) target_compile_options(auto_allocate_array PRIVATE diff --git a/test/character/CMakeLists.txt b/test/character/CMakeLists.txt index d1c43c1..15f817b 100644 --- a/test/character/CMakeLists.txt +++ b/test/character/CMakeLists.txt @@ -1,8 +1,14 @@ set_property(DIRECTORY PROPERTY LABELS character) -foreach(t IN ITEMS ascii character_allocatable character_array charlen +set(tests ascii character_array charlen color_text print_vs_write overwrite_stdout special_characters str2int utf8) + +if(f03charalloc) + list(APPEND tests character_allocatable) +endif() + +foreach(t IN LISTS tests) add_executable(${t} ${t}.f90) add_test(NAME ${t} COMMAND ${t}) endforeach() diff --git a/test/io/CMakeLists.txt b/test/io/CMakeLists.txt index 254fb07..8fa0487 100644 --- a/test/io/CMakeLists.txt +++ b/test/io/CMakeLists.txt @@ -6,12 +6,16 @@ foreach(t IN ITEMS devnull leading_zeros terminal_size) endforeach() +if(f03selectType) + add_library(logging OBJECT ${PROJECT_SOURCE_DIR}/src/io/logging.f90) add_executable(append_file append_file.f90 unlink.f90) target_link_libraries(append_file PRIVATE logging) add_test(NAME appendFile COMMAND append_file) +endif() + add_executable(termio ${PROJECT_SOURCE_DIR}/app/io/terminal_io.f90) add_test(NAME terminal COMMAND ${CMAKE_COMMAND} diff --git a/test/pointer/CMakeLists.txt b/test/pointer/CMakeLists.txt index 962de10..5d642dc 100644 --- a/test/pointer/CMakeLists.txt +++ b/test/pointer/CMakeLists.txt @@ -1,6 +1,11 @@ set_property(DIRECTORY PROPERTY LABELS pointer) -foreach(t IN ITEMS null_pointer derived_type) +set(tests null_pointer) +if(f03abstract) + list(APPEND tests derived_type) +endif() + +foreach(t IN LISTS tests) add_executable(${t} ${t}.f90) add_test(NAME ${t} COMMAND ${t}) endforeach() diff --git a/test/submodule/CMakeLists.txt b/test/submodule/CMakeLists.txt index cb36f52..a6f399f 100644 --- a/test/submodule/CMakeLists.txt +++ b/test/submodule/CMakeLists.txt @@ -1,5 +1,9 @@ set_property(DIRECTORY PROPERTY LABELS submodule) +if(NOT f03selectType) + return() +endif() + foreach(t IN ITEMS explicit procedure) add_executable(${t} ${t}.f90) add_test(NAME ${t} COMMAND ${t})