[Flang-RT] Support building no library (#187868)

Allow setting both FLANG_RT_ENABLE_SHARED and FLANG_RT_ENABLE_STATIC to
OFF at the same time.

This is extracted out of #171515 to make that PR a little smaller. By
itself it makes little sense since if not building either the `.a` or
the `.so`, you are not building anything. But with #171515, the module
files are still built, allowing building the modules files without the
library. This is mostly intended for GPGPU targets where building the
library is not always needed, but the module files are.
This commit is contained in:
Michael Kruse 2026-03-25 19:49:15 +01:00 committed by GitHub
parent 61533e7e75
commit 4380ae6dbb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 55 additions and 39 deletions

View File

@ -139,12 +139,6 @@ cmake_path(NORMAL_PATH FLANG_RT_INSTALL_RESOURCE_LIB_PATH)
# Important: flang-rt user options must be prefixed with "FLANG_RT_". Variables
# with this prefix will be forwarded in bootstrap builds.
# TODO: Support tests for the GPU target.
set(FLANG_RT_INCLUDE_TESTS_default ${LLVM_INCLUDE_TESTS})
if ("${LLVM_RUNTIMES_TARGET}" MATCHES "^amdgcn|^nvptx")
set(FLANG_RT_INCLUDE_TESTS_default OFF)
endif()
option(FLANG_RT_INCLUDE_TESTS "Generate build targets for the flang-rt unit and regression-tests." "${FLANG_RT_INCLUDE_TESTS_default}")
# Provide an interface to link against the LLVM libc/libc++ projects directly.
set(FLANG_RT_SUPPORTED_PROVIDERS system llvm)
@ -171,11 +165,22 @@ else ()
# breaking change unless the driver is changed.
option(FLANG_RT_ENABLE_SHARED "Build Flang-RT as a shared library." OFF)
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)
")
# TODO: Support tests for the GPU target.
set(FLANG_RT_INCLUDE_TESTS_default ${LLVM_INCLUDE_TESTS})
if ("${LLVM_RUNTIMES_TARGET}" MATCHES "^amdgcn|^nvptx")
set(FLANG_RT_INCLUDE_TESTS_default OFF)
elseif (NOT FLANG_RT_ENABLE_STATIC AND NOT FLANG_RT_ENABLE_SHARED)
set(FLANG_RT_INCLUDE_TESTS_default OFF)
endif()
option(FLANG_RT_INCLUDE_TESTS "Generate build targets for the flang-rt unit and regression-tests." "${FLANG_RT_INCLUDE_TESTS_default}")
if (FLANG_RT_INCLUDE_TESTS AND NOT FLANG_RT_ENABLE_STATIC AND NOT FLANG_RT_ENABLE_SHARED)
message(WARNING "FLANG_RT_INCLUDE_TESTS=${FLANG_RT_INCLUDE_TESTS} requires a "
"library to be built (FLANG_RT_ENABLE_STATIC=ON or "
"FLANG_RT_ENABLE_SHARED=ON).\n"
"Tests are disabled: check-flang-rt does nothing")
set(FLANG_RT_INCLUDE_TESTS OFF)
endif ()

View File

@ -6,11 +6,16 @@
#
#===------------------------------------------------------------------------===#
add_subdirectory(quadmath)
add_subdirectory(runtime)
if (FLANG_RT_INCLUDE_CUF)
add_subdirectory(cuda)
endif()
if (FLANG_RT_ENABLE_STATIC OR FLANG_RT_ENABLE_SHARED)
add_subdirectory(quadmath)
add_subdirectory(runtime)
if (FLANG_RT_INCLUDE_CUF)
add_subdirectory(cuda)
endif()
else ()
# Generate modules files only, skip the libraries
add_subdirectory(runtime)
endif ()
if (FLANG_RT_INCLUDE_TESTS)
add_subdirectory(Testing)

View File

@ -159,28 +159,32 @@ file(GLOB_RECURSE private_headers
# Import changes from flang_rt.quadmath
get_target_property(f128_sources
FortranFloat128MathILib INTERFACE_SOURCES
)
if (f128_sources)
# The interface may define special macros for Float128Math files,
# so we need to propagate them.
get_target_property(f128_defs
FortranFloat128MathILib INTERFACE_COMPILE_DEFINITIONS
set(f128_sources "")
if (TARGET FortranFloat128MathILib)
get_target_property(f128_sources
FortranFloat128MathILib INTERFACE_SOURCES
)
set_property(SOURCE ${f128_sources}
APPEND PROPERTY COMPILE_DEFINITIONS
${f128_defs}
)
get_target_property(f128_include_dirs
FortranFloat128MathILib INTERFACE_INCLUDE_DIRECTORIES
)
set_property(SOURCE ${f128_sources}
APPEND PROPERTY INCLUDE_DIRECTORIES
${f128_include_dirs}
)
else ()
set(f128_sources "")
if (f128_sources)
# The interface may define special macros for Float128Math files,
# so we need to propagate them.
get_target_property(f128_defs
FortranFloat128MathILib INTERFACE_COMPILE_DEFINITIONS
)
set_property(SOURCE ${f128_sources}
APPEND PROPERTY COMPILE_DEFINITIONS
${f128_defs}
)
get_target_property(f128_include_dirs
FortranFloat128MathILib INTERFACE_INCLUDE_DIRECTORIES
)
set_property(SOURCE ${f128_sources}
APPEND PROPERTY INCLUDE_DIRECTORIES
${f128_include_dirs}
)
else ()
# Change `f128_sources-NOTFOUND` to "no additional sources"
set(f128_sources "")
endif ()
endif ()
if ("${LLVM_RUNTIMES_TARGET}" MATCHES "^amdgcn|^nvptx")
@ -203,8 +207,10 @@ if (NOT WIN32)
enable_cuda_compilation(flang_rt.runtime "${supported_sources}")
# Select a default runtime, which is used for unit and regression tests.
get_target_property(default_target flang_rt.runtime.default ALIASED_TARGET)
add_library(flang_rt.runtime.unittest ALIAS "${default_target}")
if (TARGET flang_rt.runtime.default)
get_target_property(default_target flang_rt.runtime.default ALIASED_TARGET)
add_library(flang_rt.runtime.unittest ALIAS "${default_target}")
endif ()
else()
# Target for building all versions of the runtime
add_custom_target(flang_rt.runtime)