浏览代码

Use CMAKE_AR instead of the system default 'ar' for merging static libraries

Using the system default 'ar' might not be the right choice when
cross compiling.

Don't prepend the ar options by a dash, not all ar implementations
support that (llvm-ar doesn't).

Also pass the 's' option when creating the merged library, to create
an index.

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

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@313122 91177308-0d34-0410-b5e6-96231b3b80d8
Martin Storsjo 8 年之前
父节点
当前提交
5f919fe349
共有 2 个文件被更改,包括 10 次插入3 次删除
  1. 1 0
      lib/CMakeLists.txt
  2. 9 3
      utils/merge_archives.py

+ 1 - 0
lib/CMakeLists.txt

@@ -270,6 +270,7 @@ if (LIBCXX_ENABLE_STATIC)
       ${PYTHON_EXECUTABLE} ${LIBCXX_SOURCE_DIR}/utils/merge_archives.py
       ${PYTHON_EXECUTABLE} ${LIBCXX_SOURCE_DIR}/utils/merge_archives.py
     ARGS
     ARGS
       -o $<TARGET_LINKER_FILE:cxx_static>
       -o $<TARGET_LINKER_FILE:cxx_static>
+      --ar "${CMAKE_AR}"
       "$<TARGET_LINKER_FILE:cxx_static>"
       "$<TARGET_LINKER_FILE:cxx_static>"
       "${MERGE_ARCHIVES_ABI_TARGET}"
       "${MERGE_ARCHIVES_ABI_TARGET}"
       "${MERGE_ARCHIVES_SEARCH_PATHS}"
       "${MERGE_ARCHIVES_SEARCH_PATHS}"

+ 9 - 3
utils/merge_archives.py

@@ -93,13 +93,19 @@ def main():
         '-L', dest='search_paths',
         '-L', dest='search_paths',
         help='Paths to search for the libraries along', action='append',
         help='Paths to search for the libraries along', action='append',
         nargs=1)
         nargs=1)
+    parser.add_argument(
+        '--ar', dest='ar_exe', required=False,
+        help='The ar executable to use, finds \'ar\' in the path if not given',
+        type=str, action='store')
     parser.add_argument(
     parser.add_argument(
         'archives', metavar='archives',  nargs='+',
         'archives', metavar='archives',  nargs='+',
         help='The archives to merge')
         help='The archives to merge')
 
 
     args = parser.parse_args()
     args = parser.parse_args()
 
 
-    ar_exe = distutils.spawn.find_executable('ar')
+    ar_exe = args.ar_exe
+    if not ar_exe:
+        ar_exe = distutils.spawn.find_executable('ar')
     if not ar_exe:
     if not ar_exe:
         print_and_exit("failed to find 'ar' executable")
         print_and_exit("failed to find 'ar' executable")
 
 
@@ -115,13 +121,13 @@ def main():
     temp_directory_root = tempfile.mkdtemp('.libcxx.merge.archives')
     temp_directory_root = tempfile.mkdtemp('.libcxx.merge.archives')
 
 
     for arc in archives:
     for arc in archives:
-        execute_command_verbose([ar_exe, '-x', arc], cwd=temp_directory_root,
+        execute_command_verbose([ar_exe, 'x', arc], cwd=temp_directory_root,
                                 verbose=args.verbose)
                                 verbose=args.verbose)
 
 
     files = glob.glob(os.path.join(temp_directory_root, '*.o*'))
     files = glob.glob(os.path.join(temp_directory_root, '*.o*'))
     if not files:
     if not files:
         print_and_exit('Failed to glob for %s' % temp_directory_root)
         print_and_exit('Failed to glob for %s' % temp_directory_root)
-    cmd = [ar_exe, '-qc', args.output] + files
+    cmd = [ar_exe, 'qcs', args.output] + files
     execute_command_verbose(cmd, cwd=temp_directory_root, verbose=args.verbose)
     execute_command_verbose(cmd, cwd=temp_directory_root, verbose=args.verbose)