1 # if CMAKE_LIBTOOL is not set, try and find it with xcrun or find_program
4 find_program(CMAKE_XCRUN NAMES xcrun)
7 execute_process(COMMAND ${CMAKE_XCRUN} -find libtool
8 OUTPUT_VARIABLE CMAKE_LIBTOOL
9 OUTPUT_STRIP_TRAILING_WHITESPACE)
12 if(NOT CMAKE_LIBTOOL OR NOT EXISTS CMAKE_LIBTOOL)
13 find_program(CMAKE_LIBTOOL NAMES libtool)
17 get_property(languages GLOBAL PROPERTY ENABLED_LANGUAGES)
19 set(CMAKE_LIBTOOL ${CMAKE_LIBTOOL} CACHE PATH "libtool executable")
20 message(STATUS "Found libtool - ${CMAKE_LIBTOOL}")
22 execute_process(COMMAND ${CMAKE_LIBTOOL} -V
23 OUTPUT_VARIABLE LIBTOOL_V_OUTPUT
24 OUTPUT_STRIP_TRAILING_WHITESPACE)
25 if("${LIBTOOL_V_OUTPUT}" MATCHES ".*cctools-([0-9.]+).*")
26 string(REGEX REPLACE ".*cctools-([0-9.]+).*" "\\1" LIBTOOL_VERSION
28 if(NOT LIBTOOL_VERSION VERSION_LESS "862")
29 set(LIBTOOL_NO_WARNING_FLAG "-no_warning_for_no_symbols")
33 foreach(lang ${languages})
34 set(CMAKE_${lang}_CREATE_STATIC_LIBRARY
35 "\"${CMAKE_LIBTOOL}\" -static ${LIBTOOL_NO_WARNING_FLAG} -o <TARGET> <LINK_FLAGS> <OBJECTS>")
38 # By default, CMake invokes ranlib on a static library after installing it.
39 # libtool will have produced the table of contents for us already, and ranlib
40 # does not understanding universal binaries, so skip this step. It's important
41 # to set it to empty instead of unsetting it to shadow the cache variable, and
42 # we don't want to unset the cache variable to not affect anything outside
47 # If DYLD_LIBRARY_PATH is set we need to set it on archiver commands
49 set(dyld_envar "DYLD_LIBRARY_PATH=${DYLD_LIBRARY_PATH}")
50 foreach(lang ${languages})
51 foreach(cmd ${CMAKE_${lang}_CREATE_STATIC_LIBRARY})
52 list(APPEND CMAKE_${lang}_CREATE_STATIC_LIBRARY_NEW
53 "${dyld_envar} ${cmd}")
55 set(CMAKE_${lang}_CREATE_STATIC_LIBRARY
56 ${CMAKE_${lang}_CREATE_STATIC_LIBRARY_NEW})