[libc-commits] [libc] ea8f4b9 - [libc][CMake] Place archives in build/lib/<target-triple>

Aiden Grossman via libc-commits libc-commits at lists.llvm.org
Sat Jun 3 15:43:46 PDT 2023


Author: Aiden Grossman
Date: 2023-06-03T22:40:03Z
New Revision: ea8f4b98419750c8cc7c60ea43b570adf47b3f78

URL: https://github.com/llvm/llvm-project/commit/ea8f4b98419750c8cc7c60ea43b570adf47b3f78
DIFF: https://github.com/llvm/llvm-project/commit/ea8f4b98419750c8cc7c60ea43b570adf47b3f78.diff

LOG: [libc][CMake] Place archives in build/lib/<target-triple>

This patch moves the location of libllvmlibc.a within the build tree to
within ./lib/<target triple>. This more closely matches the behavior of
other runtime builds and allows for clang in the same build tree to
automatically be able to link against llvmlibc since this path is by
default included by the driver.

Also removes the LIBC_BINARY_DIR CMake flag since it isn't used anywhere
in the tree (based on a quick grep).

Reviewed By: phosek

Differential Revision: https://reviews.llvm.org/D151624

Added: 
    

Modified: 
    libc/CMakeLists.txt
    libc/cmake/modules/LLVMLibCLibraryRules.cmake

Removed: 
    


################################################################################
diff  --git a/libc/CMakeLists.txt b/libc/CMakeLists.txt
index 317ac08441b8d..aa09a5182469b 100644
--- a/libc/CMakeLists.txt
+++ b/libc/CMakeLists.txt
@@ -12,12 +12,21 @@ set(CMAKE_CXX_STANDARD 17)
 
 list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
 
-# The top-level sourse and binary directories.
+# The top-level source directory.
 set(LIBC_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
-set(LIBC_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
 # The top-level directory in which libc is being built.
 set(LIBC_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR})
 
+if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR)
+  set(LIBC_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE})
+else()
+  if(LLVM_LIBRARY_OUTPUT_INTDIR)
+    set(LIBC_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
+  else()
+    set(LIBC_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX})
+  endif()
+endif()
+
 if(LLVM_LIBC_FULL_BUILD OR LIBC_GPU_BUILD OR LIBC_GPU_ARCHITECTURES)
   if(NOT LIBC_HDRGEN_EXE)
     # We need to set up hdrgen first since other targets depend on it.

diff  --git a/libc/cmake/modules/LLVMLibCLibraryRules.cmake b/libc/cmake/modules/LLVMLibCLibraryRules.cmake
index 6d37232c8ae57..70b2babfb84cc 100644
--- a/libc/cmake/modules/LLVMLibCLibraryRules.cmake
+++ b/libc/cmake/modules/LLVMLibCLibraryRules.cmake
@@ -108,7 +108,7 @@ function(add_entrypoint_library target_name)
     STATIC
     ${objects}
   )
-  set_target_properties(${target_name}  PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
+  set_target_properties(${target_name} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${LIBC_LIBRARY_DIR})
 endfunction(add_entrypoint_library)
 
 # Rule to build a shared library of redirector objects.
@@ -135,7 +135,7 @@ function(add_redirector_library target_name)
     SHARED
     ${obj_files}
   )
-  set_target_properties(${target_name}  PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
+  set_target_properties(${target_name}  PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${LIBC_LIBRARY_DIR})
   target_link_libraries(${target_name}  -nostdlib -lc -lm)
   set_target_properties(${target_name}  PROPERTIES LINKER_LANGUAGE "C")
 endfunction(add_redirector_library)


        


More information about the libc-commits mailing list