Skip to content

Commit

Permalink
Merge pull request #48 from Goddard-Fortran-Ecosystem/cmake-cache-sou…
Browse files Browse the repository at this point in the history
…rce-compilation-tests

CMake: Don't rerun source-compilation tests if they've already run
  • Loading branch information
tclune authored Mar 3, 2024
2 parents 3979699 + 9fe53d4 commit 7b13e64
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 72 deletions.
54 changes: 54 additions & 0 deletions cmake/CheckFortranSource.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
function (CHECK_FORTRAN_SOURCE_RUN file var)
if (NOT DEFINED ${var})
try_run (
run compile
${CMAKE_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 compile OR run)
if (NOT CMAKE_REQUIRED_QUIET)
message(STATUS "Performing Test ${var}: FAILURE")
endif ()
return()
endif()

string(STRIP "${${var}}" ${var})
if (NOT CMAKE_REQUIRED_QUIET)
message(STATUS "Performing Test ${var}: SUCCESS (value=${${var}})")
endif ()
set(${var} ${${var}} CACHE STRING "" FORCE)

endif()
add_definitions(-D${var}=${${var}})
endfunction (CHECK_FORTRAN_SOURCE_RUN)


function (CHECK_FORTRAN_SOURCE_COMPILE file var)
if (NOT DEFINED ${var})
try_compile (
code_compiles
${CMAKE_BINARY_DIR}
${file}
CMAKE_FLAGS "-DCOMPILE_DEFINITIONS=${CMAKE_REQUIRED_DEFINITIONS}"
)

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

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

set(${var} ${${var}} CACHE STRING "" FORCE)
endif()
add_definitions(-D${var})
endfunction (CHECK_FORTRAN_SOURCE_COMPILE)
2 changes: 1 addition & 1 deletion cmake/check_intrinsic_kinds.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include (fortran_try)
include (CheckFortranSource)

CHECK_Fortran_SOURCE_RUN (
${CMAKE_CURRENT_LIST_DIR}/trial_sources/LOGICAL_DEFAULT_KIND.F90
Expand Down
71 changes: 0 additions & 71 deletions cmake/fortran_try.cmake

This file was deleted.

0 comments on commit 7b13e64

Please sign in to comment.