[compiler-rt] r362466 - [builtins] Use libtool for builtins when building for Apple platform

Petr Hosek via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 3 19:38:16 PDT 2019


Author: phosek
Date: Mon Jun  3 19:38:15 2019
New Revision: 362466

URL: http://llvm.org/viewvc/llvm-project?rev=362466&view=rev
Log:
[builtins] Use libtool for builtins when building for Apple platform

compiler-rt already uses libtool instead of ar when building for
Apple platform, but that's not being used when builtins are being
built separately e.g. as part of the runtimes build. This change
extracts the logic setting up libtool into a separate file and uses
it from both the compiler-rt and standalone builtins build.

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

Added:
    compiler-rt/trunk/cmake/Modules/UseLibtool.cmake
Modified:
    compiler-rt/trunk/CMakeLists.txt
    compiler-rt/trunk/lib/builtins/CMakeLists.txt

Modified: compiler-rt/trunk/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/CMakeLists.txt?rev=362466&r1=362465&r2=362466&view=diff
==============================================================================
--- compiler-rt/trunk/CMakeLists.txt (original)
+++ compiler-rt/trunk/CMakeLists.txt Mon Jun  3 19:38:15 2019
@@ -89,58 +89,8 @@ if (COMPILER_RT_STANDALONE_BUILD)
   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>")
-      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()
-      endforeach()
-    endif()
+  if(CMAKE_HOST_APPLE AND APPLE)
+    include(UseLibtool)
   endif()
 
   # Define default arguments to lit.

Added: compiler-rt/trunk/cmake/Modules/UseLibtool.cmake
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/cmake/Modules/UseLibtool.cmake?rev=362466&view=auto
==============================================================================
--- compiler-rt/trunk/cmake/Modules/UseLibtool.cmake (added)
+++ compiler-rt/trunk/cmake/Modules/UseLibtool.cmake Mon Jun  3 19:38:15 2019
@@ -0,0 +1,50 @@
+# if CMAKE_LIBTOOL is not set, try and find it with xcrun or find_program
+if(NOT CMAKE_LIBTOOL)
+  if(NOT CMAKE_XCRUN)
+    find_program(CMAKE_XCRUN NAMES xcrun)
+  endif()
+  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>")
+  endforeach()
+endif()
+
+# If DYLD_LIBRARY_PATH is set we need to set it on archiver commands
+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})
+  endforeach()
+endif()

Modified: compiler-rt/trunk/lib/builtins/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/builtins/CMakeLists.txt?rev=362466&r1=362465&r2=362466&view=diff
==============================================================================
--- compiler-rt/trunk/lib/builtins/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/builtins/CMakeLists.txt Mon Jun  3 19:38:15 2019
@@ -20,6 +20,9 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURR
   if(APPLE)
     include(CompilerRTDarwinUtils)
   endif()
+  if(CMAKE_HOST_APPLE AND APPLE)
+    include(UseLibtool)
+  endif()
   include(AddCompilerRT)
 endif()
 




More information about the llvm-commits mailing list