Pārlūkot izejas kodu

Fujitsu: Add support for the Fujitsu compiler in Trad mode

Co-Author: Yuichiro Utsumi <[email protected]>
Chuck Atkins 4 gadi atpakaļ
vecāks
revīzija
3c867cff4a

+ 1 - 0
Help/manual/cmake-compile-features.7.rst

@@ -359,6 +359,7 @@ following :variable:`compiler ids <CMAKE_<LANG>_COMPILER_ID>` as of the
 versions specified for each:
 versions specified for each:
 
 
 * ``Cray``: Cray Compiler Environment version 8.1+.
 * ``Cray``: Cray Compiler Environment version 8.1+.
+* ``Fujitsu``: Fujitsu HPC compiler 4.0+.
 * ``PGI``: PGI version 12.10+.
 * ``PGI``: PGI version 12.10+.
 * ``NVHPC``: NVIDIA HPC compilers version 11.0+.
 * ``NVHPC``: NVIDIA HPC compilers version 11.0+.
 * ``TI``: Texas Instruments compiler.
 * ``TI``: Texas Instruments compiler.

+ 1 - 0
Help/variable/CMAKE_LANG_COMPILER_ID.rst

@@ -19,6 +19,7 @@ include:
   Cray = Cray Compiler (cray.com)
   Cray = Cray Compiler (cray.com)
   Embarcadero, Borland = Embarcadero (embarcadero.com)
   Embarcadero, Borland = Embarcadero (embarcadero.com)
   Flang = Flang LLVM Fortran Compiler
   Flang = Flang LLVM Fortran Compiler
+  Fujitsu = Fujitsu HPC compiler (Trad mode)
   G95 = G95 Fortran (g95.org)
   G95 = G95 Fortran (g95.org)
   GNU = GNU Compiler Collection (gcc.gnu.org)
   GNU = GNU Compiler Collection (gcc.gnu.org)
   GHS = Green Hills Software (www.ghs.com)
   GHS = Green Hills Software (www.ghs.com)

+ 1 - 1
Modules/CMakeCheckCompilerFlagCommonPatterns.cmake

@@ -8,7 +8,7 @@
 
 
 macro (CHECK_COMPILER_FLAG_COMMON_PATTERNS _VAR)
 macro (CHECK_COMPILER_FLAG_COMMON_PATTERNS _VAR)
   set(${_VAR}
   set(${_VAR}
-    FAIL_REGEX "[Uu]nrecogni[sz]ed .*option"               # GNU, NAG
+    FAIL_REGEX "[Uu]nrecogni[sz]ed .*option"               # GNU, NAG, Fujitsu
     FAIL_REGEX "switch .* is no longer supported"          # GNU
     FAIL_REGEX "switch .* is no longer supported"          # GNU
     FAIL_REGEX "unknown .*option"                          # Clang
     FAIL_REGEX "unknown .*option"                          # Clang
     FAIL_REGEX "optimization flag .* not supported"        # Clang
     FAIL_REGEX "optimization flag .* not supported"        # Clang

+ 23 - 2
Modules/CMakeDetermineCompilerId.cmake

@@ -165,6 +165,25 @@ function(CMAKE_DETERMINE_COMPILER_ID lang flagvar src)
     endif()
     endif()
   endif()
   endif()
 
 
+  # The Fujitsu compiler does not always convey version information through
+  # preprocessor symbols so we extract through command line info
+  if (CMAKE_${lang}_COMPILER_ID STREQUAL "Fujitsu")
+    if(NOT CMAKE_${lang}_COMPILER_VERSION)
+      execute_process(
+        COMMAND "${CMAKE_${lang}_COMPILER}" -V
+        OUTPUT_VARIABLE output
+        ERROR_VARIABLE output
+        RESULT_VARIABLE result
+        TIMEOUT 10
+      )
+      if (result EQUAL 0)
+        if (output MATCHES [[Fujitsu [^ ]* Compiler ([0-9]+\.[0-9]+\.[0-9]+)]])
+          set(CMAKE_${lang}_COMPILER_VERSION "${CMAKE_MATCH_1}")
+        endif()
+      endif()
+    endif()
+  endif()
+
   # if the format is unknown after all files have been checked, put "Unknown" in the cache
   # if the format is unknown after all files have been checked, put "Unknown" in the cache
   if(NOT CMAKE_EXECUTABLE_FORMAT)
   if(NOT CMAKE_EXECUTABLE_FORMAT)
     set(CMAKE_EXECUTABLE_FORMAT "Unknown" CACHE INTERNAL "Executable file format")
     set(CMAKE_EXECUTABLE_FORMAT "Unknown" CACHE INTERNAL "Executable file format")
@@ -830,8 +849,10 @@ function(CMAKE_DETERMINE_COMPILER_ID_CHECK lang file)
         string(REGEX REPLACE "\\.0+([0-9])" ".\\1" COMPILER_VERSION "${COMPILER_VERSION}")
         string(REGEX REPLACE "\\.0+([0-9])" ".\\1" COMPILER_VERSION "${COMPILER_VERSION}")
       endif()
       endif()
       if("${info}" MATCHES "INFO:compiler_version_internal\\[([^]\"]*)\\]")
       if("${info}" MATCHES "INFO:compiler_version_internal\\[([^]\"]*)\\]")
-        string(REGEX REPLACE "^0+([0-9])" "\\1" COMPILER_VERSION_INTERNAL "${CMAKE_MATCH_1}")
-        string(REGEX REPLACE "\\.0+([0-9])" ".\\1" COMPILER_VERSION_INTERNAL "${COMPILER_VERSION_INTERNAL}")
+        set(COMPILER_VERSION_INTERNAL "${CMAKE_MATCH_1}")
+        string(REGEX REPLACE "^0+([0-9]+)" "\\1" COMPILER_VERSION_INTERNAL "${COMPILER_VERSION_INTERNAL}")
+        string(REGEX REPLACE "\\.0+([0-9]+)" ".\\1" COMPILER_VERSION_INTERNAL "${COMPILER_VERSION_INTERNAL}")
+        string(STRIP "${COMPILER_VERSION_INTERNAL}" COMPILER_VERSION_INTERNAL)
       endif()
       endif()
       foreach(comp MAJOR MINOR PATCH TWEAK)
       foreach(comp MAJOR MINOR PATCH TWEAK)
         foreach(digit 1 2 3 4 5 6 7 8 9)
         foreach(digit 1 2 3 4 5 6 7 8 9)

+ 9 - 0
Modules/CMakeFortranCompilerId.F.in

@@ -136,6 +136,15 @@
 #define COMPILER_VERSION_MAJOR DEC(__NAG_COMPILER_RELEASE/10)
 #define COMPILER_VERSION_MAJOR DEC(__NAG_COMPILER_RELEASE/10)
 #define COMPILER_VERSION_MINOR DEC(__NAG_COMPILER_RELEASE % 10)
 #define COMPILER_VERSION_MINOR DEC(__NAG_COMPILER_RELEASE % 10)
 #define COMPILER_VERSION_PATCH DEC(__NAG_COMPILER_BUILD)
 #define COMPILER_VERSION_PATCH DEC(__NAG_COMPILER_BUILD)
+#elif defined(__FUJITSU)
+        PRINT *, 'INFO:compiler[Fujitsu]'
+# if defined(__FRT_major__)
+#   define COMPILER_VERSION_MAJOR DEC(__FRT_major__)
+#   define COMPILER_VERSION_MINOR DEC(__FRT_minor__)
+#   define COMPILER_VERSION_PATCH DEC(__FRT_patchlevel__)
+# elif defined(__FRT_version__)
+        PRINT *, 'INFO:compiler_version['//__FRT_version__//']'
+# endif
 #else
 #else
         PRINT *, 'INFO:compiler[]'
         PRINT *, 'INFO:compiler[]'
 #endif
 #endif

+ 15 - 0
Modules/CMakeParseImplicitIncludeInfo.cmake

@@ -146,6 +146,21 @@ function(cmake_parse_implicit_include_line line lang id_var log_var state_var)
     endif()
     endif()
   endif()
   endif()
 
 
+  # Fujitsu compiler
+  if(CMAKE_${lang}_COMPILER_ID STREQUAL "Fujitsu" AND
+     line MATCHES "/ccpcom")
+    string(REGEX MATCHALL " (-I *|--sys_include=|--preinclude +)(\"[^\"]+\"|[^ \"]+)" incs "${line}")
+    foreach(inc IN LISTS incs)
+      string(REGEX REPLACE " (-I *|--sys_include=|--preinclude +)(\"[^\"]+\"|[^ \"]+)" "\\2" idir "${inc}")
+      list(APPEND rv "${idir}")
+    endforeach()
+    if(rv)
+      string(APPEND log "  got implicit includes via fujitsu ccpcom parser!\n")
+    else()
+      string(APPEND log "  warning: fujitsu ccpcom parse failed!\n")
+    endif()
+  endif()
+
   if(log)
   if(log)
     set(${log_var} "${log}" PARENT_SCOPE)
     set(${log_var} "${log}" PARENT_SCOPE)
   else()
   else()

+ 5 - 1
Modules/CMakePlatformId.h.in

@@ -256,8 +256,12 @@
   ('0' + ((n)>>4  & 0xF)), \
   ('0' + ((n)>>4  & 0xF)), \
   ('0' + ((n)     & 0xF))
   ('0' + ((n)     & 0xF))
 
 
+/* Construct a string literal encoding the version number. */
+#ifdef COMPILER_VERSION
+char const* info_version = "INFO" ":" "compiler_version[" COMPILER_VERSION "]";
+
 /* Construct a string literal encoding the version number components. */
 /* Construct a string literal encoding the version number components. */
-#ifdef COMPILER_VERSION_MAJOR
+#elif defined(COMPILER_VERSION_MAJOR)
 char const info_version[] = {
 char const info_version[] = {
   'I', 'N', 'F', 'O', ':',
   'I', 'N', 'F', 'O', ':',
   'c','o','m','p','i','l','e','r','_','v','e','r','s','i','o','n','[',
   'c','o','m','p','i','l','e','r','_','v','e','r','s','i','o','n','[',

+ 20 - 0
Modules/Compiler/Fujitsu-C.cmake

@@ -0,0 +1,20 @@
+# Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
+# file Copyright.txt or https://cmake.org/licensing for details.
+include(Compiler/Fujitsu)
+__compiler_fujitsu(C)
+
+if(CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 4)
+  set(CMAKE_C89_STANDARD_COMPILE_OPTION  -std=c89)
+  set(CMAKE_C89_EXTENSION_COMPILE_OPTION -std=gnu89)
+  set(CMAKE_C89_STANDARD__HAS_FULL_SUPPORT ON)
+
+  set(CMAKE_C99_STANDARD_COMPILE_OPTION  -std=c99)
+  set(CMAKE_C99_EXTENSION_COMPILE_OPTION -std=gnu99)
+  set(CMAKE_C99_STANDARD__HAS_FULL_SUPPORT ON)
+
+  set(CMAKE_C11_STANDARD_COMPILE_OPTION  -std=c11)
+  set(CMAKE_C11_EXTENSION_COMPILE_OPTION -std=gnu11)
+  set(CMAKE_C11_STANDARD__HAS_FULL_SUPPORT ON)
+endif()
+
+__compiler_check_default_language_standard(C 4 11)

+ 47 - 0
Modules/Compiler/Fujitsu-CXX.cmake

@@ -0,0 +1,47 @@
+# Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
+# file Copyright.txt or https://cmake.org/licensing for details.
+include(Compiler/Fujitsu)
+__compiler_fujitsu(CXX)
+
+#set(CMAKE_PCH_EXTENSION .pch)
+#set(CMAKE_PCH_EPILOGUE "#pragma hdrstop")
+#set(CMAKE_CXX_COMPILE_OPTIONS_USE_PCH --no_pch_messages -include <PCH_HEADER> --use_pch <PCH_FILE>)
+#set(CMAKE_CXX_COMPILE_OPTIONS_CREATE_PCH --no_pch_messages -include <PCH_HEADER> --create_pch <PCH_FILE>)
+
+# The Fujitsu compiler offers both a 98 and 03 mode.  These two are
+# essentially interchangeable as 03 simply provides clarity to some 98
+# ambiguyity.
+#
+# Re: Stroustrup's C++ FAQ:
+#   What is the difference between C++98 and C++03?
+#     From a programmer's view there is none. The C++03 revision of the
+#     standard was a bug fix release for implementers to ensure greater
+#     consistency and portability. In particular, tutorial and reference
+#     material describing C++98 and C++03 can be used interchangeably by all
+#     except compiler writers and standards gurus.
+#
+# Since CMake doesn't actually have an 03 mode and they're effectively
+# interchangeable then we're just going to explicitly use 03 mode in the
+# compiler when 98 is requested.
+
+# The version matching is messy here.  The std support seems to be related to
+# the compiler tweak version derived from the patch id in the version string.
+
+if(CMAKE_CXX_COMPILER_VERSION GREATER_EQUAL 4)
+  set(CMAKE_CXX98_STANDARD_COMPILE_OPTION  -std=c++03)
+  set(CMAKE_CXX98_EXTENSION_COMPILE_OPTION -std=gnu++03)
+  set(CMAKE_CXX98_STANDARD__HAS_FULL_SUPPORT ON)
+
+  set(CMAKE_CXX11_STANDARD_COMPILE_OPTION  -std=c++11)
+  set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION -std=gnu++11)
+  set(CMAKE_CXX11_STANDARD__HAS_FULL_SUPPORT ON)
+
+  set(CMAKE_CXX14_STANDARD_COMPILE_OPTION  -std=c++14)
+  set(CMAKE_CXX14_EXTENSION_COMPILE_OPTION -std=gnu++14)
+  set(CMAKE_CXX14_STANDARD__HAS_FULL_SUPPORT ON)
+
+  set(CMAKE_CXX17_STANDARD_COMPILE_OPTION  -std=c++17)
+  set(CMAKE_CXX17_EXTENSION_COMPILE_OPTION -std=gnu++17)
+endif()
+
+__compiler_check_default_language_standard(CXX 4 14)

+ 16 - 1
Modules/Compiler/Fujitsu-DetermineCompiler.cmake

@@ -1,2 +1,17 @@
 
 
-set(_compiler_id_pp_test "defined(__FUJITSU) || defined(__FCC_VERSION) || defined(__fcc_version)")
+set(_compiler_id_pp_test "defined(__FUJITSU) && !defined(__CLANG_FUJITSU)")
+
+set(_compiler_id_version_compute "
+# if defined(__FCC_version__)
+#   define @PREFIX@COMPILER_VERSION __FCC_version__
+# elif defined(__FCC_major__)
+#   define @PREFIX@COMPILER_VERSION_MAJOR @MACRO_DEC@(__FCC_major__)
+#   define @PREFIX@COMPILER_VERSION_MINOR @MACRO_DEC@(__FCC_minor__)
+#   define @PREFIX@COMPILER_VERSION_PATCH @MACRO_DEC@(__FCC_patchlevel__)
+# endif
+# if defined(__fcc_version)
+#   define @PREFIX@COMPILER_VERSION_INTERNAL @MACRO_DEC@(__fcc_version)
+# elif defined(__FCC_VERSION)
+#   define @PREFIX@COMPILER_VERSION_INTERNAL @MACRO_DEC@(__FCC_VERSION)
+# endif
+")

+ 16 - 0
Modules/Compiler/Fujitsu-Fortran.cmake

@@ -0,0 +1,16 @@
+include(Compiler/Fujitsu)
+__compiler_fujitsu(Fortran)
+
+set(CMAKE_Fortran_SUBMODULE_SEP ".")
+set(CMAKE_Fortran_SUBMODULE_EXT ".smod")
+
+set(CMAKE_Fortran_PREPROCESS_SOURCE
+  "<CMAKE_Fortran_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -Cpp -E <SOURCE> > <PREPROCESSED_SOURCE>")
+set(CMAKE_Fortran_COMPILE_OPTIONS_PREPROCESS_ON "-Cpp")
+
+set(CMAKE_Fortran_FORMAT_FIXED_FLAG "-Fixed")
+set(CMAKE_Fortran_FORMAT_FREE_FLAG "-Free")
+
+string(APPEND CMAKE_Fortran_FLAGS_DEBUG_INIT "")
+
+set(CMAKE_Fortran_MODDIR_FLAG "-M ")

+ 33 - 0
Modules/Compiler/Fujitsu.cmake

@@ -0,0 +1,33 @@
+# Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
+# file Copyright.txt or https://cmake.org/licensing for details.
+
+# This module is shared by multiple languages; use include blocker.
+if(__COMPILER_FUJITSU)
+  return()
+endif()
+set(__COMPILER_FUJITSU 1)
+
+include(Compiler/CMakeCommonCompilerMacros)
+
+macro(__compiler_fujitsu lang)
+  set(CMAKE_${lang}_VERBOSE_FLAG "-###")
+
+  # Initial configuration flags
+  string(APPEND CMAKE_${lang}_FLAGS_INIT " ")
+  string(APPEND CMAKE_${lang}_FLAGS_DEBUG_INIT " -g -O0")
+  string(APPEND CMAKE_${lang}_FLAGS_RELEASE_INIT " -O3 -DNDEBUG")
+  string(APPEND CMAKE_${lang}_FLAGS_RELWITHDEBINFO_INIT " -O2 -g -DNDEBUG")
+
+  # PIC flags
+  set(CMAKE_${lang}_COMPILE_OPTIONS_PIC "-fPIC")
+  set(CMAKE_${lang}_COMPILE_OPTIONS_PIE "-fPIE")
+
+  # Passing link options to the compiler
+  set(CMAKE_${lang}_LINKER_WRAPPER_FLAG "-Wl,")
+  set(CMAKE_${lang}_LINKER_WRAPPER_FLAG_SEP ",")
+
+  # How to actually call the compiler
+  set(CMAKE_${lang}_CREATE_PREPROCESSED_SOURCE
+  "<CMAKE_${lang}_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -E $<$<COMPILE_LANGUAGE:Fortran>:-Cpp> <SOURCE> > <PREPROCESSED_SOURCE>")
+  set(CMAKE_${lang}_CREATE_ASSEMBLY_SOURCE "<CMAKE_${lang}_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -S <SOURCE> -o <ASSEMBLY_SOURCE>")
+endmacro()

+ 8 - 0
Modules/Platform/Linux-Fujitsu-CXX.cmake

@@ -0,0 +1,8 @@
+# Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
+# file Copyright.txt or https://cmake.org/licensing for details
+
+include(Platform/Linux-Fujitsu)
+__linux_compiler_fujitsu(CXX)
+
+# Special sauce to propagate the -std=xxx flag when linking
+set(CMAKE_CXX_LINK_WITH_STANDARD_COMPILE_OPTION ON)

+ 17 - 0
Modules/Platform/Linux-Fujitsu.cmake

@@ -0,0 +1,17 @@
+# Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
+# file Copyright.txt or https://cmake.org/licensing for details.
+
+
+# This module is shared by multiple languages; use include blocker.
+if(__LINUX_COMPILER_FUJITSU)
+  return()
+endif()
+set(__LINUX_COMPILER_FUJITSU 1)
+
+macro(__linux_compiler_fujitsu lang)
+  set(CMAKE_${lang}_COMPILE_OPTIONS_PIC "-fPIC")
+  set(CMAKE_${lang}_COMPILE_OPTIONS_PIE "-fPIE")
+  set(CMAKE_${lang}_COMPILE_OPTIONS_VISIBILITY "-fvisibility=")
+  set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS "-fPIC")
+  set(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS "-shared")
+endmacro()