diff --git a/CMakeLists.txt b/CMakeLists.txt index 26f49a428..471ce6eda 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -59,6 +59,7 @@ endif() list( APPEND fyppFlags + "-DWITH_CBOOL=$" "-DWITH_QP=$" "-DWITH_XDP=$" "-DPROJECT_VERSION_MAJOR=${PROJECT_VERSION_MAJOR}" diff --git a/config/CMakeLists.txt b/config/CMakeLists.txt index f9a556966..10025c3e6 100644 --- a/config/CMakeLists.txt +++ b/config/CMakeLists.txt @@ -16,6 +16,15 @@ set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" PARENT_SCOPE) # Check for available features # Note: users can overwrite the automatic check by setting the value at configure time include(CheckFortranSourceRuns) +if (NOT DEFINED WITH_CBOOL) + check_fortran_source_runs( + "use, intrinsic :: iso_c_binding, only: c_bool; integer, parameter :: lk = kind(.true.) + if (c_bool == lk) stop 1 + end" + WITH_CBOOL + ) + set(WITH_CBOOL ${WITH_CBOOL} PARENT_SCOPE) +endif() if (NOT DEFINED WITH_QP) check_fortran_source_runs( "if (selected_real_kind(33) == -1) stop 1; end" diff --git a/config/template.cmake b/config/template.cmake index d01dafcce..9a0b15e8d 100644 --- a/config/template.cmake +++ b/config/template.cmake @@ -1,5 +1,6 @@ @PACKAGE_INIT@ +set("@PROJECT_NAME@_WITH_CBOOL" @WITH_CBOOL@) set("@PROJECT_NAME@_WITH_QP" @WITH_QP@) set("@PROJECT_NAME@_WITH_XDP" @WITH_XDP@) diff --git a/src/common.fypp b/src/common.fypp index f94b6ec1a..364a8ae72 100644 --- a/src/common.fypp +++ b/src/common.fypp @@ -3,6 +3,11 @@ #! Project version number #:set PROJECT_VERSION = "{}.{}.{}".format(PROJECT_VERSION_MAJOR, PROJECT_VERSION_MINOR, PROJECT_VERSION_PATCH) +#! Support for C_BOOL logical +#:if not defined("WITH_CBOOL") +#:set WITH_CBOOL = False +#:endif + #! Support for quadruple precision floating point numbers #:if not defined("WITH_QP") #:set WITH_QP = False @@ -53,7 +58,10 @@ #:set INT_KINDS_TYPES = list(zip(INT_KINDS, INT_TYPES)) #! Logical kinds to be considered during templating -#:set LOG_KINDS = ["lk", "c_bool"] +#:set LOG_KINDS = ["lk"] +#:if WITH_CBOOL +#:set LOG_KINDS = LOG_KINDS + ["c_bool"] +#:endif #! Logical types to be considered during templating #:set LOG_TYPES = ["logical({})".format(k) for k in LOG_KINDS] diff --git a/test/ascii/test_ascii.f90 b/test/ascii/test_ascii.f90 index 27256136a..5a8878632 100644 --- a/test/ascii/test_ascii.f90 +++ b/test/ascii/test_ascii.f90 @@ -6,7 +6,7 @@ module test_ascii is_digit, is_octal_digit, is_hex_digit, is_white, is_blank, & is_control, is_punctuation, is_graphical, is_printable, is_ascii, & to_lower, to_upper, to_title, to_sentence, reverse, LF, TAB, NUL, DEL - use stdlib_kinds, only : int8, int16, int32, int64, lk, c_bool + use stdlib_kinds, only : int8, int16, int32, int64, lk implicit none private diff --git a/test/string/CMakeLists.txt b/test/string/CMakeLists.txt index 59ee5cf86..f8e3c2323 100644 --- a/test/string/CMakeLists.txt +++ b/test/string/CMakeLists.txt @@ -1,3 +1,12 @@ +#### Pre-process: .fpp -> .f90 via Fypp + +# Create a list of the files to be preprocessed +set(fppFiles + test_string_assignment.fypp +) + +fypp_f90("${fyppFlags}" "${fppFiles}" outFiles) + ADDTEST(string_assignment) ADDTEST(string_operator) ADDTEST(string_intrinsic) diff --git a/test/string/test_string_assignment.f90 b/test/string/test_string_assignment.fypp similarity index 99% rename from test/string/test_string_assignment.f90 rename to test/string/test_string_assignment.fypp index e2e693995..e64bcc754 100644 --- a/test/string/test_string_assignment.f90 +++ b/test/string/test_string_assignment.fypp @@ -79,9 +79,11 @@ subroutine test_constructor(error) call check(error, string_type(.false.) == trim(flc)) if (allocated(error)) return +#:if WITH_CBOOL write(flc, '(g0)') .false._c_bool call check(error, string_type(.false._c_bool) == trim(flc)) if (allocated(error)) return +#:endif write(flc, '(g0)') .true._lk call check(error, string_type(.true._lk) == trim(flc))