llvm.org GIT mirror llvm / ce40381
[CMake] Use libtool for runtimes when building for Apple platform LLVM CMake build already uses libtool instead of ar when building for Apple platform and we should be using the same when building runtimes. To do so, this change extracts the logic for finding libtool into a separate file and then uses it from both the LLVM build as well as the LLVM runtimes build. Differential Revision: https://reviews.llvm.org/D62769 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@362313 91177308-0d34-0410-b5e6-96231b3b80d8 Petr Hosek 3 months ago
3 changed file(s) with 60 addition(s) and 55 deletion(s). Raw diff Collapse all Expand all
4646 if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
4747 message(STATUS "No build type selected, default to Debug")
4848 set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Build type (default Debug)" FORCE)
49 endif()
50
51 # This should only apply if you are both on an Apple host, and targeting Apple.
52 if(CMAKE_HOST_APPLE AND APPLE)
53 # if CMAKE_LIBTOOL is not set, try and find it with xcrun or find_program
54 if(NOT CMAKE_LIBTOOL)
55 if(NOT CMAKE_XCRUN)
56 find_program(CMAKE_XCRUN NAMES xcrun)
57 endif()
58 if(CMAKE_XCRUN)
59 execute_process(COMMAND ${CMAKE_XCRUN} -find libtool
60 OUTPUT_VARIABLE CMAKE_LIBTOOL
61 OUTPUT_STRIP_TRAILING_WHITESPACE)
62 endif()
63
64 if(NOT CMAKE_LIBTOOL OR NOT EXISTS CMAKE_LIBTOOL)
65 find_program(CMAKE_LIBTOOL NAMES libtool)
66 endif()
67 endif()
68
69 get_property(languages GLOBAL PROPERTY ENABLED_LANGUAGES)
70 if(CMAKE_LIBTOOL)
71 set(CMAKE_LIBTOOL ${CMAKE_LIBTOOL} CACHE PATH "libtool executable")
72 message(STATUS "Found libtool - ${CMAKE_LIBTOOL}")
73
74 execute_process(COMMAND ${CMAKE_LIBTOOL} -V
75 OUTPUT_VARIABLE LIBTOOL_V_OUTPUT
76 OUTPUT_STRIP_TRAILING_WHITESPACE)
77 if("${LIBTOOL_V_OUTPUT}" MATCHES ".*cctools-([0-9.]+).*")
78 string(REGEX REPLACE ".*cctools-([0-9.]+).*" "\\1" LIBTOOL_VERSION
79 ${LIBTOOL_V_OUTPUT})
80 if(NOT LIBTOOL_VERSION VERSION_LESS "862")
81 set(LIBTOOL_NO_WARNING_FLAG "-no_warning_for_no_symbols")
82 endif()
83 endif()
84
85 foreach(lang ${languages})
86 set(CMAKE_${lang}_CREATE_STATIC_LIBRARY
87 "\"${CMAKE_LIBTOOL}\" -static ${LIBTOOL_NO_WARNING_FLAG} -o \
88 ")
89 endforeach()
90 endif()
91
92 # If DYLD_LIBRARY_PATH is set we need to set it on archiver commands
93 if(DYLD_LIBRARY_PATH)
94 set(dyld_envar "DYLD_LIBRARY_PATH=${DYLD_LIBRARY_PATH}")
95 foreach(lang ${languages})
96 foreach(cmd ${CMAKE_${lang}_CREATE_STATIC_LIBRARY})
97 list(APPEND CMAKE_${lang}_CREATE_STATIC_LIBRARY_NEW
98 "${dyld_envar} ${cmd}")
99 endforeach()
100 set(CMAKE_${lang}_CREATE_STATIC_LIBRARY
101 ${CMAKE_${lang}_CREATE_STATIC_LIBRARY_NEW})
102 endforeach()
103 endif()
10449 endif()
10550
10651 # Side-by-side subprojects layout: automatically set the
647592 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static")
648593 endif()
649594
595 # Use libtool instead of ar if you are both on an Apple host, and targeting Apple.
596 if(CMAKE_HOST_APPLE AND APPLE)
597 include(UseLibtool)
598 endif()
599
650600 # Override the default target with an environment variable named by LLVM_TARGET_TRIPLE_ENV.
651601 set(LLVM_TARGET_TRIPLE_ENV CACHE STRING "The name of environment variable to override default target. Disabled by blank.")
652602 mark_as_advanced(LLVM_TARGET_TRIPLE_ENV)
0 # if CMAKE_LIBTOOL is not set, try and find it with xcrun or find_program
1 if(NOT CMAKE_LIBTOOL)
2 if(NOT CMAKE_XCRUN)
3 find_program(CMAKE_XCRUN NAMES xcrun)
4 endif()
5 if(CMAKE_XCRUN)
6 execute_process(COMMAND ${CMAKE_XCRUN} -find libtool
7 OUTPUT_VARIABLE CMAKE_LIBTOOL
8 OUTPUT_STRIP_TRAILING_WHITESPACE)
9 endif()
10
11 if(NOT CMAKE_LIBTOOL OR NOT EXISTS CMAKE_LIBTOOL)
12 find_program(CMAKE_LIBTOOL NAMES libtool)
13 endif()
14 endif()
15
16 get_property(languages GLOBAL PROPERTY ENABLED_LANGUAGES)
17 if(CMAKE_LIBTOOL)
18 set(CMAKE_LIBTOOL ${CMAKE_LIBTOOL} CACHE PATH "libtool executable")
19 message(STATUS "Found libtool - ${CMAKE_LIBTOOL}")
20
21 execute_process(COMMAND ${CMAKE_LIBTOOL} -V
22 OUTPUT_VARIABLE LIBTOOL_V_OUTPUT
23 OUTPUT_STRIP_TRAILING_WHITESPACE)
24 if("${LIBTOOL_V_OUTPUT}" MATCHES ".*cctools-([0-9.]+).*")
25 string(REGEX REPLACE ".*cctools-([0-9.]+).*" "\\1" LIBTOOL_VERSION
26 ${LIBTOOL_V_OUTPUT})
27 if(NOT LIBTOOL_VERSION VERSION_LESS "862")
28 set(LIBTOOL_NO_WARNING_FLAG "-no_warning_for_no_symbols")
29 endif()
30 endif()
31
32 foreach(lang ${languages})
33 set(CMAKE_${lang}_CREATE_STATIC_LIBRARY
34 "\"${CMAKE_LIBTOOL}\" -static ${LIBTOOL_NO_WARNING_FLAG} -o ")
35 endforeach()
36 endif()
37
38 # If DYLD_LIBRARY_PATH is set we need to set it on archiver commands
39 if(DYLD_LIBRARY_PATH)
40 set(dyld_envar "DYLD_LIBRARY_PATH=${DYLD_LIBRARY_PATH}")
41 foreach(lang ${languages})
42 foreach(cmd ${CMAKE_${lang}_CREATE_STATIC_LIBRARY})
43 list(APPEND CMAKE_${lang}_CREATE_STATIC_LIBRARY_NEW
44 "${dyld_envar} ${cmd}")
45 endforeach()
46 set(CMAKE_${lang}_CREATE_STATIC_LIBRARY
47 ${CMAKE_${lang}_CREATE_STATIC_LIBRARY_NEW})
48 endforeach()
49 endif()
115115
116116 # Remove the -nostdlib++ option we've added earlier.
117117 string(REPLACE "-nostdlib++" "" CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
118
119 # Use libtool instead of ar if you are both on an Apple host, and targeting Apple.
120 if(CMAKE_HOST_APPLE AND APPLE)
121 include(UseLibtool)
122 endif()
118123
119124 # This can be used to detect whether we're in the runtimes build.
120125 set(RUNTIMES_BUILD ON)