|
| 1 | +From 19f267c75e84b72c4de42570be0c4222bb93aaff Mon Sep 17 00:00:00 2001 |
| 2 | +From: Brad King < [email protected]> |
| 3 | +Date: Thu, 21 Nov 2019 14:38:35 -0500 |
| 4 | +Subject: [PATCH] XL: Add support for Ninja and XL Fortran |
| 5 | + |
| 6 | +The Ninja generator's support for Fortran requires that source files |
| 7 | +be preprocessed explicitly first. However, the `xlf` compiler does |
| 8 | +not have a simple `-E` option or equivalent to do preprocessing. |
| 9 | +The only documented way to get preprocessed output is to use `-d` |
| 10 | +to leave it behind, but only at an inflexible location. |
| 11 | + |
| 12 | +Instead, create our own `cpp` wrapper script and substitute it for the |
| 13 | +real preprocessor using `-tF -B ...`. Teach the wrapper to map the |
| 14 | +`cpp` output to the location we need and then invoke the real `cpp` |
| 15 | +underneath. |
| 16 | + |
| 17 | +Fixes: #19450 |
| 18 | +--- |
| 19 | + Help/release/dev/xlf-ninja.rst | 5 ++++ |
| 20 | + Modules/CMakeDetermineCompilerId.cmake | 10 +++++++ |
| 21 | + Modules/CMakeDetermineFortranCompiler.cmake | 5 ++++ |
| 22 | + Modules/CMakeFortranCompiler.cmake.in | 1 + |
| 23 | + Modules/Compiler/XL-Fortran.cmake | 4 +++ |
| 24 | + Modules/Compiler/XL-Fortran/cpp | 29 +++++++++++++++++++++ |
| 25 | + 6 files changed, 54 insertions(+) |
| 26 | + create mode 100644 Help/release/dev/xlf-ninja.rst |
| 27 | + create mode 100755 Modules/Compiler/XL-Fortran/cpp |
| 28 | + |
| 29 | +diff --git a/Help/release/dev/xlf-ninja.rst b/Help/release/dev/xlf-ninja.rst |
| 30 | +new file mode 100644 |
| 31 | +index 0000000000..916e713008 |
| 32 | +--- /dev/null |
| 33 | ++++ b/Help/release/dev/xlf-ninja.rst |
| 34 | +@@ -0,0 +1,5 @@ |
| 35 | ++xlf-ninja |
| 36 | ++--------- |
| 37 | ++ |
| 38 | ++* The IBM XL Fortran compiler is now supported by the :generator:`Ninja` |
| 39 | ++ generator. |
| 40 | +diff --git a/Modules/CMakeDetermineCompilerId.cmake b/Modules/CMakeDetermineCompilerId.cmake |
| 41 | +index f7ef755aeb..0b3664c5de 100644 |
| 42 | +--- a/Modules/CMakeDetermineCompilerId.cmake |
| 43 | ++++ b/Modules/CMakeDetermineCompilerId.cmake |
| 44 | +@@ -182,6 +182,10 @@ function(CMAKE_DETERMINE_COMPILER_ID lang flagvar src) |
| 45 | + message(STATUS "The ${lang} compiler identification is unknown") |
| 46 | + endif() |
| 47 | + |
| 48 | ++ if(lang STREQUAL "Fortran" AND CMAKE_${lang}_COMPILER_ID STREQUAL "XL") |
| 49 | ++ set(CMAKE_${lang}_XL_CPP "${CMAKE_${lang}_COMPILER_ID_CPP}" PARENT_SCOPE) |
| 50 | ++ endif() |
| 51 | ++ |
| 52 | + set(CMAKE_${lang}_COMPILER_ID "${CMAKE_${lang}_COMPILER_ID}" PARENT_SCOPE) |
| 53 | + set(CMAKE_${lang}_PLATFORM_ID "${CMAKE_${lang}_PLATFORM_ID}" PARENT_SCOPE) |
| 54 | + set(CMAKE_${lang}_COMPILER_ARCHITECTURE_ID "${CMAKE_${lang}_COMPILER_ARCHITECTURE_ID}" PARENT_SCOPE) |
| 55 | +@@ -542,6 +546,12 @@ Id flags: ${testflags} ${CMAKE_${lang}_COMPILER_ID_FLAGS_ALWAYS} |
| 56 | + ERROR_VARIABLE CMAKE_${lang}_COMPILER_ID_OUTPUT |
| 57 | + RESULT_VARIABLE CMAKE_${lang}_COMPILER_ID_RESULT |
| 58 | + ) |
| 59 | ++ if("${CMAKE_${lang}_COMPILER_ID_OUTPUT}" MATCHES "exec: [^\n]*\\((/[^,\n]*/cpp),CMakeFortranCompilerId.F") |
| 60 | ++ set(_cpp "${CMAKE_MATCH_1}") |
| 61 | ++ if(EXISTS "${_cpp}") |
| 62 | ++ set(CMAKE_${lang}_COMPILER_ID_CPP "${_cpp}" PARENT_SCOPE) |
| 63 | ++ endif() |
| 64 | ++ endif() |
| 65 | + endif() |
| 66 | + |
| 67 | + # Check the result of compilation. |
| 68 | +diff --git a/Modules/CMakeDetermineFortranCompiler.cmake b/Modules/CMakeDetermineFortranCompiler.cmake |
| 69 | +index 5ddd64fae8..e8505417d6 100644 |
| 70 | +--- a/Modules/CMakeDetermineFortranCompiler.cmake |
| 71 | ++++ b/Modules/CMakeDetermineFortranCompiler.cmake |
| 72 | +@@ -271,6 +271,11 @@ include(CMakeFindBinUtils) |
| 73 | + include(Compiler/${CMAKE_Fortran_COMPILER_ID}-FindBinUtils OPTIONAL) |
| 74 | + unset(_CMAKE_PROCESSING_LANGUAGE) |
| 75 | + |
| 76 | ++if(CMAKE_Fortran_XL_CPP) |
| 77 | ++ set(_SET_CMAKE_Fortran_XL_CPP |
| 78 | ++ "set(CMAKE_Fortran_XL_CPP \"${CMAKE_Fortran_XL_CPP}\")") |
| 79 | ++endif() |
| 80 | ++ |
| 81 | + if(CMAKE_Fortran_COMPILER_ARCHITECTURE_ID) |
| 82 | + set(_SET_CMAKE_Fortran_COMPILER_ARCHITECTURE_ID |
| 83 | + "set(CMAKE_Fortran_COMPILER_ARCHITECTURE_ID ${CMAKE_Fortran_COMPILER_ARCHITECTURE_ID})") |
| 84 | +diff --git a/Modules/CMakeFortranCompiler.cmake.in b/Modules/CMakeFortranCompiler.cmake.in |
| 85 | +index ae7b73ac4a..34f44aa542 100644 |
| 86 | +--- a/Modules/CMakeFortranCompiler.cmake.in |
| 87 | ++++ b/Modules/CMakeFortranCompiler.cmake.in |
| 88 | +@@ -6,6 +6,7 @@ set(CMAKE_Fortran_COMPILER_WRAPPER "@CMAKE_Fortran_COMPILER_WRAPPER@") |
| 89 | + set(CMAKE_Fortran_PLATFORM_ID "@CMAKE_Fortran_PLATFORM_ID@") |
| 90 | + set(CMAKE_Fortran_SIMULATE_ID "@CMAKE_Fortran_SIMULATE_ID@") |
| 91 | + set(CMAKE_Fortran_SIMULATE_VERSION "@CMAKE_Fortran_SIMULATE_VERSION@") |
| 92 | ++@_SET_CMAKE_Fortran_XL_CPP@ |
| 93 | + @_SET_CMAKE_Fortran_COMPILER_ARCHITECTURE_ID@ |
| 94 | + @SET_MSVC_Fortran_ARCHITECTURE_ID@ |
| 95 | + set(CMAKE_AR "@CMAKE_AR@") |
| 96 | +diff --git a/Modules/Compiler/XL-Fortran.cmake b/Modules/Compiler/XL-Fortran.cmake |
| 97 | +index c4fb09712a..1683dff4f0 100644 |
| 98 | +--- a/Modules/Compiler/XL-Fortran.cmake |
| 99 | ++++ b/Modules/Compiler/XL-Fortran.cmake |
| 100 | +@@ -18,3 +18,7 @@ string(APPEND CMAKE_Fortran_FLAGS_INIT " -qthreaded -qhalt=e") |
| 101 | + # xlf: 1501-214 (W) command option E reserved for future use - ignored |
| 102 | + set(CMAKE_Fortran_CREATE_PREPROCESSED_SOURCE) |
| 103 | + set(CMAKE_Fortran_CREATE_ASSEMBLY_SOURCE) |
| 104 | ++ |
| 105 | ++set(CMAKE_Fortran_PREPROCESS_SOURCE |
| 106 | ++ "<CMAKE_Fortran_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -qpreprocess -qnoobject -qsuppress=1517-020 -tF -B \"${CMAKE_CURRENT_LIST_DIR}/XL-Fortran/\" -WF,--cpp,\"${CMAKE_Fortran_XL_CPP}\",--out,<PREPROCESSED_SOURCE> <SOURCE>" |
| 107 | ++ ) |
| 108 | +diff --git a/Modules/Compiler/XL-Fortran/cpp b/Modules/Compiler/XL-Fortran/cpp |
| 109 | +new file mode 100755 |
| 110 | +index 0000000000..1fd62c26a0 |
| 111 | +--- /dev/null |
| 112 | ++++ b/Modules/Compiler/XL-Fortran/cpp |
| 113 | +@@ -0,0 +1,29 @@ |
| 114 | ++#!/usr/bin/env bash |
| 115 | ++ |
| 116 | ++# Source file. |
| 117 | ++src="$(printf %q "$1")" |
| 118 | ++shift |
| 119 | ++ |
| 120 | ++# Output file the compiler expects. |
| 121 | ++out="$(printf %q "$1")" |
| 122 | ++shift |
| 123 | ++ |
| 124 | ++# Create the file the compiler expects. It will check syntax. |
| 125 | ++>"$out" |
| 126 | ++ |
| 127 | ++cpp='cpp' |
| 128 | ++opts='' |
| 129 | ++while test "$#" != 0; do |
| 130 | ++ case "$1" in |
| 131 | ++ # Extract the option for the path to cpp. |
| 132 | ++ --cpp) shift; cpp="$(printf %q "$1")" ;; |
| 133 | ++ # Extract the option for our own output file. |
| 134 | ++ --out) shift; out="$(printf %q "$1")" ;; |
| 135 | ++ # Collect the rest of the command line. |
| 136 | ++ *) opts="$opts $(printf %q "$1")" ;; |
| 137 | ++ esac |
| 138 | ++ shift |
| 139 | ++done |
| 140 | ++ |
| 141 | ++# Execute the real preprocessor tool. |
| 142 | ++eval "exec $cpp $src $out $opts" |
| 143 | +-- |
| 144 | +2.24.1 |
| 145 | + |
0 commit comments