summaryrefslogtreecommitdiff
path: root/CMakeLists.txt
diff options
context:
space:
mode:
authorSaleem Abdulrasool <compnerd@compnerd.org>2018-09-17 23:25:36 +0000
committerSaleem Abdulrasool <compnerd@compnerd.org>2018-09-17 23:25:36 +0000
commit0c902dcd570c12dcb061e5a6dc373868b3d9a91f (patch)
tree8b6a0d5c9a9e9f9395e9ed9ccbd27ba7c70eea82 /CMakeLists.txt
parent6f1aaf12fb3befeb78f33cbc4243329861597a3e (diff)
downloadcompiler-rt-0c902dcd570c12dcb061e5a6dc373868b3d9a91f.tar.gz
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. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@342425 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r--CMakeLists.txt60
1 files changed, 60 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 193342c1c..d4f185602 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -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)