[test-suite] r309077 - cmake/xcode_sdk: Work around problems with ranlib/strip

Matthias Braun via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 25 19:03:24 PDT 2017


Author: matze
Date: Tue Jul 25 19:03:24 2017
New Revision: 309077

URL: http://llvm.org/viewvc/llvm-project?rev=309077&view=rev
Log:
cmake/xcode_sdk: Work around problems with ranlib/strip

ranlib/strip in LTO builds require libLTO.dylib to read the bitcode
embedded in the .o/.a files. However by default they pick up the library
coming with the SDK while we usually want to pick up the one coming with
the compiler (in case we are not using the compiler coming with the
SDK). Create shims for ranlib/strip to avoid this problem.

Modified:
    test-suite/trunk/cmake/caches/util/xcode_sdk.cmake

Modified: test-suite/trunk/cmake/caches/util/xcode_sdk.cmake
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/cmake/caches/util/xcode_sdk.cmake?rev=309077&r1=309076&r2=309077&view=diff
==============================================================================
--- test-suite/trunk/cmake/caches/util/xcode_sdk.cmake (original)
+++ test-suite/trunk/cmake/caches/util/xcode_sdk.cmake Tue Jul 25 19:03:24 2017
@@ -11,21 +11,51 @@ endmacro()
 execute_process(COMMAND xcrun ${XCRUN_FLAGS} --show-sdk-path
                 OUTPUT_STRIP_TRAILING_WHITESPACE
                 OUTPUT_VARIABLE SDK_PATH)
-xcrun_find(LINKER_PATH ld)
-get_filename_component(LINKER_DIR ${LINKER_PATH} DIRECTORY)
-xcrun_find_update_cache(CMAKE_C_COMPILER clang)
-# Note that we do not search CMAKE_CXX_COMPILER to not disturb cmakes
-# convenient way to defaulting to xxx/clang++ if the c compiler is xxx/clang.
-xcrun_find_update_cache(CMAKE_RANLIB ranlib)
 xcrun_find_update_cache(CMAKE_AR ar)
-xcrun_find_update_cache(CMAKE_STRIP strip)
 xcrun_find_update_cache(CMAKE_NM nm)
 xcrun_find_update_cache(CMAKE_LINKER ld)
 
+if (CMAKE_C_COMPILER)
+  # The user manually specified a compiler which is usually different than
+  # the one coming with the SDK.
+
+  # Construct shim for ranlib
+  # This is necessary because the ranlib coming with the xcode sdk looks for
+  # ../lib/libLTO.dylib and will therefor pick up libLTO.dylib coming with the
+  # SDK. However for correct behavior it has to pick up libLTO.dylib coming
+  # the clang compiler used.
+  xcrun_find_update_cache(SDK_RANLIB ranlib)
+  get_filename_component(COMPILER_DIR ${CMAKE_C_COMPILER} DIRECTORY)
+  file(WRITE ${CMAKE_BINARY_DIR}/ranlib "
+# Shim to have the tool use the correct libLTO.dylib
+DYLD_LIBRARY_PATH=\"${COMPILER_DIR}/../lib:$DYLD_LIBRARY_PATH\" ${SDK_RANLIB} \"$@\"
+  ")
+  execute_process(COMMAND chmod +x ${CMAKE_BINARY_DIR}/ranlib)
+  set(CMAKE_RANLIB ${CMAKE_BINARY_DIR}/ranlib CACHE STRING "")
+
+  # Construct shim for strip
+  xcrun_find_update_cache(SDK_STRIP strip)
+  file(WRITE ${CMAKE_BINARY_DIR}/strip "
+# Shim to have the tool use the correct libLTO.dylib
+DYLD_LIBRARY_PATH=\"${COMPILER_DIR}/../lib:$DYLD_LIBRARY_PATH\" ${SDK_STRIP} \"$@\"
+  ")
+  execute_process(COMMAND chmod +x ${CMAKE_BINARY_DIR}/strip)
+  set(CMAKE_STRIP ${CMAKE_BINARY_DIR}/strip CACHE STRING "")
+else()
+  # Search and use compiler coming with the SDK.
+  # Note that we do not search CMAKE_CXX_COMPILER here. cmake will try
+  # `${CMAKE_C_COMPILER}++` and use that if available.
+  xcrun_find_update_cache(CMAKE_C_COMPILER clang)
+  xcrun_find_update_cache(CMAKE_RANLIB ranlib)
+  xcrun_find_update_cache(CMAKE_STRIP strip)
+endif()
+
 set(CMAKE_OSX_SYSROOT "${SDK_PATH}" CACHE STRING "")
 
 # Append -B so clang picks up the linker coming with the SDK instead of the
 # one in $PATH.
+xcrun_find(LINKER_PATH ld)
+get_filename_component(LINKER_DIR ${LINKER_PATH} DIRECTORY)
 set(TEST_SUITE_ARCH_FLAGS "${TEST_SUITE_ARCH_FLAGS} -B ${LINKER_DIR}" CACHE STRING "")
 
 # The problem with TEST_SUITE_ARCH_FLAGS is that they will not be used when




More information about the llvm-commits mailing list