[flang-commits] [PATCH] D110851: [flang] Add a wrapper for Fortran main program

Jean Perier via Phabricator via flang-commits flang-commits at lists.llvm.org
Fri Oct 1 00:12:38 PDT 2021


jeanPerier updated this revision to Diff 376432.
jeanPerier added a comment.

Added LLVM licence to Fortran_main.c


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110851/new/

https://reviews.llvm.org/D110851

Files:
  flang/cmake/modules/AddFlang.cmake
  flang/runtime/CMakeLists.txt
  flang/runtime/Fortran_main.c


Index: flang/runtime/Fortran_main.c
===================================================================
--- /dev/null
+++ flang/runtime/Fortran_main.c
@@ -0,0 +1,22 @@
+//===-- runtime/Fortran_main.c --------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "flang/Runtime/main.h"
+#include "flang/Runtime/stop.h"
+
+/* main entry into PROGRAM */
+void _QQmain();
+
+/* C main stub */
+int main(int argc, const char *argv[], const char *envp[])
+{
+  RTNAME(ProgramStart)(argc, argv, envp);
+  _QQmain();
+  RTNAME(ProgramEndStatement)();
+  return 0;
+}
Index: flang/runtime/CMakeLists.txt
===================================================================
--- flang/runtime/CMakeLists.txt
+++ flang/runtime/CMakeLists.txt
@@ -1,15 +1,9 @@
-#===-- runtime/CMakeLists.txt ----------------------------------------------===#
-#
-# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-# See https://llvm.org/LICENSE.txt for license information.
-# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-#
-#===------------------------------------------------------------------------===#
 
 include(CheckCXXSymbolExists)
 include(CheckCXXSourceCompiles)
 check_cxx_symbol_exists(strerror string.h HAVE_STRERROR)
 check_cxx_symbol_exists(strerror_r string.h HAVE_STRERROR_R)
+
 # Can't use symbol exists here as the function is overloaded in C++
 check_cxx_source_compiles(
   "#include <string.h>
@@ -30,7 +24,7 @@
 # with different names
 include_directories(AFTER ${CMAKE_CURRENT_BINARY_DIR})
 
-add_flang_library(FortranRuntime
+add_flang_library(FortranRuntime PARTIAL_SOURCES_INTENDED
   ISO_Fortran_binding.cpp
   allocatable.cpp
   assign.cpp
@@ -82,3 +76,7 @@
   LINK_LIBS
   FortranDecimal
 )
+
+add_flang_library(Fortran_main STATIC PARTIAL_SOURCES_INTENDED
+  Fortran_main.c
+)
Index: flang/cmake/modules/AddFlang.cmake
===================================================================
--- flang/cmake/modules/AddFlang.cmake
+++ flang/cmake/modules/AddFlang.cmake
@@ -17,7 +17,7 @@
 
 macro(add_flang_library name)
   cmake_parse_arguments(ARG
-    "SHARED"
+    "SHARED;STATIC"
     ""
     "ADDITIONAL_HEADERS"
     ${ARGN})
@@ -52,7 +52,7 @@
   else()
     # llvm_add_library ignores BUILD_SHARED_LIBS if STATIC is explicitly set,
     # so we need to handle it here.
-    if (BUILD_SHARED_LIBS)
+    if (BUILD_SHARED_LIBS AND NOT ARG_STATIC)
       set(LIBTYPE SHARED OBJECT)
     else()
       set(LIBTYPE STATIC OBJECT)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D110851.376432.patch
Type: text/x-patch
Size: 2762 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20211001/5ae2d689/attachment.bin>


More information about the flang-commits mailing list