@@ -10,3 +10,195 @@ function(apply_xcode_substitutions config path result_var_name)
10
10
set ("${result_var_name} " "${result} " PARENT_SCOPE )
11
11
endfunction ()
12
12
13
+ function (get_effective_platform_for_triple triple output )
14
+ string (FIND "${triple} " "macos" IS_MACOS )
15
+ if (IS_MACOS )
16
+ set (${output} "" PARENT_SCOPE )
17
+ return ()
18
+ endif ()
19
+ message (FATAL_ERROR "Not supported" )
20
+ endfunction ()
21
+
22
+ # Eliminate $(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) from a path.
23
+ #
24
+ # We do not support compiling llvm with an Xcode setting beyond the one that was
25
+ # used with build-script. This allows us to remove those paths. Right now,
26
+ # nothing here is tested for cross compiling with Xcode, but it is in principal
27
+ # possible.
28
+ function (escape_llvm_path_for_xcode path outvar )
29
+ # First check if we are using Xcode. If not, return early.
30
+ if (NOT XCODE )
31
+ set (${outvar} "${path} " PARENT_SCOPE )
32
+ return ()
33
+ endif ()
34
+
35
+ get_effective_platform_for_triple ("${SWIFT_HOST_TRIPLE} " SWIFT_EFFECTIVE_PLATFORM_NAME )
36
+ string (REPLACE "$(CONFIGURATION)" "${LLVM_BUILD_TYPE} " path "${path} " )
37
+ string (REPLACE "$(EFFECTIVE_PLATFORM_NAME)" "${SWIFT_EFFECTIVE_PLATFORM_NAME} " path "${path} " )
38
+ set (${outvar} "${path} " PARENT_SCOPE )
39
+ endfunction ()
40
+
41
+ function (get_imported_library_prefix outvar target prefix )
42
+ string (FIND "${target} " "${prefix} " ALREADY_HAS_PREFIX )
43
+ if (ALREADY_HAS_PREFIX )
44
+ set (${outvar} "" PARENT_SCOPE )
45
+ else ()
46
+ set (${outvar} "${prefix} " PARENT_SCOPE )
47
+ endif ()
48
+ endfunction ()
49
+
50
+ function (check_imported_target_has_imported_configuration target config )
51
+ get_target_property (IMPORTED_CONFIGS_LIST ${target} IMPORTED_CONFIGURATIONS )
52
+ if ("${IMPORTED_CONFIGS_LIST} " STREQUAL "NOTFOUND" )
53
+ message (FATAL_ERROR "No import configuration of ${target} specified?!" )
54
+ endif ()
55
+
56
+ list (FIND "${IMPORTED_CONFIGS_LIST} " "${config} " FOUND_CONFIG )
57
+ if (NOT FOUND_CONFIG )
58
+ message (FATAL_ERROR "${target} does not have imported config '${config} '?! \
59
+ Instead: ${IMPORTED_CONFIGS_LIST} " )
60
+ endif ()
61
+ endfunction ()
62
+
63
+ function (fixup_imported_target_property_for_xcode target property real_build_type )
64
+ set (FULL_PROP_NAME "${property} _${real_build_type} " )
65
+
66
+ # First try to lookup the value associated with the "real build type".
67
+ get_target_property (PROP_VALUE ${target} ${FULL_PROP_NAME} )
68
+
69
+ # If the property is unspecified, return.
70
+ if ("${PROP_VALUE} " STREQUAL "NOTFOUND" )
71
+ return ()
72
+ endif ()
73
+
74
+ # Otherwise for each cmake configuration that is not real_build_type, hardcode
75
+ # its value to be PROP_VALUE.
76
+ foreach (c ${CMAKE_CONFIGURATION_TYPES} )
77
+ if ("${c} " STREQUAL "${real_build_type} " )
78
+ continue ()
79
+ endif ()
80
+ set_target_properties (${target} PROPERTIES ${FULL_PROP_NAME} "${PROP_VALUE} " )
81
+ endforeach ()
82
+ endfunction ()
83
+
84
+ # When building with Xcode, we only support compiling against the LLVM
85
+ # configuration that was specified by build-script. This becomes a problem since
86
+ # if we compile LLVM-Release and Swift-Debug, Swift is going to look in the
87
+ # Debug, not the Release folder for LLVM's code and thus will be compiling
88
+ # against an unintended set of libraries, if those libraries exist at all.
89
+ #
90
+ # Luckily, via LLVMConfig.cmake, we know the configuration that LLVM was
91
+ # compiled in, so we can grab the imported location for that configuration and
92
+ # splat it across the other configurations as well.
93
+ function (fix_imported_targets_for_xcode imported_targets )
94
+ # This is the set of configuration specific cmake properties that are
95
+ # supported for imported targets in cmake 3.4.3. Sadly, beyond hacks, it seems
96
+ # that there is no way to dynamically query the list of set properties of a
97
+ # target.
98
+ #
99
+ # *NOTE* In fixup_imported_target_property_for_xcode, we add the _${CONFIG}
100
+ # *suffix.
101
+ set (imported_target_properties
102
+ IMPORTED_IMPLIB
103
+ IMPORTED_LINK_DEPENDENT_LIBRARIES
104
+ IMPORTED_LINK_INTERFACE_LANGUAGES
105
+ IMPORTED_LINK_INTERFACE_LIBRARIES
106
+ IMPORTED_LINK_INTERFACE_MULTIPLICITY
107
+ IMPORTED_LOCATION
108
+ IMPORTED_NO_SONAME
109
+ IMPORTED_SONAME )
110
+
111
+ foreach (target ${imported_targets} )
112
+ if (NOT TARGET ${target} )
113
+ message (FATAL_ERROR "${target} is not a target?!" )
114
+ endif ()
115
+
116
+ # First check that we actually imported the configuration that LLVM said
117
+ # that we did. This is just a sanity check.
118
+ check_imported_target_has_imported_configuration (${target} ${LLVM_BUILD_TYPE} )
119
+
120
+ # Then loop through all of the imported properties and translate.
121
+ foreach (property ${imported_properties} )
122
+ fixup_imported_target_property_for_xcode (
123
+ ${target} ${property} ${LLVM_BUILD_TYPE} )
124
+ endforeach ()
125
+ endforeach ()
126
+ endfunction ()
127
+
128
+ # Common additional cmake project config for Xcode.
129
+ #
130
+ macro (swift_common_xcode_cxx_config )
131
+ # Force usage of Clang.
132
+ set (CMAKE_XCODE_ATTRIBUTE_GCC_VERSION "com.apple.compilers.llvm.clang.1_0"
133
+ CACHE STRING "Xcode Compiler" )
134
+ # Use C++'11.
135
+ set (CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD "c++11"
136
+ CACHE STRING "Xcode C++ Language Standard" )
137
+ # Use libc++.
138
+ set (CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++"
139
+ CACHE STRING "Xcode C++ Standard Library" )
140
+ # Enable some warnings not enabled by default. These
141
+ # mostly reset clang back to its default settings, since
142
+ # Xcode passes -Wno... for many warnings that are not enabled
143
+ # by default.
144
+ set (CMAKE_XCODE_ATTRIBUTE_GCC_WARN_ABOUT_RETURN_TYPE "YES" )
145
+ set (CMAKE_XCODE_ATTRIBUTE_GCC_WARN_ABOUT_MISSING_NEWLINE "YES" )
146
+ set (CMAKE_XCODE_ATTRIBUTE_GCC_WARN_UNUSED_VALUE "YES" )
147
+ set (CMAKE_XCODE_ATTRIBUTE_GCC_WARN_UNUSED_VARIABLE "YES" )
148
+ set (CMAKE_XCODE_ATTRIBUTE_GCC_WARN_SIGN_COMPARE "YES" )
149
+ set (CMAKE_XCODE_ATTRIBUTE_GCC_WARN_UNUSED_FUNCTION "YES" )
150
+ set (CMAKE_XCODE_ATTRIBUTE_GCC_WARN_HIDDEN_VIRTUAL_FUNCTIONS "YES" )
151
+ set (CMAKE_XCODE_ATTRIBUTE_GCC_WARN_UNINITIALIZED_AUTOS "YES" )
152
+ set (CMAKE_XCODE_ATTRIBUTE_CLANG_WARN_DOCUMENTATION_COMMENTS "YES" )
153
+ set (CMAKE_XCODE_ATTRIBUTE_CLANG_WARN_BOOL_CONVERSION "YES" )
154
+ set (CMAKE_XCODE_ATTRIBUTE_CLANG_WARN_EMPTY_BODY "YES" )
155
+ set (CMAKE_XCODE_ATTRIBUTE_CLANG_WARN_ENUM_CONVERSION "YES" )
156
+ set (CMAKE_XCODE_ATTRIBUTE_CLANG_WARN_INT_CONVERSION "YES" )
157
+ set (CMAKE_XCODE_ATTRIBUTE_CLANG_WARN_CONSTANT_CONVERSION "YES" )
158
+ set (CMAKE_XCODE_ATTRIBUTE_GCC_WARN_NON_VIRTUAL_DESTRUCTOR "YES" )
159
+
160
+ # Disable RTTI
161
+ set (CMAKE_XCODE_ATTRIBUTE_GCC_ENABLE_CPP_RTTI "NO" )
162
+
163
+ # Disable exceptions
164
+ set (CMAKE_XCODE_ATTRIBUTE_GCC_ENABLE_CPP_EXCEPTIONS "NO" )
165
+ endmacro ()
166
+
167
+ # Additional cmake variables for Xcode.
168
+ macro (swift_common_xcode_cxx_config )
169
+ # Force usage of Clang.
170
+ set (CMAKE_XCODE_ATTRIBUTE_GCC_VERSION "com.apple.compilers.llvm.clang.1_0"
171
+ CACHE STRING "Xcode Compiler" )
172
+ # Use C++'11.
173
+ set (CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD "c++11"
174
+ CACHE STRING "Xcode C++ Language Standard" )
175
+ # Use libc++.
176
+ set (CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++"
177
+ CACHE STRING "Xcode C++ Standard Library" )
178
+ # Enable some warnings not enabled by default. These
179
+ # mostly reset clang back to its default settings, since
180
+ # Xcode passes -Wno... for many warnings that are not enabled
181
+ # by default.
182
+ set (CMAKE_XCODE_ATTRIBUTE_GCC_WARN_ABOUT_RETURN_TYPE "YES" )
183
+ set (CMAKE_XCODE_ATTRIBUTE_GCC_WARN_ABOUT_MISSING_NEWLINE "YES" )
184
+ set (CMAKE_XCODE_ATTRIBUTE_GCC_WARN_UNUSED_VALUE "YES" )
185
+ set (CMAKE_XCODE_ATTRIBUTE_GCC_WARN_UNUSED_VARIABLE "YES" )
186
+ set (CMAKE_XCODE_ATTRIBUTE_GCC_WARN_SIGN_COMPARE "YES" )
187
+ set (CMAKE_XCODE_ATTRIBUTE_GCC_WARN_UNUSED_FUNCTION "YES" )
188
+ set (CMAKE_XCODE_ATTRIBUTE_GCC_WARN_HIDDEN_VIRTUAL_FUNCTIONS "YES" )
189
+ set (CMAKE_XCODE_ATTRIBUTE_GCC_WARN_UNINITIALIZED_AUTOS "YES" )
190
+ set (CMAKE_XCODE_ATTRIBUTE_CLANG_WARN_DOCUMENTATION_COMMENTS "YES" )
191
+ set (CMAKE_XCODE_ATTRIBUTE_CLANG_WARN_BOOL_CONVERSION "YES" )
192
+ set (CMAKE_XCODE_ATTRIBUTE_CLANG_WARN_EMPTY_BODY "YES" )
193
+ set (CMAKE_XCODE_ATTRIBUTE_CLANG_WARN_ENUM_CONVERSION "YES" )
194
+ set (CMAKE_XCODE_ATTRIBUTE_CLANG_WARN_INT_CONVERSION "YES" )
195
+ set (CMAKE_XCODE_ATTRIBUTE_CLANG_WARN_CONSTANT_CONVERSION "YES" )
196
+ set (CMAKE_XCODE_ATTRIBUTE_GCC_WARN_NON_VIRTUAL_DESTRUCTOR "YES" )
197
+
198
+ # Disable RTTI
199
+ set (CMAKE_XCODE_ATTRIBUTE_GCC_ENABLE_CPP_RTTI "NO" )
200
+
201
+ # Disable exceptions
202
+ set (CMAKE_XCODE_ATTRIBUTE_GCC_ENABLE_CPP_EXCEPTIONS "NO" )
203
+ endmacro ()
204
+
0 commit comments