Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Results from trial sources during CMake config are now cached #49

Merged
merged 2 commits into from
Mar 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Fujitsu compiler support

## Changed
- Results from running trial sources during CMake config are now stored in the CMake cache

## [1.7.0] - 2023-11-29

### Fixed
Expand Down Expand Up @@ -74,7 +77,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Add `NVHPC.cmake` file for NVHPC support


## [1.3.6] - 2021-11-16

### Fixed
Expand Down
46 changes: 28 additions & 18 deletions cmake/check_intrinsic_kinds.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ include (fortran_try)
CHECK_Fortran_SOURCE_RUN (
${CMAKE_CURRENT_LIST_DIR}/trial_sources/LOGICAL_DEFAULT_KIND.F90
_LOGICAL_DEFAULT_KIND
"Default logical kind"
)

CHECK_Fortran_SOURCE_RUN (
${CMAKE_CURRENT_LIST_DIR}/trial_sources/INT_DEFAULT_KIND.F90
_INT_DEFAULT_KIND
"Default integer kind"
)
foreach (kind 8 16 32 64)
set(CMAKE_REQUIRED_FLAGS = -fpp)
Expand All @@ -16,44 +18,52 @@ foreach (kind 8 16 32 64)
CHECK_Fortran_SOURCE_RUN (
${CMAKE_CURRENT_LIST_DIR}/trial_sources/INT_KIND.F90
_ISO_INT${kind}
"Integer(${kind}) kind"
)

endforeach()

CHECK_Fortran_SOURCE_RUN (
${CMAKE_CURRENT_LIST_DIR}/trial_sources/REAL_DEFAULT_KIND.F90
_REAL_DEFAULT_KIND
"Default real kind"
)

CHECK_Fortran_SOURCE_RUN (
${CMAKE_CURRENT_LIST_DIR}/trial_sources/DOUBLE_DEFAULT_KIND.F90
_DOUBLE_DEFAULT_KIND
"Default double kind"
)

foreach (kind 32 64 128)
set(CMAKE_REQUIRED_FLAGS = -fpp)
set(CMAKE_REQUIRED_DEFINITIONS -D_KIND=REAL${kind})

try_compile (
code_compiles
${GFTL_SHARED_BINARY_DIR}
${CMAKE_CURRENT_LIST_DIR}/trial_sources/REAL_KIND.F90
CMAKE_FLAGS "-DCOMPILE_DEFINITIONS=${CMAKE_REQUIRED_DEFINITIONS}")
if (NOT DEFINED CACHE{GFTL_SHARED_ISO_REAL${kind}})

if (code_compiles)
CHECK_Fortran_SOURCE_RUN (
set(CMAKE_REQUIRED_FLAGS = -fpp)
set(CMAKE_REQUIRED_DEFINITIONS -D_KIND=REAL${kind})

try_compile (
code_compiles
${GFTL_SHARED_BINARY_DIR}
${CMAKE_CURRENT_LIST_DIR}/trial_sources/REAL_KIND.F90
CMAKE_FLAGS "-DCOMPILE_DEFINITIONS=${CMAKE_REQUIRED_DEFINITIONS}")

if (code_compiles)
CHECK_Fortran_SOURCE_RUN (
${CMAKE_CURRENT_LIST_DIR}/trial_sources/REAL_KIND.F90
_ISO_REAL${kind}
"Real(${kind}) kind"
)
endif ()

try_compile (
code_compiles
${GFTL_SHARED_BINARY_DIR}
${CMAKE_CURRENT_LIST_DIR}/trial_sources/REAL_KIND.F90
_ISO_REAL${kind}
)
CMAKE_FLAGS "-DCOMPILE_DEFINITIONS=${CMAKE_REQUIRED_DEFINITIONS}")

endif ()

try_compile (
code_compiles
${GFTL_SHARED_BINARY_DIR}
${CMAKE_CURRENT_LIST_DIR}/trial_sources/REAL_KIND.F90
CMAKE_FLAGS "-DCOMPILE_DEFINITIONS=${CMAKE_REQUIRED_DEFINITIONS}")


endforeach()


Expand Down
54 changes: 34 additions & 20 deletions cmake/fortran_try.cmake
Original file line number Diff line number Diff line change
@@ -1,29 +1,43 @@
macro (CHECK_FORTRAN_SOURCE_RUN file var)
macro (CHECK_FORTRAN_SOURCE_RUN file var docstr)

try_run (
run compile
${CMAKE_CURRENT_BINARY_DIR}
${file}
CMAKE_FLAGS "-DCOMPILE_DEFINITIONS=${CMAKE_REQUIRED_DEFINITIONS}"
RUN_OUTPUT_VARIABLE ${var}
)

# Successful runs return "0", which is opposite of CMake sense of "if":
if (NOT run)
string(STRIP ${${var}} ${var})
if (NOT CMAKE_REQUIRED_QUIET)
message(STATUS "Performing Test ${var}: SUCCESS (value=${${var}})")
endif ()

add_definitions(-D${var}=${${var}})

if (DEFINED CACHE{GFTL_SHARED${var}})
set( ${var} ${GFTL_SHARED${var}})
else ()
try_run (
run compile
${CMAKE_CURRENT_BINARY_DIR}
${file}
CMAKE_FLAGS "-DCOMPILE_DEFINITIONS=${CMAKE_REQUIRED_DEFINITIONS}"
RUN_OUTPUT_VARIABLE ${var}
)

# Successful runs return "0", which is opposite of CMake sense of "if":
if (NOT run)
string(STRIP ${${var}} ${var})
if (NOT CMAKE_REQUIRED_QUIET)
message(STATUS "Performing Test ${var}: SUCCESS (value=${${var}})")
endif ()

set (GFTL_SHARED${var}
${${var}}
CACHE
STRING
${docstr}
)

else ()

if (NOT CMAKE_REQUIRED_QUIET)
message(STATUS "Performing Test ${var}: FAILURE")
endif ()

if (NOT CMAKE_REQUIRED_QUIET)
message(STATUS "Performing Test ${var}: FAILURE")
endif ()

endif ()

if (NOT ${${var}} EQUAL "")
add_definitions(-D${var}=${${var}})
endif ()

endmacro (CHECK_FORTRAN_SOURCE_RUN)

Expand Down