[flang-commits] [flang] [flang] Put ISO_Fortran_binding.h where it can be easily used (PR #70129)

Pete Steinfeld via flang-commits flang-commits at lists.llvm.org
Tue Oct 24 14:46:53 PDT 2023


https://github.com/psteinfeld created https://github.com/llvm/llvm-project/pull/70129

The update stems from the discussion in
https://discourse.llvm.org/t/adding-flang-specific-header-files-to-clang/72442

This is my third attempt at this.  My second attempt was in pull request #69121.

This is my second attempt at this.  My first attempt was in pull request #68756.

This pull request has three changes from the second one:
- I put the test into the Driver directory rather than Examples so that it would get run without require the define LLVM_BUILD_EXAMPLES.
- When installing ISO_Fortran_binding.h, I changed the location where it was installed from.
- I changed the test so that it would work when flang was built with shared libraries.

Here's the information from my previous attempts:

I decided to put ISO_Fortran_binding.h in a place where it would be accessible with the include: "#include<ISO_Fortran_binding.h>" rather than "#include<fortran/ISO_Fortran_binding.h>" because this is what gfortran implements.

Note that the file is also installed into ".../include/flang", so if a user wanted to access the file from a compiler other than clang, it would be available.

I added a test in ".../flang/test/Driver".  To make the test work, I also needed to put ISO_Fortran_binding.h into the build area.

Although the flang project depends on clang, clang may not always be available in a flang build.  For example, when building just the "check-flang" target, the "clang" executable may not be available at the time the new test gets run. To account for this, I made the test's script check for the existence of the "clang" executable.  If "clang" is not available, it simply prints "PASS".  If it is available, it fully builds and executes the test.  On success, this will also print "PASS"

>From c4d305f62c5acda3cd02d69369a828b5bd1c809a Mon Sep 17 00:00:00 2001
From: Peter Steinfeld <psteinfeld at nvidia.com>
Date: Tue, 24 Oct 2023 14:35:05 -0700
Subject: [PATCH] [flang] Put ISO_Fortran_binding.h where it can be easily used

The update stems from the discussion in
https://discourse.llvm.org/t/adding-flang-specific-header-files-to-clang/72442

This is my third attempt at this.  My second attempt was in pull request

This is my second attempt at this.  My first attempt was in pull request

This pull request has three changes from the second one:
- I put the test into the Driver directory rather than Examples so that
it would get run without require the define LLVM_BUILD_EXAMPLES.
- When installing ISO_Fortran_binding.h, I changed the location where it
was installed from.
- I changed the test so that it would work when flang was built with
shared libraries.

Here's the information from my previous attempts:

I decided to put ISO_Fortran_binding.h in a place where it would be
accessible with the include: "#include<ISO_Fortran_binding.h>" rather
than "#include<fortran/ISO_Fortran_binding.h>" because this is what
gfortran implements.

Note that the file is also installed into ".../include/flang", so if a
user wanted to access the file from a compiler other than clang, it
would be available.

I added a test in ".../flang/test/Driver".  To make the test work, I also
needed to put ISO_Fortran_binding.h into the build area.

Although the flang project depends on clang, clang may not always be available
in a flang build.  For example, when building just the "check-flang" target,
the "clang" executable may not be available at the time the new test gets run.
To account for this, I made the test's script check for the existence of the
"clang" executable.  If "clang" is not available, it simply prints "PASS".  If
it is available, it fully builds and executes the test.  On success, this will
also print "PASS"
---
 flang/CMakeLists.txt | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/flang/CMakeLists.txt b/flang/CMakeLists.txt
index ac30da89995ed31..f81d3e33fe86c0c 100644
--- a/flang/CMakeLists.txt
+++ b/flang/CMakeLists.txt
@@ -276,6 +276,9 @@ endif()
 
 
 set(PACKAGE_VERSION "${LLVM_PACKAGE_VERSION}")
+if (NOT PACKAGE_VERSION)
+  set(PACKAGE_VERSION ${LLVM_VERSION_MAJOR})
+endif()
 
 
 if (NOT DEFINED FLANG_VERSION_MAJOR)
@@ -490,3 +493,17 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
     PATTERN "*.inc"
     )
 endif()
+
+# Put ISO_Fortran_binding.h into the include files of the build area now
+# so that we can run tests before installing
+include(GetClangResourceDir)
+get_clang_resource_dir(HEADER_BINARY_DIR PREFIX ${LLVM_LIBRARY_OUTPUT_INTDIR}/.. SUBDIR include)
+configure_file(
+  ${FLANG_SOURCE_DIR}/include/flang/ISO_Fortran_binding.h
+  ${HEADER_BINARY_DIR}/ISO_Fortran_binding.h)
+
+# And also install it into the install area
+get_clang_resource_dir(HEADER_INSTALL_DIR SUBDIR include)
+install(
+  FILES include/flang/ISO_Fortran_binding.h
+  DESTINATION ${HEADER_INSTALL_DIR} )



More information about the flang-commits mailing list