Skip to content

Commit 4d6a94b

Browse files
committed
Merge LLVM_TREE_AVAILABLE
1 parent 376bbcf commit 4d6a94b

File tree

1 file changed

+46
-58
lines changed

1 file changed

+46
-58
lines changed

runtimes/CMakeLists.txt

Lines changed: 46 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,6 @@ if (CMAKE_VERSION VERSION_LESS "3.24" AND CMAKE_Fortran_COMPILER)
123123
endif ()
124124

125125

126-
# Determine whether we are in the runtimes/runtimes-bins directory of a
127-
# bootstrapping build.
128-
set(LLVM_TREE_AVAILABLE OFF)
129-
if (LLVM_LIBRARY_OUTPUT_INTDIR AND LLVM_RUNTIME_OUTPUT_INTDIR AND PACKAGE_VERSION)
130-
set(LLVM_TREE_AVAILABLE ON)
131-
endif()
132-
133-
134126
# Determine whether we are in the runtimes/runtimes-bins directory of a
135127
# bootstrap build.
136128
set(LLVM_TREE_AVAILABLE OFF)
@@ -139,16 +131,59 @@ if (LLVM_LIBRARY_DIR AND LLVM_TOOLS_BINARY_DIR AND PACKAGE_VERSION)
139131
endif()
140132

141133
if(LLVM_TREE_AVAILABLE)
142-
# Setting these variables will allow the sub-build to put their outputs into
143-
# the library and bin directories of the top-level build.
134+
# In a bootstrap build emit the libraries into a default search path in the
135+
# build directory of the just-built compiler. This allows using the
136+
# just-built compiler without specifying paths to runtime libraries.
137+
# LLVM_LIBRARY_OUTPUT_INTDIR/LLVM_RUNTIME_OUTPUT_INTDIR is used by
138+
# AddLLVM.cmake as artifact output locations.
144139
set(LLVM_LIBRARY_OUTPUT_INTDIR ${LLVM_LIBRARY_DIR})
145140
set(LLVM_RUNTIME_OUTPUT_INTDIR ${LLVM_TOOLS_BINARY_DIR})
141+
142+
# Despite Clang in the name, get_clang_resource_dir does not depend on Clang
143+
# being added to the build. Flang uses the same resource dir as Clang.
144+
include(GetClangResourceDir)
145+
get_clang_resource_dir(RUNTIMES_OUTPUT_RESOURCE_DIR PREFIX "${LLVM_LIBRARY_OUTPUT_INTDIR}/..")
146+
get_clang_resource_dir(RUNTIMES_INSTALL_RESOURCE_PATH_DEFAULT)
146147
else()
147-
# Use own build directory for artifact output.
148+
# In a standalone runtimes build, do not write into LLVM_BINARY_DIR. It may be
149+
# read-only and/or shared by multiple runtimes with different build
150+
# configurations (e.g. Debug/Release). Use the runtime's own lib dir like any
151+
# non-toolchain library. Use own build directory for artifact output.
148152
set(LLVM_LIBRARY_OUTPUT_INTDIR "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX}")
149153
set(LLVM_RUNTIME_OUTPUT_INTDIR "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin")
154+
155+
# For the install prefix, still use the resource dir assuming that Flang will
156+
# be installed there using the same prefix. This is to not have a difference
157+
# between bootstrap and standalone runtimes builds.
158+
set(RUNTIMES_OUTPUT_RESOURCE_DIR "${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}/clang/${LLVM_VERSION_MAJOR}")
159+
set(RUNTIMES_INSTALL_RESOURCE_PATH_DEFAULT "lib${LLVM_LIBDIR_SUFFIX}/clang/${LLVM_VERSION_MAJOR}")
150160
endif()
151161

162+
# Determine build and install paths.
163+
# The build path is absolute, but the install dir is relative, CMake's install
164+
# command has to apply CMAKE_INSTALL_PREFIX itself.
165+
# FIXME: For shared libraries, the toolchain resource lib dir is not a good
166+
# destination because it is not a ld.so default search path.
167+
# The machine where the executable is eventually executed may not be the
168+
# machine where the Flang compiler and its resource dir is installed, so
169+
# setting RPath by the driver is not an solution. It should belong into
170+
# /usr/lib/<triple>/lib<name>.so, like e.g. libgcc_s.so.
171+
# But the linker as invoked by the Flang driver also requires
172+
# libflang_rt.so to be found when linking and the resource lib dir is
173+
# the only reliable location.
174+
include(GetToolchainDirs)
175+
get_toolchain_library_subdir(toolchain_lib_subdir)
176+
extend_path(RUNTIMES_OUTPUT_RESOURCE_LIB_DIR "${RUNTIMES_OUTPUT_RESOURCE_DIR}" "${toolchain_lib_subdir}")
177+
178+
set(RUNTIMES_INSTALL_RESOURCE_PATH "${RUNTIMES_INSTALL_RESOURCE_PATH_DEFAULT}" CACHE PATH "Path to install headers, runtime libraries, and Fortran modules to (default: Clang resource dir)")
179+
extend_path(RUNTIMES_INSTALL_RESOURCE_LIB_PATH "${RUNTIMES_INSTALL_RESOURCE_PATH}" "${toolchain_lib_subdir}")
180+
181+
cmake_path(NORMAL_PATH RUNTIMES_OUTPUT_RESOURCE_DIR)
182+
cmake_path(NORMAL_PATH RUNTIMES_INSTALL_RESOURCE_PATH)
183+
cmake_path(NORMAL_PATH RUNTIMES_OUTPUT_RESOURCE_LIB_DIR)
184+
cmake_path(NORMAL_PATH RUNTIMES_INSTALL_RESOURCE_LIB_PATH)
185+
186+
152187
# CMake omits default compiler include paths, but in runtimes build, we use
153188
# -nostdinc and -nostdinc++ and control include paths manually so this behavior
154189
# is undesirable. Filtering CMAKE_{LANG}_IMPLICIT_INCLUDE_DIRECTORIES to remove
@@ -372,53 +407,6 @@ if(LLVM_INCLUDE_TESTS)
372407
umbrella_lit_testsuite_begin(check-runtimes)
373408
endif()
374409

375-
# Determine paths for files that belong into the Clang/Flang resource dir.
376-
if (LLVM_TREE_AVAILABLE)
377-
# In a bootstrap build emit the libraries into a default search path in the
378-
# build directory of the just-built compiler. This allows using the
379-
# just-built compiler without specifying paths to runtime libraries.
380-
#
381-
# Despite Clang in the name, get_clang_resource_dir does not depend on Clang
382-
# being added to the build. Flang uses the same resource dir as clang.
383-
include(GetClangResourceDir)
384-
get_clang_resource_dir(RUNTIMES_OUTPUT_RESOURCE_DIR PREFIX "${LLVM_LIBRARY_OUTPUT_INTDIR}/..")
385-
get_clang_resource_dir(RUNTIMES_INSTALL_RESOURCE_PATH_DEFAULT)
386-
else ()
387-
# In a standalone runtimes build, do not write into LLVM_BINARY_DIR. It may be
388-
# read-only and/or shared by multiple runtimes with different build
389-
# configurations (e.g. Debug/Release). Use the runtime's own lib dir like any
390-
# non-toolchain library.
391-
# For the install prefix, still use the resource dir assuming that Flang will
392-
# be installed there using the same prefix. This is to not have a difference
393-
# between bootstrap and standalone runtimes builds.
394-
set(RUNTIMES_OUTPUT_RESOURCE_DIR "${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}/clang/${LLVM_VERSION_MAJOR}")
395-
set(RUNTIMES_INSTALL_RESOURCE_PATH_DEFAULT "lib${LLVM_LIBDIR_SUFFIX}/clang/${LLVM_VERSION_MAJOR}")
396-
endif ()
397-
398-
# Determine build and install paths.
399-
# The build path is absolute, but the install dir is relative, CMake's install
400-
# command has to apply CMAKE_INSTALL_PREFIX itself.
401-
# FIXME: For shared libraries, the toolchain resource lib dir is not a good
402-
# destination because it is not a ld.so default search path.
403-
# The machine where the executable is eventually executed may not be the
404-
# machine where the Flang compiler and its resource dir is installed, so
405-
# setting RPath by the driver is not an solution. It should belong into
406-
# /usr/lib/<triple>/lib<name>.so, like e.g. libgcc_s.so.
407-
# But the linker as invoked by the Flang driver also requires
408-
# libflang_rt.so to be found when linking and the resource lib dir is
409-
# the only reliable location.
410-
include(GetToolchainDirs)
411-
get_toolchain_library_subdir(toolchain_lib_subdir)
412-
extend_path(RUNTIMES_OUTPUT_RESOURCE_LIB_DIR "${RUNTIMES_OUTPUT_RESOURCE_DIR}" "${toolchain_lib_subdir}")
413-
414-
set(RUNTIMES_INSTALL_RESOURCE_PATH "${RUNTIMES_INSTALL_RESOURCE_PATH_DEFAULT}" CACHE PATH "Path to install headers, runtime libraries, and Fortran modules to (default: Clang resource dir)")
415-
extend_path(RUNTIMES_INSTALL_RESOURCE_LIB_PATH "${RUNTIMES_INSTALL_RESOURCE_PATH}" "${toolchain_lib_subdir}")
416-
417-
cmake_path(NORMAL_PATH RUNTIMES_OUTPUT_RESOURCE_DIR)
418-
cmake_path(NORMAL_PATH RUNTIMES_INSTALL_RESOURCE_PATH)
419-
cmake_path(NORMAL_PATH RUNTIMES_OUTPUT_RESOURCE_LIB_DIR)
420-
cmake_path(NORMAL_PATH RUNTIMES_INSTALL_RESOURCE_LIB_PATH)
421-
422410

423411
include(CheckFortranSourceCompiles)
424412

0 commit comments

Comments
 (0)