summaryrefslogtreecommitdiff
path: root/cmake/Modules
diff options
context:
space:
mode:
authorPetr Hosek <phosek@chromium.org>2019-06-04 02:38:15 +0000
committerPetr Hosek <phosek@chromium.org>2019-06-04 02:38:15 +0000
commit2c250cb3570f33e531d6843fc4baea1b2a0227b9 (patch)
treee5883fd259deec93cb328ba2395af1a25f093c54 /cmake/Modules
parent40f32b2e765076d76a7caa6342821c89a1580c25 (diff)
downloadcompiler-rt-2c250cb3570f33e531d6843fc4baea1b2a0227b9.tar.gz
[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 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@362466 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'cmake/Modules')
-rw-r--r--cmake/Modules/UseLibtool.cmake50
1 files changed, 50 insertions, 0 deletions
diff --git a/cmake/Modules/UseLibtool.cmake b/cmake/Modules/UseLibtool.cmake
new file mode 100644
index 000000000..38d197d48
--- /dev/null
+++ b/cmake/Modules/UseLibtool.cmake
@@ -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()