================
@@ -236,6 +237,36 @@ if(CMAKE_C_COMPILER_ID MATCHES "Clang")
   endif()
 endif()
 
+# Determine output and install paths based on LLVM_TARGET_TRIPLE
+if(LLVM_TREE_AVAILABLE)
+  # Despite Clang in the name, get_clang_resource_dir does not depend on Clang
+  # being added to the build. Flang uses the same resource dir as Clang.
+  include(GetClangResourceDir)
+  get_clang_resource_dir(RUNTIMES_OUTPUT_RESOURCE_DIR PREFIX 
"${LLVM_LIBRARY_OUTPUT_INTDIR}/..")
+  get_clang_resource_dir(RUNTIMES_INSTALL_RESOURCE_PATH_DEFAULT)
+else()
+  # For the install prefix, still use the resource dir assuming the compilers
+  # looking for it (Clang, Flang) will be installed there using the same 
prefix.
+  # This is to not have a difference between bootstrapping and 
default/standalone runtimes
+  # builds.
+  set(RUNTIMES_OUTPUT_RESOURCE_DIR 
"${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}/clang/${LLVM_VERSION_MAJOR}")
+  set(RUNTIMES_INSTALL_RESOURCE_PATH_DEFAULT 
"lib${LLVM_LIBDIR_SUFFIX}/clang/${LLVM_VERSION_MAJOR}")
+endif()
+
+# Determine build and install paths. The output paths are absolute, but the
+# install dirs are relative to CMAKE_INSTALL_PREFIX to be resolved by CMake.
+get_toolchain_library_subdir(toolchain_lib_subdir)
+extend_path(RUNTIMES_OUTPUT_RESOURCE_LIB_DIR "${RUNTIMES_OUTPUT_RESOURCE_DIR}" 
"${toolchain_lib_subdir}")
+
+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)")
+extend_path(RUNTIMES_INSTALL_RESOURCE_LIB_PATH 
"${RUNTIMES_INSTALL_RESOURCE_PATH}" "${toolchain_lib_subdir}")
----------------
petrhosek wrote:

It took me a while to fully understand this logic, but I don't think this is 
correct. Specifically, this uses the triple construction logic extracted from 
compiler-rt (`get_compiler_rt_target`), but it crucially omits this part:
```
  if(COMPILER_RT_DEFAULT_TARGET_ONLY)
    # Use exact spelling when building only for the target specified to CMake.
    set(target "${COMPILER_RT_DEFAULT_TARGET_TRIPLE}")
``` 
In the runtimes build, we always set `COMPILER_RT_DEFAULT_TARGET_ONLY=1` and 
therefore we don't do any triple normalization and instead we use the triple as 
is (bypassing all the logic `get_compiler_rt_target`). 

https://github.com/llvm/llvm-project/pull/177953
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to