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. llvm-svn: 342425
This commit is contained in:
parent
2ee93d28fd
commit
f5ebd70a67
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue