Skip to content

Commit

Permalink
cmake: control scope
Browse files Browse the repository at this point in the history
  • Loading branch information
scivision committed Jul 5, 2024
1 parent e20c022 commit 9cee709
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
16 changes: 13 additions & 3 deletions cmake/compilers.cmake
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
include(CheckSourceCompiles)

function(check_abi)

if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.25)
# check C and Fortran compiler ABI compatibility

if(NOT abi_ok)
message(CHECK_START "checking that C, C++, and Fortran compilers can link")
try_compile(abi_ok
${CMAKE_CURRENT_BINARY_DIR}/abi_check ${CMAKE_CURRENT_LIST_DIR}/abi_check
abi_check
PROJECT abi_check
SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/abi_check
)
if(abi_ok)
message(CHECK_PASS "OK")
Expand All @@ -20,14 +23,21 @@ if(NOT abi_ok)
endif()
endif()

endif()

set(CMAKE_TRY_COMPILE_TARGET_TYPE "EXECUTABLE")

check_source_compiles(Fortran
"program int
"program test
intrinsic :: random_init
end program"
HAVE_RANDOM_INIT
)

endfunction(check_abi)

check_abi()

# always do compiler options after all FindXXX and checks

if(CMAKE_Fortran_COMPILER_ID MATCHES "^Intel")
Expand Down
10 changes: 10 additions & 0 deletions cmake/curses.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ else()
FetchContent_MakeAvailable(CURSES)
endif()


function(check_getch)

# always true
# check_include_file("${curses_SOURCE_DIR}/curses.h" HAVE_CURSES_H)
# always true
Expand All @@ -39,6 +42,9 @@ endif()
# Rather than hard-code this fact, test dynamically (maybe PDCurses will implement this differently in the future).
set(CMAKE_REQUIRED_LIBRARIES ${CURSES_LIBRARIES})
set(CMAKE_REQUIRED_INCLUDES ${CURSES_INCLUDE_DIRS})

set(CMAKE_TRY_COMPILE_TARGET_TYPE "EXECUTABLE")

check_source_compiles(Fortran
"program test
use, intrinsic :: iso_c_binding, only : C_INT
Expand All @@ -58,3 +64,7 @@ end program
"
HAVE_Fortran_GETCH
)

endfunction(check_getch)

check_getch()

0 comments on commit 9cee709

Please sign in to comment.