Skip to content

Commit 455d3a1

Browse files
committed
[cmake] Move the cmake xcode configuration code from SwiftSharedCMakeConfig.cmake => SwiftXcodeSupport.cmake.
1 parent 0e95abd commit 455d3a1

File tree

2 files changed

+193
-153
lines changed

2 files changed

+193
-153
lines changed

cmake/modules/SwiftSharedCMakeConfig.cmake

Lines changed: 1 addition & 153 deletions
Original file line numberDiff line numberDiff line change
@@ -12,120 +12,7 @@ else()
1212
set(cmake_3_2_USES_TERMINAL USES_TERMINAL)
1313
endif()
1414

15-
function(get_effective_platform_for_triple triple output)
16-
string(FIND "${triple}" "macos" IS_MACOS)
17-
if (IS_MACOS)
18-
set(${output} "" PARENT_SCOPE)
19-
return()
20-
endif()
21-
message(FATAL_ERROR "Not supported")
22-
endfunction()
23-
24-
# Eliminate $(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) from a path.
25-
#
26-
# We do not support compiling llvm with an Xcode setting beyond the one that was
27-
# used with build-script. This allows us to remove those paths. Right now,
28-
# nothing here is tested for cross compiling with Xcode, but it is in principal
29-
# possible.
30-
function(escape_llvm_path_for_xcode path outvar)
31-
# First check if we are using Xcode. If not, return early.
32-
if (NOT XCODE)
33-
set(${outvar} "${path}" PARENT_SCOPE)
34-
return()
35-
endif()
36-
37-
get_effective_platform_for_triple("${SWIFT_HOST_TRIPLE}" SWIFT_EFFECTIVE_PLATFORM_NAME)
38-
string(REPLACE "$(CONFIGURATION)" "${LLVM_BUILD_TYPE}" path "${path}")
39-
string(REPLACE "$(EFFECTIVE_PLATFORM_NAME)" "${SWIFT_EFFECTIVE_PLATFORM_NAME}" path "${path}")
40-
set(${outvar} "${path}" PARENT_SCOPE)
41-
endfunction()
42-
43-
function(get_imported_library_prefix outvar target prefix)
44-
string(FIND "${target}" "${prefix}" ALREADY_HAS_PREFIX)
45-
if (ALREADY_HAS_PREFIX)
46-
set(${outvar} "" PARENT_SCOPE)
47-
else()
48-
set(${outvar} "${prefix}" PARENT_SCOPE)
49-
endif()
50-
endfunction()
51-
52-
function(check_imported_target_has_imported_configuration target config)
53-
get_target_property(IMPORTED_CONFIGS_LIST ${target} IMPORTED_CONFIGURATIONS)
54-
if ("${IMPORTED_CONFIGS_LIST}" STREQUAL "NOTFOUND")
55-
message(FATAL_ERROR "No import configuration of ${target} specified?!")
56-
endif()
57-
58-
list(FIND "${IMPORTED_CONFIGS_LIST}" "${config}" FOUND_CONFIG)
59-
if (NOT FOUND_CONFIG)
60-
message(FATAL_ERROR "${target} does not have imported config '${config}'?! \
61-
Instead: ${IMPORTED_CONFIGS_LIST}")
62-
endif()
63-
endfunction()
64-
65-
function(fixup_imported_target_property_for_xcode target property real_build_type)
66-
set(FULL_PROP_NAME "${property}_${real_build_type}")
67-
68-
# First try to lookup the value associated with the "real build type".
69-
get_target_property(PROP_VALUE ${target} ${FULL_PROP_NAME})
70-
71-
# If the property is unspecified, return.
72-
if ("${PROP_VALUE}" STREQUAL "NOTFOUND")
73-
return()
74-
endif()
75-
76-
# Otherwise for each cmake configuration that is not real_build_type, hardcode
77-
# its value to be PROP_VALUE.
78-
foreach(c ${CMAKE_CONFIGURATION_TYPES})
79-
if ("${c}" STREQUAL "${real_build_type}")
80-
continue()
81-
endif()
82-
set_target_properties(${target} PROPERTIES ${FULL_PROP_NAME} "${PROP_VALUE}")
83-
endforeach()
84-
endfunction()
85-
86-
# When building with Xcode, we only support compiling against the LLVM
87-
# configuration that was specified by build-script. This becomes a problem since
88-
# if we compile LLVM-Release and Swift-Debug, Swift is going to look in the
89-
# Debug, not the Release folder for LLVM's code and thus will be compiling
90-
# against an unintended set of libraries, if those libraries exist at all.
91-
#
92-
# Luckily, via LLVMConfig.cmake, we know the configuration that LLVM was
93-
# compiled in, so we can grab the imported location for that configuration and
94-
# splat it across the other configurations as well.
95-
function(fix_imported_targets_for_xcode imported_targets)
96-
# This is the set of configuration specific cmake properties that are
97-
# supported for imported targets in cmake 3.4.3. Sadly, beyond hacks, it seems
98-
# that there is no way to dynamically query the list of set properties of a
99-
# target.
100-
#
101-
# *NOTE* In fixup_imported_target_property_for_xcode, we add the _${CONFIG}
102-
# *suffix.
103-
set(imported_target_properties
104-
IMPORTED_IMPLIB
105-
IMPORTED_LINK_DEPENDENT_LIBRARIES
106-
IMPORTED_LINK_INTERFACE_LANGUAGES
107-
IMPORTED_LINK_INTERFACE_LIBRARIES
108-
IMPORTED_LINK_INTERFACE_MULTIPLICITY
109-
IMPORTED_LOCATION
110-
IMPORTED_NO_SONAME
111-
IMPORTED_SONAME)
112-
113-
foreach(target ${imported_targets})
114-
if (NOT TARGET ${target})
115-
message(FATAL_ERROR "${target} is not a target?!")
116-
endif()
117-
118-
# First check that we actually imported the configuration that LLVM said
119-
# that we did. This is just a sanity check.
120-
check_imported_target_has_imported_configuration(${target} ${LLVM_BUILD_TYPE})
121-
122-
# Then loop through all of the imported properties and translate.
123-
foreach(property ${imported_properties})
124-
fixup_imported_target_property_for_xcode(
125-
${target} ${property} ${LLVM_BUILD_TYPE})
126-
endforeach()
127-
endforeach()
128-
endfunction()
15+
include(SwiftXcodeSupport)
12916

13017
macro(swift_common_standalone_build_config_llvm product is_cross_compiling)
13118
option(LLVM_ENABLE_WARNINGS "Enable compiler warnings." ON)
@@ -371,45 +258,6 @@ macro(swift_common_unified_build_config product)
371258
endif()
372259
endmacro()
373260

374-
# Common additional cmake project config for Xcode.
375-
#
376-
macro(swift_common_xcode_cxx_config)
377-
# Force usage of Clang.
378-
set(CMAKE_XCODE_ATTRIBUTE_GCC_VERSION "com.apple.compilers.llvm.clang.1_0"
379-
CACHE STRING "Xcode Compiler")
380-
# Use C++'11.
381-
set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD "c++11"
382-
CACHE STRING "Xcode C++ Language Standard")
383-
# Use libc++.
384-
set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++"
385-
CACHE STRING "Xcode C++ Standard Library")
386-
# Enable some warnings not enabled by default. These
387-
# mostly reset clang back to its default settings, since
388-
# Xcode passes -Wno... for many warnings that are not enabled
389-
# by default.
390-
set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_ABOUT_RETURN_TYPE "YES")
391-
set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_ABOUT_MISSING_NEWLINE "YES")
392-
set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_UNUSED_VALUE "YES")
393-
set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_UNUSED_VARIABLE "YES")
394-
set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_SIGN_COMPARE "YES")
395-
set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_UNUSED_FUNCTION "YES")
396-
set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_HIDDEN_VIRTUAL_FUNCTIONS "YES")
397-
set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_UNINITIALIZED_AUTOS "YES")
398-
set(CMAKE_XCODE_ATTRIBUTE_CLANG_WARN_DOCUMENTATION_COMMENTS "YES")
399-
set(CMAKE_XCODE_ATTRIBUTE_CLANG_WARN_BOOL_CONVERSION "YES")
400-
set(CMAKE_XCODE_ATTRIBUTE_CLANG_WARN_EMPTY_BODY "YES")
401-
set(CMAKE_XCODE_ATTRIBUTE_CLANG_WARN_ENUM_CONVERSION "YES")
402-
set(CMAKE_XCODE_ATTRIBUTE_CLANG_WARN_INT_CONVERSION "YES")
403-
set(CMAKE_XCODE_ATTRIBUTE_CLANG_WARN_CONSTANT_CONVERSION "YES")
404-
set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_NON_VIRTUAL_DESTRUCTOR "YES")
405-
406-
# Disable RTTI
407-
set(CMAKE_XCODE_ATTRIBUTE_GCC_ENABLE_CPP_RTTI "NO")
408-
409-
# Disable exceptions
410-
set(CMAKE_XCODE_ATTRIBUTE_GCC_ENABLE_CPP_EXCEPTIONS "NO")
411-
endmacro()
412-
413261
# Common cmake project config for additional warnings.
414262
#
415263
macro(swift_common_cxx_warnings)

cmake/modules/SwiftXcodeSupport.cmake

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,195 @@ function(apply_xcode_substitutions config path result_var_name)
1010
set("${result_var_name}" "${result}" PARENT_SCOPE)
1111
endfunction()
1212

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

Comments
 (0)