[flang-commits] [flang] 8e1c09e - [flang] Build intrinsic .mod files in include/flang

Tim Keith via flang-commits flang-commits at lists.llvm.org
Mon Mar 15 08:03:42 PDT 2021


Author: Tim Keith
Date: 2021-03-15T08:03:02-07:00
New Revision: 8e1c09ee5f8066918c6c91982395f6449f97f056

URL: https://github.com/llvm/llvm-project/commit/8e1c09ee5f8066918c6c91982395f6449f97f056
DIFF: https://github.com/llvm/llvm-project/commit/8e1c09ee5f8066918c6c91982395f6449f97f056.diff

LOG: [flang] Build intrinsic .mod files in include/flang

The build was putting .mod files for intrinsic modules in
tools/flang/include/flang but the install puts them in include/flang,
as does the out-of-tree build. This confused things for the driver.
This change makes the build consistent with the install and simplifies
the flang script accordingly.

Also, clean up the cmake commands for building the .mod files.

Differential Revision: https://reviews.llvm.org/D98522

Added: 
    

Modified: 
    flang/CMakeLists.txt
    flang/test/CMakeLists.txt
    flang/tools/f18/CMakeLists.txt
    flang/tools/f18/flang

Removed: 
    


################################################################################
diff  --git a/flang/CMakeLists.txt b/flang/CMakeLists.txt
index 4ea0569ceb47..33e5521f6d5b 100644
--- a/flang/CMakeLists.txt
+++ b/flang/CMakeLists.txt
@@ -190,6 +190,7 @@ else()
   include_directories(SYSTEM ${MLIR_INCLUDE_DIR})
   include_directories(SYSTEM ${MLIR_TABLEGEN_OUTPUT_DIR})
 endif()
+set(FLANG_INTRINSIC_MODULES_DIR ${CMAKE_BINARY_DIR}/include/flang)
 
 if(FLANG_BUILD_NEW_DRIVER)
     # TODO: Remove when libclangDriver is lifted out of Clang

diff  --git a/flang/test/CMakeLists.txt b/flang/test/CMakeLists.txt
index 7328afc7ba02..905d491708eb 100644
--- a/flang/test/CMakeLists.txt
+++ b/flang/test/CMakeLists.txt
@@ -5,8 +5,6 @@ llvm_canonicalize_cmake_booleans(
   FLANG_STANDALONE_BUILD
 )
 
-set(FLANG_INTRINSIC_MODULES_DIR ${FLANG_BINARY_DIR}/include/flang)
-
 set(FLANG_TOOLS_DIR ${FLANG_BINARY_DIR}/bin)
 
 configure_lit_site_cfg(

diff  --git a/flang/tools/f18/CMakeLists.txt b/flang/tools/f18/CMakeLists.txt
index 41237fe06003..d84516161594 100644
--- a/flang/tools/f18/CMakeLists.txt
+++ b/flang/tools/f18/CMakeLists.txt
@@ -30,7 +30,6 @@ set(MODULES
   "__fortran_type_info"
 )
 
-set(include ${FLANG_BINARY_DIR}/include/flang)
 target_include_directories(f18
   PRIVATE
   ${CMAKE_CURRENT_BINARY_DIR}
@@ -38,27 +37,24 @@ target_include_directories(f18
 
 # Create module files directly from the top-level module source directory
 foreach(filename ${MODULES})
+  set(base ${FLANG_INTRINSIC_MODULES_DIR}/${filename})
   if(${filename} MATCHES "__fortran_type_info")
     set(depends "")
   elseif(${filename} MATCHES "__fortran_builtins")
-    set(depends ${include}/__fortran_type_info.mod)
+    set(depends ${FLANG_INTRINSIC_MODULES_DIR}/__fortran_type_info.mod)
   else()
-    set(depends ${include}/__fortran_builtins.mod)
+    set(depends ${FLANG_INTRINSIC_MODULES_DIR}/__fortran_builtins.mod)
   endif()
-  add_custom_command(OUTPUT ${include}/${filename}.mod
-    COMMAND f18 -fsyntax-only -I${include}
-      ${FLANG_SOURCE_DIR}/module/${filename}.f90
-    WORKING_DIRECTORY ${include}
+  add_custom_command(OUTPUT ${base}.mod
+    COMMAND f18 -fsyntax-only ${FLANG_SOURCE_DIR}/module/${filename}.f90
+    WORKING_DIRECTORY ${FLANG_INTRINSIC_MODULES_DIR}
     DEPENDS f18 ${FLANG_SOURCE_DIR}/module/${filename}.f90 ${depends}
   )
-  add_custom_command(OUTPUT ${include}/${filename}.f18.mod
-    DEPENDS ${include}/${filename}.mod
-    COMMAND ${CMAKE_COMMAND} -E
-      copy ${include}/${filename}.mod ${include}/${filename}.f18.mod)
-  list(APPEND MODULE_FILES ${include}/${filename}.mod)
-  list(APPEND MODULE_FILES ${include}/${filename}.f18.mod)
-  install(FILES ${include}/${filename}.mod DESTINATION include/flang)
-  install(FILES ${include}/${filename}.f18.mod DESTINATION include/flang)
+  add_custom_command(OUTPUT ${base}.f18.mod
+    DEPENDS ${base}.mod
+    COMMAND ${CMAKE_COMMAND} -E copy ${base}.mod ${base}.f18.mod)
+  list(APPEND MODULE_FILES ${base}.mod ${base}.f18.mod)
+  install(FILES ${base}.mod ${base}.f18.mod DESTINATION include/flang)
 endforeach()
 
 add_custom_target(module_files ALL DEPENDS ${MODULE_FILES})

diff  --git a/flang/tools/f18/flang b/flang/tools/f18/flang
index 7109cd7f547a..8dda836c86c4 100644
--- a/flang/tools/f18/flang
+++ b/flang/tools/f18/flang
@@ -8,11 +8,7 @@
 #===------------------------------------------------------------------------===#
 
 wd=$(cd $(dirname "$0")/.. && pwd)
-module_dir=$wd/include/flang
-if [[ ! -d $module_dir ]]; then
-  module_dir=$wd/tools/flang/include/flang
-fi
-opts="-module-suffix .f18.mod -intrinsic-module-directory $module_dir"
+opts="-module-suffix .f18.mod -intrinsic-module-directory $wd/include/flang"
 if ! $wd/bin/f18 $opts "$@"
 then status=$?
      echo flang: in $PWD, f18 failed with exit status $status: $wd/bin/f18 $opts "$@" >&2


        


More information about the flang-commits mailing list