Skip to content

Commit 29ddcd8

Browse files
authored
Merge pull request #3413 from gottesmm/cmake-refactor-xcode-support
Cmake refactor xcode support
2 parents 1f63d98 + b42b7f4 commit 29ddcd8

File tree

5 files changed

+199
-169
lines changed

5 files changed

+199
-169
lines changed

CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,6 @@ include(AddSwift)
356356
include(SwiftConfigureSDK)
357357
include(SwiftInstallComponents)
358358
include(SwiftGetConfigurationTypes)
359-
include(SwiftApplyXcodeSubstitutions)
360359
include(SwiftList)
361360

362361
swift_configure_install_components("${SWIFT_INSTALL_COMPONENTS}")

cmake/modules/AddSwift.cmake

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
include(SwiftList)
2+
include(SwiftXcodeSupport)
23

34
# SWIFTLIB_DIR is the directory in the build tree where Swift resource files
45
# should be placed. Note that $CMAKE_CFG_INTDIR expands to "." for
@@ -677,7 +678,7 @@ function(_add_swift_library_single target name)
677678

678679
foreach(config ${CMAKE_CONFIGURATION_TYPES})
679680
string(TOUPPER ${config} config_upper)
680-
apply_xcode_substitutions("${config}" "${SWIFTLIB_DIR}" config_lib_dir)
681+
escape_path_for_xcode("${config}" "${SWIFTLIB_DIR}" config_lib_dir)
681682
set_target_properties(${target} PROPERTIES
682683
LIBRARY_OUTPUT_DIRECTORY_${config_upper} ${config_lib_dir}/${SWIFTLIB_SINGLE_SUBDIR}
683684
ARCHIVE_OUTPUT_DIRECTORY_${config_upper} ${config_lib_dir}/${SWIFTLIB_SINGLE_SUBDIR})
@@ -731,7 +732,7 @@ function(_add_swift_library_single target name)
731732

732733
foreach(config ${CMAKE_CONFIGURATION_TYPES})
733734
string(TOUPPER ${config} config_upper)
734-
apply_xcode_substitutions(
735+
escape_path_for_xcode(
735736
"${config}" "${SWIFTSTATICLIB_DIR}" config_lib_dir)
736737
set_target_properties(${target_static} PROPERTIES
737738
LIBRARY_OUTPUT_DIRECTORY_${config_upper} ${config_lib_dir}/${SWIFTLIB_SINGLE_SUBDIR}

cmake/modules/SwiftApplyXcodeSubstitutions.cmake

Lines changed: 0 additions & 9 deletions
This file was deleted.

cmake/modules/SwiftSharedCMakeConfig.cmake

Lines changed: 5 additions & 157 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)
@@ -170,14 +57,14 @@ macro(swift_common_standalone_build_config_llvm product is_cross_compiling)
17057
mark_as_advanced(LLVM_ENABLE_ASSERTIONS)
17158

17259
precondition(LLVM_TOOLS_BINARY_DIR)
173-
escape_llvm_path_for_xcode("${LLVM_TOOLS_BINARY_DIR}" LLVM_TOOLS_BINARY_DIR)
60+
escape_path_for_xcode("${LLVM_BUILD_TYPE}" "${LLVM_TOOLS_BINARY_DIR}" LLVM_TOOLS_BINARY_DIR)
17461
precondition_translate_flag(LLVM_BUILD_LIBRARY_DIR LLVM_LIBRARY_DIR)
175-
escape_llvm_path_for_xcode("${LLVM_LIBRARY_DIR}" LLVM_LIBRARY_DIR)
62+
escape_path_for_xcode("${LLVM_BUILD_TYPE}" "${LLVM_LIBRARY_DIR}" LLVM_LIBRARY_DIR)
17663
precondition_translate_flag(LLVM_BUILD_MAIN_INCLUDE_DIR LLVM_MAIN_INCLUDE_DIR)
17764
precondition_translate_flag(LLVM_BUILD_BINARY_DIR LLVM_BINARY_DIR)
17865
precondition_translate_flag(LLVM_BUILD_MAIN_SRC_DIR LLVM_MAIN_SRC_DIR)
17966
precondition(LLVM_LIBRARY_DIRS)
180-
escape_llvm_path_for_xcode("${LLVM_LIBRARY_DIRS}" LLVM_LIBRARY_DIRS)
67+
escape_path_for_xcode("${LLVM_BUILD_TYPE}" "${LLVM_LIBRARY_DIRS}" LLVM_LIBRARY_DIRS)
18168

18269
# This could be computed using ${CMAKE_CFG_INTDIR} if we want to link Swift
18370
# against a matching LLVM build configuration. However, we usually want to be
@@ -215,7 +102,7 @@ macro(swift_common_standalone_build_config_llvm product is_cross_compiling)
215102
"Version number that will be placed into the libclang library , in the form XX.YY")
216103

217104
foreach (INCLUDE_DIR ${LLVM_INCLUDE_DIRS})
218-
escape_llvm_path_for_xcode("${INCLUDE_DIR}" INCLUDE_DIR)
105+
escape_path_for_xcode("${LLVM_BUILD_TYPE}" "${INCLUDE_DIR}" INCLUDE_DIR)
219106
include_directories(${INCLUDE_DIR})
220107
endforeach ()
221108

@@ -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)

0 commit comments

Comments
 (0)