[flang] Add cmake option to link with FIR and LLVM
authorTim Keith <tkeith@nvidia.com>
Wed, 13 Mar 2019 19:41:15 +0000 (12:41 -0700)
committerTim Keith <tkeith@nvidia.com>
Wed, 13 Mar 2019 19:41:15 +0000 (12:41 -0700)
The cmake option -DLINK_WITH_FIR=ON causes the f18 driver to be linked
against FIR and LLVM. When it is set to OFF (the default), the call into
FIR is #ifdef'd out.

The source in lib/FIR is always built; this option only affects linking.

Original-commit: flang-compiler/f18@69569edd4c6abbb7a66c0d8f3595858693a06996
Reviewed-on: https://github.com/flang-compiler/f18/pull/329

flang/CMakeLists.txt
flang/tools/f18/CMakeLists.txt
flang/tools/f18/f18.cc

index c07fe4d..b473fc3 100644 (file)
@@ -14,6 +14,8 @@
 
 cmake_minimum_required(VERSION 3.9.0)
 
+option(LINK_WITH_FIR "Link driver with FIR and LLVM" OFF)
+
 # Pass -DGCC=... to cmake to use a specific gcc installation.
 if( GCC )
   set(CMAKE_CXX_COMPILER "${GCC}/bin/g++")
@@ -49,7 +51,7 @@ endif()
 message(STATUS "Build Type: ${CMAKE_BUILD_TYPE}" )
 
 find_package(LLVM REQUIRED CONFIG)
-message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION} in ${LLVM_INSTALL_PREFIX}")
+message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION} in ${LLVM_DIR}")
 
 # Get names for the LLVM libraries
 #
@@ -70,8 +72,11 @@ message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION} in ${LLVM_INSTALL_PREFIX}")
 include_directories(${LLVM_INCLUDE_DIRS})
 add_definitions(${LLVM_DEFINITIONS})
 
-llvm_map_components_to_libnames(LLVM_COMMON_LIBS support)
-message(STATUS "LLVM libraries: ${LLVM_COMMON_LIBS}")
+if(LINK_WITH_FIR)
+  message(STATUS "Linking driver with FIR and LLVM")
+  llvm_map_components_to_libnames(LLVM_COMMON_LIBS support)
+  message(STATUS "LLVM libraries: ${LLVM_COMMON_LIBS}")
+endif()
 
 if(CMAKE_COMPILER_IS_GNUCXX OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
    if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
index df87112..e9aad66 100644 (file)
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+if(LINK_WITH_FIR)
+  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DLINK_WITH_FIR")
+  set(FORTRAN_FIR_LIB "FortranFIR")
+endif()
+
 add_executable(f18
   f18.cc
   dump.cc
@@ -21,6 +26,6 @@ target_link_libraries(f18
   FortranParser
   FortranEvaluate
   FortranSemantics
-#  FortranFIR
-#  ${LLVM_COMMON_LIBS}
+  ${FORTRAN_FIR_LIB}
+  ${LLVM_COMMON_LIBS}
 )
index 79bb0d2..6b773f6 100644 (file)
@@ -14,7 +14,7 @@
 
 // Temporary Fortran front end driver main program for development scaffolding.
 
-#ifdef FIR
+#ifdef LINK_WITH_FIR
 #include "../../lib/FIR/afforestation.h"
 #include "../../lib/FIR/graph-writer.h"
 #endif
@@ -240,9 +240,9 @@ std::string CompileFortran(std::string path, Fortran::parser::Options options,
     }
   }
   if (driver.dumpGraph) {
-#ifdef FIR
-    auto *fir{Fortran::FIR::CreateFortranIR(parseTree,
-        semanticsContext, driver.debugLinearFIR)};
+#ifdef LINK_WITH_FIR
+    auto *fir{Fortran::FIR::CreateFortranIR(
+        parseTree, semanticsContext, driver.debugLinearFIR)};
     Fortran::FIR::GraphWriter::print(*fir);
 #endif
     return {};