forked from OSchip/llvm-project
[flang] Add a wrapper for Fortran main program
Add a C wrapper that calls the Fortran runtime initialization and
finalization routines as well as the compiled Fortran main program
_QQmain.
Place it in its own library to satisfy shared library builds since it
contains a C main function.
- cc7ac498f9 (diff-fa35a5efa62731fd2845e5e982eca9a2e36439783e11a4e4a463753c2160ec10R53)
- was created in flang/test/Examples/main.c in Eric's branch
This commit is contained in:
parent
a63f57674d
commit
2c1ce0755e
|
@ -17,7 +17,7 @@ endmacro()
|
||||||
|
|
||||||
macro(add_flang_library name)
|
macro(add_flang_library name)
|
||||||
cmake_parse_arguments(ARG
|
cmake_parse_arguments(ARG
|
||||||
"SHARED"
|
"SHARED;STATIC"
|
||||||
""
|
""
|
||||||
"ADDITIONAL_HEADERS"
|
"ADDITIONAL_HEADERS"
|
||||||
${ARGN})
|
${ARGN})
|
||||||
|
@ -52,7 +52,7 @@ macro(add_flang_library name)
|
||||||
else()
|
else()
|
||||||
# llvm_add_library ignores BUILD_SHARED_LIBS if STATIC is explicitly set,
|
# llvm_add_library ignores BUILD_SHARED_LIBS if STATIC is explicitly set,
|
||||||
# so we need to handle it here.
|
# so we need to handle it here.
|
||||||
if (BUILD_SHARED_LIBS)
|
if (BUILD_SHARED_LIBS AND NOT ARG_STATIC)
|
||||||
set(LIBTYPE SHARED OBJECT)
|
set(LIBTYPE SHARED OBJECT)
|
||||||
else()
|
else()
|
||||||
set(LIBTYPE STATIC OBJECT)
|
set(LIBTYPE STATIC OBJECT)
|
||||||
|
|
|
@ -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(CheckCXXSymbolExists)
|
||||||
include(CheckCXXSourceCompiles)
|
include(CheckCXXSourceCompiles)
|
||||||
check_cxx_symbol_exists(strerror string.h HAVE_STRERROR)
|
check_cxx_symbol_exists(strerror string.h HAVE_STRERROR)
|
||||||
check_cxx_symbol_exists(strerror_r string.h HAVE_STRERROR_R)
|
check_cxx_symbol_exists(strerror_r string.h HAVE_STRERROR_R)
|
||||||
|
|
||||||
# Can't use symbol exists here as the function is overloaded in C++
|
# Can't use symbol exists here as the function is overloaded in C++
|
||||||
check_cxx_source_compiles(
|
check_cxx_source_compiles(
|
||||||
"#include <string.h>
|
"#include <string.h>
|
||||||
|
@ -30,7 +24,7 @@ configure_file(config.h.cmake config.h)
|
||||||
# with different names
|
# with different names
|
||||||
include_directories(AFTER ${CMAKE_CURRENT_BINARY_DIR})
|
include_directories(AFTER ${CMAKE_CURRENT_BINARY_DIR})
|
||||||
|
|
||||||
add_flang_library(FortranRuntime
|
add_flang_library(FortranRuntime PARTIAL_SOURCES_INTENDED
|
||||||
ISO_Fortran_binding.cpp
|
ISO_Fortran_binding.cpp
|
||||||
allocatable.cpp
|
allocatable.cpp
|
||||||
assign.cpp
|
assign.cpp
|
||||||
|
@ -82,3 +76,7 @@ add_flang_library(FortranRuntime
|
||||||
LINK_LIBS
|
LINK_LIBS
|
||||||
FortranDecimal
|
FortranDecimal
|
||||||
)
|
)
|
||||||
|
|
||||||
|
add_flang_library(Fortran_main STATIC PARTIAL_SOURCES_INTENDED
|
||||||
|
Fortran_main.c
|
||||||
|
)
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
#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;
|
||||||
|
}
|
Loading…
Reference in New Issue