[flang-commits] [flang] 1c5d121 - [flang] Handle Flang examples consistently with LLVM.

Slava Zakharin via flang-commits flang-commits at lists.llvm.org
Tue Mar 14 13:09:03 PDT 2023


Author: Slava Zakharin
Date: 2023-03-14T13:08:43-07:00
New Revision: 1c5d12144058b4cfc3028401e8a16df933ff4dc6

URL: https://github.com/llvm/llvm-project/commit/1c5d12144058b4cfc3028401e8a16df933ff4dc6
DIFF: https://github.com/llvm/llvm-project/commit/1c5d12144058b4cfc3028401e8a16df933ff4dc6.diff

LOG: [flang] Handle Flang examples consistently with LLVM.

Without this change the problem is that flangOmpReport and
flangPrintFunctionNames libraries are not built under 'all',
but they are imported targets via LLVMExports.cmake so that
any out-of-tree build that configures upon LLVM+Flang package
will get this CMake error:
```
  The imported target "flangPrintFunctionNames" references the file

     ".../lib/flangPrintFunctionNames.so"

  but this file does not exist.
```

flang-aarch64-out-of-tree buildbot (https://lab.llvm.org/buildbot/#/builders/175)
does not catch this issue, because it does not enable Flang on the first stage.

This change gets rid of FLANG_BUILD_EXAMPLES in favor of LLVM_BUILD_EXAMPLES
and uses available LLVM CMake macros to add example executables/libraries.

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

Added: 
    

Modified: 
    flang/CMakeLists.txt
    flang/cmake/modules/AddFlang.cmake
    flang/docs/FlangDriver.md
    flang/examples/CMakeLists.txt
    flang/examples/ExternalHelloWorld/CMakeLists.txt
    flang/examples/FlangOmpReport/CMakeLists.txt
    flang/examples/PrintFlangFunctionNames/CMakeLists.txt
    flang/test/CMakeLists.txt
    flang/test/Examples/print-fns-calls.f90
    flang/test/Examples/print-fns-definitions.f90
    flang/test/Examples/print-fns-interfaces.f90
    flang/test/lit.site.cfg.py.in

Removed: 
    


################################################################################
diff  --git a/flang/CMakeLists.txt b/flang/CMakeLists.txt
index b048ea220e20c..9be6cd7eb1f59 100644
--- a/flang/CMakeLists.txt
+++ b/flang/CMakeLists.txt
@@ -430,11 +430,9 @@ if (FLANG_BUILD_TOOLS)
 endif()
 add_subdirectory(runtime)
 
-option(FLANG_BUILD_EXAMPLES "Build Flang example programs by default." OFF)
-if (FLANG_BUILD_EXAMPLES AND FLANG_STANDALONE_BUILD)
-  message(FATAL_ERROR "Examples are not supported in out-of-tree builds.")
+if (LLVM_INCLUDE_EXAMPLES)
+  add_subdirectory(examples)
 endif()
-add_subdirectory(examples)
 
 if (FLANG_INCLUDE_TESTS)
   add_subdirectory(test)

diff  --git a/flang/cmake/modules/AddFlang.cmake b/flang/cmake/modules/AddFlang.cmake
index c54c30dbf6df5..4332eb83c013e 100644
--- a/flang/cmake/modules/AddFlang.cmake
+++ b/flang/cmake/modules/AddFlang.cmake
@@ -127,4 +127,3 @@ macro(add_flang_symlink name dest)
   # Always generate install targets
   llvm_install_symlink(FLANG ${name} ${dest} ALWAYS_GENERATE)
 endmacro()
-

diff  --git a/flang/docs/FlangDriver.md b/flang/docs/FlangDriver.md
index e87df93907ef2..6c2a473820634 100644
--- a/flang/docs/FlangDriver.md
+++ b/flang/docs/FlangDriver.md
@@ -485,7 +485,7 @@ reports an error diagnostic and returns `nullptr`.
 For in-tree plugins, there is the CMake flag `FLANG_PLUGIN_SUPPORT`, enabled by
 default, that controls the exporting of executable symbols from `flang-new`,
 which plugins need access to. Additionally, there is the CMake flag
-`FLANG_BUILD_EXAMPLES`, turned off by default, that is used to control if the
+`LLVM_BUILD_EXAMPLES`, turned off by default, that is used to control if the
 example programs are built. This includes plugins that are in the
 `flang/example` directory and added as a `sub_directory` to the
 `flang/examples/CMakeLists.txt`, for example, the `PrintFlangFunctionNames`

diff  --git a/flang/examples/CMakeLists.txt b/flang/examples/CMakeLists.txt
index e1a309f1a7a97..23fea3920efb6 100644
--- a/flang/examples/CMakeLists.txt
+++ b/flang/examples/CMakeLists.txt
@@ -1,7 +1,3 @@
-if(NOT FLANG_BUILD_EXAMPLES)
-  set_property(DIRECTORY PROPERTY EXCLUDE_FROM_ALL ON)
-endif()
-
 add_subdirectory(ExternalHelloWorld)
 add_subdirectory(PrintFlangFunctionNames)
 add_subdirectory(FlangOmpReport)

diff  --git a/flang/examples/ExternalHelloWorld/CMakeLists.txt b/flang/examples/ExternalHelloWorld/CMakeLists.txt
index 3ca9feddf33e9..ec4a4b042291f 100644
--- a/flang/examples/ExternalHelloWorld/CMakeLists.txt
+++ b/flang/examples/ExternalHelloWorld/CMakeLists.txt
@@ -1,8 +1,8 @@
+set(LLVM_LINK_COMPONENTS
+  FortranRuntime
+  )
+
 # This test is not run by default as it requires input.
-add_executable(external-hello-world
+add_llvm_example(external-hello-world
   external-hello.cpp
 )
-
-target_link_libraries(external-hello-world
-  FortranRuntime
-)

diff  --git a/flang/examples/FlangOmpReport/CMakeLists.txt b/flang/examples/FlangOmpReport/CMakeLists.txt
index ab39b2ca4fb1e..bd5172a9fde59 100644
--- a/flang/examples/FlangOmpReport/CMakeLists.txt
+++ b/flang/examples/FlangOmpReport/CMakeLists.txt
@@ -1,4 +1,4 @@
-add_llvm_library(flangOmpReport
+add_llvm_example_library(flangOmpReport
   MODULE
   FlangOmpReport.cpp
   FlangOmpReportVisitor.cpp

diff  --git a/flang/examples/PrintFlangFunctionNames/CMakeLists.txt b/flang/examples/PrintFlangFunctionNames/CMakeLists.txt
index 7ba91fa4ef3c3..db20b5ee415b5 100644
--- a/flang/examples/PrintFlangFunctionNames/CMakeLists.txt
+++ b/flang/examples/PrintFlangFunctionNames/CMakeLists.txt
@@ -1,6 +1,6 @@
 # TODO: Note that this is currently only available on Linux.
 # On Windows, we would also have to specify e.g. `PLUGIN_TOOL`.
-add_llvm_library(flangPrintFunctionNames
+add_llvm_example_library(flangPrintFunctionNames
     MODULE
     PrintFlangFunctionNames.cpp
 

diff  --git a/flang/test/CMakeLists.txt b/flang/test/CMakeLists.txt
index 3252ff37bd21e..d04b69dc6974e 100644
--- a/flang/test/CMakeLists.txt
+++ b/flang/test/CMakeLists.txt
@@ -3,8 +3,8 @@
 add_subdirectory(lib)
 
 llvm_canonicalize_cmake_booleans(
-  FLANG_BUILD_EXAMPLES
   FLANG_STANDALONE_BUILD
+  LLVM_BUILD_EXAMPLES
   LLVM_BYE_LINK_INTO_TOOLS
   LLVM_ENABLE_PLUGINS
 )
@@ -74,7 +74,7 @@ if (FLANG_INCLUDE_TESTS)
   endif()
 endif()
 
-if (FLANG_BUILD_EXAMPLES)
+if (LLVM_BUILD_EXAMPLES)
   list(APPEND FLANG_TEST_DEPENDS
     flangPrintFunctionNames
     flangOmpReport

diff  --git a/flang/test/Examples/print-fns-calls.f90 b/flang/test/Examples/print-fns-calls.f90
index 426de0049663b..f45a0932ee215 100644
--- a/flang/test/Examples/print-fns-calls.f90
+++ b/flang/test/Examples/print-fns-calls.f90
@@ -1,5 +1,5 @@
 ! Check the Flang Print Function Names example plugin doesn't count/print function/subroutine calls (should only count definitions)
-! This requires that the examples are built (FLANG_BUILD_EXAMPLES=ON) to access flangPrintFunctionNames.so
+! This requires that the examples are built (LLVM_BUILD_EXAMPLES=ON) to access flangPrintFunctionNames.so
 
 ! REQUIRES: plugins, examples, shell
 

diff  --git a/flang/test/Examples/print-fns-definitions.f90 b/flang/test/Examples/print-fns-definitions.f90
index 98b8e64e66e7b..a1f342a246248 100644
--- a/flang/test/Examples/print-fns-definitions.f90
+++ b/flang/test/Examples/print-fns-definitions.f90
@@ -1,6 +1,6 @@
 ! Check the Flang Print Function Names example plugin prints and counts function/subroutine definitions
 ! This includes internal and external Function/Subroutines, but not Statement Functions
-! This requires that the examples are built (FLANG_BUILD_EXAMPLES=ON) to access flangPrintFunctionNames.so
+! This requires that the examples are built (LLVM_BUILD_EXAMPLES=ON) to access flangPrintFunctionNames.so
 
 ! REQUIRES: plugins, examples, shell
 

diff  --git a/flang/test/Examples/print-fns-interfaces.f90 b/flang/test/Examples/print-fns-interfaces.f90
index 0813fd4bd939f..c1e2f3488e232 100644
--- a/flang/test/Examples/print-fns-interfaces.f90
+++ b/flang/test/Examples/print-fns-interfaces.f90
@@ -1,6 +1,6 @@
 ! Check the Flang Print Function Names example plugin doesn't count/print Functions/Subroutines in interfaces
 ! (It should only count definitions, which will appear elsewhere for interfaced functions/subroutines)
-! This requires that the examples are built (FLANG_BUILD_EXAMPLES=ON) to access flangPrintFunctionNames.so
+! This requires that the examples are built (LLVM_BUILD_EXAMPLES=ON) to access flangPrintFunctionNames.so
 
 ! REQUIRES: plugins, examples, shell
 

diff  --git a/flang/test/lit.site.cfg.py.in b/flang/test/lit.site.cfg.py.in
index dbd84354e854e..46ba53ef672ef 100644
--- a/flang/test/lit.site.cfg.py.in
+++ b/flang/test/lit.site.cfg.py.in
@@ -16,7 +16,7 @@ config.flang_intrinsic_modules_dir = "@FLANG_INTRINSIC_MODULES_DIR@"
 config.flang_llvm_tools_dir = "@CMAKE_BINARY_DIR@/bin"
 config.flang_lib_dir = "@CMAKE_BINARY_DIR@/lib"
 config.flang_test_triple = "@FLANG_TEST_TARGET_TRIPLE@"
-config.flang_examples = @FLANG_BUILD_EXAMPLES@
+config.flang_examples = @LLVM_BUILD_EXAMPLES@
 config.python_executable = "@PYTHON_EXECUTABLE@"
 config.flang_standalone_build = @FLANG_STANDALONE_BUILD@
 config.has_plugins = @LLVM_ENABLE_PLUGINS@


        


More information about the flang-commits mailing list