[PATCH] D101842: [flang][cmake] Enable the new driver by default

Andrzej Warzynski via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 4 09:13:47 PDT 2021


awarzynski created this revision.
Herald added a subscriber: mgorny.
Herald added a reviewer: sscalpone.
awarzynski requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

With this patch:

- `FLANG_BUILD_NEW_DRIVER` is set to `On` by default (i.e. the new driver is enabled)
- Clang is automatically added to the list of dependencies.

By setting `FLANG_BUILD_NEW_DRIVER` to `Off`, the new driver will be
disabled and Clang will be removed from the list of dependencies.

I tried implementing this logic in Flang's top CMake script, but that's
too late for updating `LLVM_ENABLE_PROJECTS` (which is used to
enable/disable Clang).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D101842

Files:
  flang/CMakeLists.txt
  flang/README.md
  llvm/CMakeLists.txt


Index: llvm/CMakeLists.txt
===================================================================
--- llvm/CMakeLists.txt
+++ llvm/CMakeLists.txt
@@ -74,9 +74,17 @@
 if( LLVM_ENABLE_PROJECTS STREQUAL "all" )
   set( LLVM_ENABLE_PROJECTS ${LLVM_ALL_PROJECTS})
 endif()
-if ("flang" IN_LIST LLVM_ENABLE_PROJECTS AND NOT "mlir" IN_LIST LLVM_ENABLE_PROJECTS)
-  message(STATUS "Enabling MLIR as a dependency to flang")
-  list(APPEND LLVM_ENABLE_PROJECTS "mlir")
+
+option(FLANG_BUILD_NEW_DRIVER "Build the flang compiler driver" ON)
+if ("flang" IN_LIST LLVM_ENABLE_PROJECTS)
+  if (NOT "mlir" IN_LIST LLVM_ENABLE_PROJECTS)
+    message(STATUS "Enabling MLIR as a dependency to flang")
+    list(APPEND LLVM_ENABLE_PROJECTS "mlir")
+  endif()
+  if ( FLANG_BUILD_NEW_DRIVER AND NOT "clang" IN_LIST LLVM_ENABLE_PROJECTS)
+    message(STATUS "Enabling Clang as a dependency to flang")
+    list(APPEND LLVM_ENABLE_PROJECTS "clang")
+  endif()
 endif()
 
 # LLVM_ENABLE_PROJECTS_USED is `ON` if the user has ever used the
Index: flang/README.md
===================================================================
--- flang/README.md
+++ flang/README.md
@@ -69,16 +69,17 @@
 We highly recommend using the same compiler to compile both llvm and flang.
 
 The flang CMakeList.txt file uses
-the variable `LLVM_DIR` to find the installed LLVM components
-and
-the variable `MLIR_DIR` to find the installed MLIR components.
+* `LLVM_DIR` to find the installed LLVM components
+* `MLIR_DIR` to find the installed MLIR components
+* `CLANG_DIR` to find the installed Clang components
 
-To get the correct LLVM and MLIR libraries included in your flang build,
-define LLVM_DIR and MLIR_DIR on the cmake command line.
+To get the correct LLVM, MLIR and Clang libraries included in your flang build,
+define `LLVM_DIR` and `MLIR_DIR` on the cmake command line.
 ```
 LLVM=<LLVM_BUILD_DIR>/lib/cmake/llvm \
 MLIR=<LLVM_BUILD_DIR>/lib/cmake/mlir \
-cmake -DLLVM_DIR=$LLVM -DMLIR_DIR=$MLIR ...
+CLANG=<LLVM_BUILD_DIR>/lib/cmake/clang \
+cmake -DLLVM_DIR=$LLVM -DMLIR_DIR=$MLIR -DCLANG_DIR=$CLANG ...
 ```
 where `LLVM_BUILD_DIR` is
 the top-level directory where LLVM was built.
@@ -140,23 +141,17 @@
 ### Build Flang out of tree
 ```
 cd ~/flang/build
-cmake -DLLVM_DIR=$LLVM -DMLIR_DIR=$MLIR ~/flang/src
+cmake -DLLVM_DIR=$LLVM -DMLIR_DIR=$MLIR -DCLANG_DIR=$CLANG ~/flang/src
 make
 ```
 
-### Build The New Flang Driver
-The new Flang driver, `flang-new`, is currently under active development and
-should be considered as an experimental feature. For this reason it is disabled
-by default. This will change once the new driver replaces the _throwaway_
-driver, `flang`.
-
-In order to build the new driver, add `-DFLANG_BUILD_NEW_DRIVER=ON` to your
-CMake invocation line. Additionally, when building out-of-tree, use `CLANG_DIR`
-(similarly to `LLVM_DIR` and `MLIR_DIR`) to find the installed Clang
-components.
-
-**Note:** `CLANG_DIR` is only required when building the new Flang driver,
-which currently depends on Clang.
+### Disable The New Flang Driver
+The new Flang compiler driver, `flang-new`, is implemented in terms of
+`clangDriver` and hence it introduces a dependency on Clang. This dependency is
+otherwise not required. If you do not require the new driver, you can disable
+it and remove Clang from the list of dependencies by adding
+`-DFLANG_BUILD_NEW_DRIVER=OFF` to your CMake invocation line. Also, when
+building out-of-tree, don't specify `CLANG_DIR`.
 
 # How to Run Tests
 
Index: flang/CMakeLists.txt
===================================================================
--- flang/CMakeLists.txt
+++ flang/CMakeLists.txt
@@ -2,8 +2,6 @@
 
 set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR ON)
 
-option(FLANG_BUILD_NEW_DRIVER "Build the flang compiler driver" OFF)
-
 # Flang requires C++17.
 set(CMAKE_CXX_STANDARD 17)
 set(CMAKE_CXX_STANDARD_REQUIRED TRUE)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101842.342767.patch
Type: text/x-patch
Size: 3858 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210504/796ef2d5/attachment.bin>


More information about the llvm-commits mailing list