Skip to content

Commit

Permalink
Support NEC Aurora compiler (#336)
Browse files Browse the repository at this point in the history
Support NEC Aurora compiler
  • Loading branch information
RobertPincus authored Jan 13, 2025
2 parents af6c185 + bbd5be6 commit 0a823c0
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 6 deletions.
19 changes: 13 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,24 @@ set_property(CACHE KERNEL_MODE PROPERTY STRINGS ${PREFERRED_KERNEL_MODES})

list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)

# CMake does not support the NEC compiler and usually mistakes it for GNU:
if(CMAKE_Fortran_COMPILER_ID STREQUAL GNU)
# Check whether the Fortran compiler in use is NEC:
include(CheckCompilerIsNEC)
check_compiler_is_nec(RTE_RRTMGP_Fortran_is_NEC Fortran)
endif()

# GNUInstallDirs issues a warning if CMAKE_SIZEOF_VOID_P is not defined, which
# is the case with NAG. One way to circumvent that is to enable C language for
# the project:
if(CMAKE_Fortran_COMPILER_ID STREQUAL NAG)
# is the case with NAG and NEC. One way to circumvent that is to enable C
# language for the project:
if(CMAKE_Fortran_COMPILER_ID STREQUAL NAG OR RTE_RRTMGP_Fortran_is_NEC)
enable_language(C)
endif()
include(GNUInstallDirs)

add_compile_options(
$<$<COMPILE_LANG_AND_ID:Fortran,GNU>:-ffree-line-length-none>
)
if(CMAKE_Fortran_COMPILER_ID STREQUAL GNU AND NOT RTE_RRTMGP_Fortran_is_NEC)
add_compile_options($<$<COMPILE_LANGUAGE:Fortran>:-ffree-line-length-none>)
endif()

set(CMAKE_Fortran_MODULE_DIRECTORY ${PROJECT_BINARY_DIR}/modules)

Expand Down
65 changes: 65 additions & 0 deletions cmake/CheckCompilerIsNEC.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# ~~~
# check_compiler_is_nec(<variable> <language>)
# ~~~
# Checks whether the <language> compiler in use is actually the NEC one (CMake
# does not support NEC compiler yet and usually mistakes it for GNU). Sets the
# internal cache <variable> to the result of the check. The requested <language>
# must be enabled. Supported languages are C, CXX and Fortran.
#
function(check_compiler_is_nec var lang)
if(DEFINED ${var})
return()
endif()

get_property(languages GLOBAL PROPERTY ENABLED_LANGUAGES)
if(NOT ${lang} IN_LIST languages)
message(FATAL_ERROR "Language ${lang} is not enabled")
endif()

if(${lang} STREQUAL "C")
include(CheckSymbolExists)
set(CMAKE_REQUIRED_QUIET 1)
check_symbol_exists(__NEC__ "" ${var})
elseif(${lang} STREQUAL "CXX")
include(CheckCXXSymbolExists)
set(CMAKE_REQUIRED_QUIET 1)
check_cxx_symbol_exists(__NEC__ "" ${var})
elseif(${lang} STREQUAL "Fortran")
set(check_source_file
"${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.F90"
)
file(
WRITE "${check_source_file}"
" program main
implicit none
#ifdef __NEC__
integer a
#else
choke me
#endif
#ifndef __NEC__
choke me
#else
integer b
#endif
a = 4
b = 2
end
"
)
try_compile(${var} "${PROJECT_BINARY_DIR}" "${check_source_file}")
else()
message(FATAL_ERROR "Language ${lang} is not supported")
endif()

if(${var})
set(${var} TRUE)
else()
set(${var} FALSE)
endif()

set(${var}
"${${var}}"
CACHE INTERNAL "Whether the ${lang} compiler is NEC"
)
endfunction()

0 comments on commit 0a823c0

Please sign in to comment.