[compiler-rt] r342425 - build: fix standalone builds for compiler-rt on Darwin

Saleem Abdulrasool via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 17 16:25:36 PDT 2018


Author: compnerd
Date: Mon Sep 17 16:25:36 2018
New Revision: 342425

URL: http://llvm.org/viewvc/llvm-project?rev=342425&view=rev
Log:
build: fix standalone builds for compiler-rt on Darwin

When building static fat libraries, we need to ensure that we use libtool rather
than llvm-ar to create the library.  Duplicate the rules from LLVM to ensure
that we correctly build the fat libraries when building compiler-rt standalone.
This also requires that we duplicate the workaround for the `DYLD_LIBRARY_PATH`
for SIP.  Additionally, ensure that we set the `CMAKE_*_ARCHIVE_FINISH` variable
to ensure that we do not try to use `ranlib` on that target.

Modified:
    compiler-rt/trunk/CMakeLists.txt

Modified: compiler-rt/trunk/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/CMakeLists.txt?rev=342425&r1=342424&r2=342425&view=diff
==============================================================================
--- compiler-rt/trunk/CMakeLists.txt (original)
+++ compiler-rt/trunk/CMakeLists.txt Mon Sep 17 16:25:36 2018
@@ -82,6 +82,66 @@ if (COMPILER_RT_STANDALONE_BUILD)
       or specify the PYTHON_EXECUTABLE CMake variable.")
   endif()
 
+  # Ensure that fat libraries are built correctly on Darwin
+  if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
+    if(NOT CMAKE_LIBTOOL)
+      find_program(CMAKE_XCRUN
+                   NAMES
+                     xcrun)
+      if(CMAKE_XCRUN)
+        execute_process(COMMAND
+                          ${CMAKE_XCRUN} -find libtool
+                        OUTPUT_VARIABLE
+                          CMAKE_LIBTOOL
+                        OUTPUT_STRIP_TRAILING_WHITESPACE)
+      endif()
+
+      if(NOT CMAKE_LIBTOOL OR NOT EXISTS CMAKE_LIBTOOL)
+        find_program(CMAKE_LIBTOOL
+                     NAMES
+                       libtool)
+      endif()
+    endif()
+
+    get_property(languages GLOBAL PROPERTY ENABLED_LANGUAGES)
+
+    if(CMAKE_LIBTOOL)
+      set(CMAKE_LIBTOOL ${CMAKE_LIBTOOL} CACHE PATH "libtool executable")
+      message(STATUS "Found libtool - ${CMAKE_LIBTOOL}")
+
+      execute_process(COMMAND
+                        ${CMAKE_LIBTOOL} -V
+                      OUTPUT_VARIABLE
+                        LIBTOOL_V_OUTPUT
+                      OUTPUT_STRIP_TRAILING_WHITESPACE)
+      if("${LIBTOOL_V_OUTPUT}" MATCHES ".*cctools-([0-9]+).*")
+        string(REGEX REPLACE ".*cctools-([0-9]+).*" "\\1" LIBTOOL_VERSION ${LIBTOOL_V_OUTPUT})
+        if(NOT LIBTOOL_VERSION VERSION_LESS "862")
+          set(LIBTOOL_NO_WARNING_FLAG "-no_warning_for_no_symbols")
+        endif()
+      endif()
+
+      foreach(lang ${languages})
+        set(CMAKE_${lang}_CREATE_STATIC_LIBRARY "\"${CMAKE_LIBTOOL}\" -static ${LIBTOOL_NO_WARNING_FLAG} -o <TARGET> <LINK_FLAGS> <OBJECTS>")
+        # Replace the finish target so that ranlib is not invoked on the
+        # archive.
+        set(CMAKE_${lang}_ARCHIVE_FINISH "")
+      endforeach()
+    endif()
+
+    # Workaround SIP :-(
+    if(DYLD_LIBRARY_PATH)
+      set(dyld_envar "DYLD_LIBRARY_PATH=${DYLD_LIBRARY_PATH}")
+      foreach(lang ${languages})
+        foreach(cmd ${CMAKE_${lang}_CREATE_STATIC_LIBRARY})
+          list(APPEND CMAKE_${lang}_CREATE_STATIC_LIBRARY_NEW "${dyld_envar} ${cmd}")
+        endforeach()
+        set(CMAKE_${lang}_CREATE_STATIC_LIBRARY ${CMAKE_${lang}_CREATE_STATIC_LIBRARY_NEW})
+        set(CMAKE_${lang}_ARCHIVE_FINISH " ")
+      endforeach()
+    endif()
+  endif()
+
   # Define default arguments to lit.
   set(LIT_ARGS_DEFAULT "-sv")
   if (MSVC OR XCODE)




More information about the llvm-commits mailing list