Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 14 additions & 0 deletions flang-rt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,20 @@ endif ()
option(FLANG_RT_INCLUDE_TESTS "Generate build targets for the flang-rt unit and regression-tests." "${LLVM_INCLUDE_TESTS}")


option(FLANG_RT_ENABLE_STATIC "Build Flang-RT as a static library." ON)
if (WIN32)
# Windows DLL currently not implemented.
set(FLANG_RT_ENABLE_SHARED OFF)
else ()
option(FLANG_RT_ENABLE_SHARED "Build Flang-RT as a shared library." ON)
endif ()
if (NOT FLANG_RT_ENABLE_STATIC AND NOT FLANG_RT_ENABLE_SHARED)
message(FATAL_ERROR "Must build at least one type of library
(FLANG_RT_ENABLE_STATIC=ON, FLANG_RT_ENABLE_SHARED=ON, or both)
")
endif ()


set(FLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT "" CACHE STRING "Compile Flang-RT with GPU support (CUDA or OpenMP)")
set_property(CACHE FLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT PROPERTY STRINGS
""
Expand Down
123 changes: 103 additions & 20 deletions flang-rt/cmake/modules/AddFlangRT.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -38,42 +38,124 @@ function (add_flangrt_library name)
${ARGN})

if (ARG_INSTALL_WITH_TOOLCHAIN AND ARG_EXCLUDE_FROM_ALL)
message(SEND_ERROR "add_flangrt_library(${name} ...):
message(SEND_ERROR "add_flangrt_library(${name} ...):
INSTALL_WITH_TOOLCHAIN and EXCLUDE_FROM_ALL are in conflict. When
installing an artifact it must have been built first in the 'all' target.
")
")
return ()
endif ()

# Also add header files to IDEs to list as part of the library
set_source_files_properties(${ARG_ADDITIONAL_HEADERS} PROPERTIES HEADER_FILE_ONLY ON)
#if (ARG_CMAKE_CONFIGURABLE AND (ARG_STATIC OR ARG_SHARED))
# message(SEND_ERROR "add_flangrt_library(${name} ...):
# CMAKE_CONFIGURABLE cannot be used together with STATIC or SHARED.
# ")
# return ()
#endif ()

#if (NOT ARG_STATIC AND NOT ARG_SHARED AND NOT ARG_CMAKE_CONFIGURABLE AND NOT ARG_OBJECT)
# message(SEND_ERROR "add_flangrt_library(${name} ...):
# Must specifiy library type.
# ")
# return ()
#endif ()

set(build_static OFF)
set(build_shared OFF)
if (ARG_STATIC AND FLANG_RT_ENABLE_STATIC)
set(build_static ON)
endif ()
if (ARG_SHARED AND FLANG_RT_ENABLE_SHARED)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not seeing the shared library version of libflang_rt being built with this patch. It seems build_shared is always set to OFF because ARG_SHARED is not set for flang_rt,

set(build_shared ON)
endif ()
if (NOT ARG_STATIC AND NOT ARG_SHARED AND NOT ARG_OBJECT)
if (BUILD_SHARED_LIBS)
set(build_shared ON)
else ()
set(build_static ON)
endif ()
endif ()

# Forward libtype to add_library
set(extra_args "")
if (ARG_SHARED)
list(APPEND extra_args SHARED)
# Name of targets must only depend on function arguments to be predictable for callers.
if (ARG_STATIC AND ARG_SHARED)
set(name_static "${name}.static")
set(name_shared "${name}.shared")
else ()
set(name_static "${name}")
set(name_shared "${name}")
endif ()
if (ARG_STATIC)
list(APPEND extra_args STATIC)
if (ARG_OBJECT AND NOT ARG_STATIC AND NOT ARG_SHARED)
set(name_object "${name}")
else ()
set(name_object "obj.${name}")
endif ()
if (ARG_OBJECT)
list(APPEND extra_args OBJECT)


if (ARG_OBJECT AND NOT build_static AND NOT build_shared)
set(build_only_objectlib ON)
else ()
set(build_only_objectlib OFF)
endif ()
if (build_only_objectlib OR (build_static AND build_shared))
set(need_objectlib ON)
else ()
set(need_objectlib OFF)
endif ()

if (NOT build_static AND NOT build_shared AND NOT need_objectlib)
# Nothing to build
return ()
endif ()

# Also add header files to IDEs to list as part of the library
set_source_files_properties(${ARG_ADDITIONAL_HEADERS} PROPERTIES HEADER_FILE_ONLY ON)

set(extra_args "")
if (ARG_EXCLUDE_FROM_ALL)
list(APPEND extra_args EXCLUDE_FROM_ALL)
endif ()

add_library(${name} ${extra_args} ${ARG_ADDITIONAL_HEADERS} ${ARG_UNPARSED_ARGUMENTS})

if (ARG_INSTALL_WITH_TOOLCHAIN)
set_target_properties(${name} PROPERTIES FOLDER "Flang-RT/Toolchain Libraries")
elseif (ARG_OBJECT)
set_target_properties(${name} PROPERTIES FOLDER "Flang-RT/Object Libraries")
if (need_objectlib)
add_library(${name_object} OBJECT ${extra_args} ${ARG_ADDITIONAL_HEADERS} ${ARG_UNPARSED_ARGUMENTS})
set_target_properties(${name_object} PROPERTIES FOLDER "Flang-RT/Object Libraries")

# Replace arguments for the libraries we are going to create
set(ARG_ADDITIONAL_HEADERS "")
set(ARG_UNPARSED_ARGUMENTS $<TARGET_OBJECTS:${objectlib_name}>)
set(srctargets ${name_object})
set(liblist nostargets)
set(alltargets ${name_object})
else ()
set_target_properties(${name} PROPERTIES FOLDER "Flang-RT/Libraries")
set(liblist srctargets)
set(alltargets)
endif ()

set(libtargets "")
if (build_static)
add_library(${name_static} STATIC ${extra_args} ${ARG_ADDITIONAL_HEADERS} ${ARG_UNPARSED_ARGUMENTS})
list(APPEND alltargets ${name_static})
list(APPEND libtargets ${name_static})
list(APPEND ${liblist} ${name_static})
endif ()
if (build_shared)
add_library(${name_shared} SHARED ${extra_args} ${ARG_ADDITIONAL_HEADERS} ${ARG_UNPARSED_ARGUMENTS})
list(APPEND alltargets ${name_shared})
list(APPEND libtargets ${name_shared})
list(APPEND ${liblist} ${name_shared})
endif ()

foreach (name IN LISTS libtargets)
if (ARG_INSTALL_WITH_TOOLCHAIN)
set_target_properties(${name} PROPERTIES FOLDER "Flang-RT/Toolchain Libraries")
else ()
set_target_properties(${name} PROPERTIES FOLDER "Flang-RT/Libraries")
endif ()
endforeach ()

foreach (name IN LISTS alltargets)
# Minimum required C++ version for Flang-RT, even if CMAKE_CXX_STANDARD is defined to something else.
target_compile_features(${name} PRIVATE cxx_std_17)

# Minimum required C++ version for Flang-RT, even if CMAKE_CXX_STANDARD is defined to something else.
target_compile_features(${name} PRIVATE cxx_std_17)

# Use compiler-specific options to disable exceptions and RTTI.
if (LLVM_COMPILER_IS_GCC_COMPATIBLE)
Expand Down Expand Up @@ -163,4 +245,5 @@ function (add_flangrt_library name)
if (NOT ARG_EXCLUDE_FROM_ALL)
add_dependencies(flang-rt ${name})
endif ()
endforeach ()
endfunction (add_flangrt_library)
Loading