[flang-commits] [flang] 621681e - [Flang] Fix multi-config generator builds

Andrzej Warzynski via flang-commits flang-commits at lists.llvm.org
Wed Aug 5 01:00:38 PDT 2020


Author: Andrzej Warzynski
Date: 2020-08-05T08:59:11+01:00
New Revision: 621681e3e59241c2ba9a4ac59047c46cdcc3c947

URL: https://github.com/llvm/llvm-project/commit/621681e3e59241c2ba9a4ac59047c46cdcc3c947
DIFF: https://github.com/llvm/llvm-project/commit/621681e3e59241c2ba9a4ac59047c46cdcc3c947.diff

LOG: [Flang] Fix multi-config generator builds

Based on https://reviews.llvm.org/D84022 with additional changes to
maintain out-of-tree builds.

Original commit message:
Currently the binaries are output directly into the bin subdirectory of
the build directory. This doesn't work correctly with multi-config
generators which should output the binaries into <CONFIG_NAME>/bin
instead.

The original patch was implemented by David Truby and the additional
changes added here were also proposed by David Truby.

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

Co-authored-by: David Truby <david.truby at arm.com>

Added: 
    

Modified: 
    flang/CMakeLists.txt
    flang/test/CMakeLists.txt
    flang/test/lit.cfg.py
    flang/test/lit.site.cfg.py.in
    flang/tools/f18/CMakeLists.txt

Removed: 
    


################################################################################
diff  --git a/flang/CMakeLists.txt b/flang/CMakeLists.txt
index f1aaa5c6473f..0e3228bff3d8 100644
--- a/flang/CMakeLists.txt
+++ b/flang/CMakeLists.txt
@@ -180,7 +180,12 @@ else()
          ${LLVM_INCLUDE_TESTS})
   set(FLANG_GTEST_AVAIL 1)
 
-  set(FLANG_BINARY_DIR ${CMAKE_BINARY_DIR}/tools/flang)
+  if(FLANG_STANDALONE_BUILD)
+    set(FLANG_BINARY_DIR ${CMAKE_BINARY_DIR}/tools/flang)
+  else()
+    set(FLANG_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
+  endif()
+
   set(BACKEND_PACKAGE_STRING "${PACKAGE_STRING}")
   if (LINK_WITH_FIR)
     set(MLIR_MAIN_SRC_DIR ${LLVM_MAIN_SRC_DIR}/../mlir/include ) # --src-root
@@ -194,8 +199,10 @@ endif()
 
 if(LINK_WITH_FIR)
   # tco tool and FIR lib output directories
-  set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/bin)
-  set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/lib)
+  if(FLANG_STANDALONE_BUILD)
+    set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/bin)
+    set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/lib)
+  endif()
   # Always build tco tool
   set(LLVM_BUILD_TOOLS ON)
   message(STATUS "Linking driver with FIR and LLVM")

diff  --git a/flang/test/CMakeLists.txt b/flang/test/CMakeLists.txt
index 7da1d94d84c4..a1532dc7141f 100644
--- a/flang/test/CMakeLists.txt
+++ b/flang/test/CMakeLists.txt
@@ -1,6 +1,10 @@
 # Test runner infrastructure for Flang. This configures the Flang test trees
 # for use by Lit, and delegates to LLVM's lit test handlers.
 
+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)

diff  --git a/flang/test/lit.cfg.py b/flang/test/lit.cfg.py
index 8ad5a9b6357f..25c63890832f 100644
--- a/flang/test/lit.cfg.py
+++ b/flang/test/lit.cfg.py
@@ -25,9 +25,9 @@
 config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell)
 
 # suffixes: A list of file extensions to treat as test files.
-config.suffixes = ['.f', '.F', '.ff','.FOR', '.for', '.f77', '.f90', '.F90',
+config.suffixes = ['.f', '.F', '.ff', '.FOR', '.for', '.f77', '.f90', '.F90',
                    '.ff90', '.f95', '.F95', '.ff95', '.fpp', '.FPP', '.cuf',
-                   '.CUF', '.f18', '.F18', '.fir' ]
+                   '.CUF', '.f18', '.F18', '.fir']
 
 config.substitutions.append(('%PATH%', config.environment['PATH']))
 
@@ -48,11 +48,12 @@
 llvm_config.with_environment('PATH', config.flang_tools_dir, append_path=True)
 llvm_config.with_environment('PATH', config.llvm_tools_dir, append_path=True)
 
-# For builds with FIR, set path for tco and enable related tests
-if config.flang_llvm_tools_dir != "" :
-  config.available_features.add('fir')
-  if config.llvm_tools_dir != config.flang_llvm_tools_dir :
-    llvm_config.with_environment('PATH', config.flang_llvm_tools_dir, append_path=True)
+if config.flang_standalone_build:
+    # For builds with FIR, set path for tco and enable related tests
+    if config.flang_llvm_tools_dir != "":
+        config.available_features.add('fir')
+        if config.llvm_tools_dir != config.flang_llvm_tools_dir:
+            llvm_config.with_environment('PATH', config.flang_llvm_tools_dir, append_path=True)
 
 # For each occurrence of a flang tool name, replace it with the full path to
 # the build directory holding that tool.
@@ -61,7 +62,11 @@
     extra_args=["-intrinsic-module-directory "+config.flang_intrinsic_modules_dir],
     unresolved='fatal')
 ]
-llvm_config.add_tool_substitutions(tools, [config.flang_llvm_tools_dir])
+
+if config.flang_standalone_build:
+    llvm_config.add_tool_substitutions(tools, [config.flang_llvm_tools_dir])
+else:
+    llvm_config.add_tool_substitutions(tools, config.llvm_tools_dir)
 
 # Enable libpgmath testing
 result = lit_config.params.get("LIBPGMATH")

diff  --git a/flang/test/lit.site.cfg.py.in b/flang/test/lit.site.cfg.py.in
index e8e2945a2cbf..10ec13208154 100644
--- a/flang/test/lit.site.cfg.py.in
+++ b/flang/test/lit.site.cfg.py.in
@@ -9,6 +9,7 @@ config.flang_tools_dir = "@FLANG_TOOLS_DIR@"
 config.flang_intrinsic_modules_dir = "@FLANG_INTRINSIC_MODULES_DIR@"
 config.flang_llvm_tools_dir = "@CMAKE_BINARY_DIR@/bin"
 config.python_executable = "@PYTHON_EXECUTABLE@"
+config.flang_standalone_build = @FLANG_STANDALONE_BUILD@
 
 # Support substitution of the tools_dir with user parameters. This is
 # used when we can't determine the tool dir at configuration time.

diff  --git a/flang/tools/f18/CMakeLists.txt b/flang/tools/f18/CMakeLists.txt
index 46c38fa43a2e..6103117123ee 100644
--- a/flang/tools/f18/CMakeLists.txt
+++ b/flang/tools/f18/CMakeLists.txt
@@ -59,8 +59,24 @@ add_custom_target(module_files ALL DEPENDS ${MODULE_FILES})
 install(TARGETS f18 DESTINATION bin)
 
 set(FLANG_INTRINSIC_MODULES_DIR ${FLANG_BINARY_DIR}/include/flang)
-configure_file(${CMAKE_CURRENT_SOURCE_DIR}/flang.sh.in ${CMAKE_BINARY_DIR}/tools/flang/bin/flang @ONLY)
-file(COPY ${CMAKE_BINARY_DIR}/tools/flang/bin/flang DESTINATION ${CMAKE_BINARY_DIR}/bin FILE_PERMISSIONS OWNER_EXECUTE OWNER_READ OWNER_WRITE)
+
+# This flang shell script will only work in a POSIX shell.
+if (NOT WIN32)
+  if (FLANG_STANDALONE_BUILD)
+    configure_file(${CMAKE_CURRENT_SOURCE_DIR}/flang.sh.in ${CMAKE_BINARY_DIR}/tools/flang/bin/flang @ONLY)
+    file(COPY ${CMAKE_BINARY_DIR}/tools/flang/bin/flang DESTINATION ${CMAKE_BINARY_DIR}/bin FILE_PERMISSIONS OWNER_EXECUTE OWNER_READ OWNER_WRITE)
+  else()
+    configure_file(${CMAKE_CURRENT_SOURCE_DIR}/flang.sh.in
+      ${CMAKE_CURRENT_BINARY_DIR}/tools/flang/bin/flang @ONLY)
+    add_custom_command(TARGET f18
+        POST_BUILD
+          COMMAND ${CMAKE_COMMAND} -E copy
+          ${CMAKE_CURRENT_BINARY_DIR}/tools/flang/bin/flang
+          ${LLVM_RUNTIME_OUTPUT_INTDIR}/flang
+            COMMAND chmod +x ${LLVM_RUNTIME_OUTPUT_INTDIR}/flang)
+  endif()
+endif()
+
 # The flang script to be installed needs a 
diff erent path to the headers.
 set(FLANG_INTRINSIC_MODULES_DIR ${CMAKE_INSTALL_PREFIX}/include/flang)
 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/flang.sh.in ${FLANG_BINARY_DIR}/bin/flang-install.sh @ONLY)


        


More information about the flang-commits mailing list