Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions flang-rt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,17 @@ cmake_path(NORMAL_PATH FLANG_RT_INSTALL_RESOURCE_LIB_PATH)

option(FLANG_RT_INCLUDE_TESTS "Generate build targets for the flang-rt unit and regression-tests." "${LLVM_INCLUDE_TESTS}")

# Provide an interface to link against the LLVM libc/libc++ projects directly.
set(FLANG_RT_SUPPORTED_PROVIDERS system llvm)
set(FLANG_RT_LIBC_PROVIDER "system" CACHE STRING "Specify C library to use. Supported values are ${FLANG_RT_SUPPORTED_PROVIDERS}.")
if (NOT "${FLANG_RT_LIBC_PROVIDER}" IN_LIST FLANG_RT_SUPPORTED_PROVIDERS)
message(FATAL_ERROR "Unsupported library: '${FLANG_RT_RUNTIME_PROVIDER}'. Supported values are ${FLANG_RT_SUPPORTED_PROVIDERS}.")
endif ()

set(FLANG_RT_LIBCXX_PROVIDER "system" CACHE STRING "Specify C++ library to use. Supported values are ${FLANG_RT_SUPPORTED_PROVIDERS}.")
if (NOT "${FLANG_RT_LIBCXX_PROVIDER}" IN_LIST FLANG_RT_SUPPORTED_PROVIDERS)
message(FATAL_ERROR "Unsupported library: '${FLANG_RT_LIBCXX_PROVIDER}'. Supported values are ${FLANG_RT_SUPPORTED_PROVIDERS}.")
endif ()

option(FLANG_RT_ENABLE_STATIC "Build Flang-RT as a static library." ON)
if (WIN32)
Expand Down Expand Up @@ -244,6 +255,15 @@ check_cxx_compiler_flag("-UTESTFLAG" FLANG_RT_SUPPORTS_UNDEFINE_FLAG)
# Check whether -fno-lto is supported.
check_cxx_compiler_flag(-fno-lto FLANG_RT_HAS_FNO_LTO_FLAG)

# Check whether -nostdlibinc is supported.
check_cxx_compiler_flag(-nostdlibinc FLANG_RT_HAS_NOSTDLIBINC_FLAG)

# Check whether -nostdlib is supported.
check_cxx_compiler_flag(-nostdlib FLANG_RT_HAS_NOSTDLIB_FLAG)

# Check whether -stdlib= is supported.
check_cxx_compiler_flag(-stdlib=platform FLANG_RT_HAS_STDLIB_FLAG)

# Check whether -Wl,--as-needed is supported.
check_linker_flag(C "LINKER:--as-needed" LINKER_SUPPORTS_AS_NEEDED)
if (LINKER_SUPPORTS_AS_NEEDED)
Expand Down Expand Up @@ -303,6 +323,8 @@ endif ()
# Build Preparation #
#####################

include(HandleLibs)

if (FLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT AND FLANG_RT_INCLUDE_TESTS)
# If Fortran runtime is built as CUDA library, the linking
# of targets that link flang-rt must be done
Expand Down
2 changes: 2 additions & 0 deletions flang-rt/cmake/modules/AddFlangRT.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,11 @@ function (add_flangrt_library name)
endif ()
if (build_static)
add_library("${name_static}" STATIC ${extra_args} ${ARG_ADDITIONAL_HEADERS} ${ARG_UNPARSED_ARGUMENTS})
target_link_libraries("${name_static}" PRIVATE flang-rt-libcxx-headers flang-rt-libc-headers flang-rt-libc-static)
endif ()
if (build_shared)
add_library("${name_shared}" SHARED ${extra_args} ${ARG_ADDITIONAL_HEADERS} ${ARG_UNPARSED_ARGUMENTS})
target_link_libraries("${name_static}" PRIVATE flang-rt-libcxx-headers flang-rt-libc-headers flang-rt-libc-shared)
if (Threads_FOUND)
target_link_libraries(${name_shared} PUBLIC Threads::Threads)
endif ()
Expand Down
50 changes: 50 additions & 0 deletions flang-rt/cmake/modules/HandleLibs.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#===-- cmake/modules/HandleLibs.cmake --------------------------------------===#
#
# 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
#
#===------------------------------------------------------------------------===#

# Select the C library to use for building flang-rt.
if (FLANG_RT_LIBC_PROVIDER STREQUAL "system")
add_library(flang-rt-libc-headers INTERFACE)
add_library(flang-rt-libc-static INTERFACE)
add_library(flang-rt-libc-shared INTERFACE)
elseif (FLANG_RT_LIBC_PROVIDER STREQUAL "llvm")
add_library(flang-rt-libc-headers INTERFACE)
target_link_libraries(flang-rt-libc-headers INTERFACE libc-headers)
if (FLANG_RT_HAS_NOSTDLIBINC_FLAG)
target_compile_options(flang-rt-libc-headers INTERFACE $<$<COMPILE_LANGUAGE:CXX,C>:-nostdlibinc>)
endif ()

add_library(flang-rt-libc-static INTERFACE)
if (TARGET libc)
target_link_libraries(flang-rt-libc-static INTERFACE libc)
endif ()
if (TARGET libm)
target_link_libraries(flang-rt-libc-static INTERFACE libm)
endif ()
if (FLANG_RT_HAS_NOSTDLIB_FLAG)
target_compile_options(flang-rt-libc-headers INTERFACE $<$<COMPILE_LANGUAGE:CXX,C>:-nostdlib>)
endif ()

# TODO: There's no support for building LLVM libc as a shared library yet.
add_library(flang-rt-libc-shared INTERFACE)
endif ()

# Select the C++ library to use for building flang-rt.
if (FLANG_RT_LIBCXX_PROVIDER STREQUAL "system")
add_library(flang-rt-libcxx-headers INTERFACE)
elseif (FLANG_RT_LIBCXX_PROVIDER STREQUAL "llvm")
add_library(flang-rt-libcxx-headers INTERFACE)
target_link_libraries(flang-rt-libcxx-headers INTERFACE cxx-headers)

if (CXX_SUPPORTS_NOSTDINCXX_FLAG)
target_compile_options(flang-rt-libc-headers INTERFACE $<$<COMPILE_LANGUAGE:CXX,C>:-nostdinc++>)
endif ()

if (FLANG_RT_HAS_STDLIB_FLAG)
target_compile_options(flang-rt-libc-headers INTERFACE $<$<COMPILE_LANGUAGE:CXX,C>:-stdlib=libc++>)
endif ()
endif ()