Skip to content

Commit

Permalink
Allow libraries to specify to be compiled against the internal varian…
Browse files Browse the repository at this point in the history
…t of the SDKs

We will need this to switch the darwin targets over to use ICU instead of going
to NSString for string operations. The public SDK does not contain the headers
for ICU - only the dylib.

For builds using a public SDK users can specify the path to an ICU install where
the headers can be found. If this path is specified the logic will not use
internal SDK variants.

Swift SVN r31471
  • Loading branch information
aschwaighofer committed Aug 26, 2015
1 parent a75b083 commit f6224bd
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 12 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ option(SWIFT_RUNTIME_CRASH_REPORTER_CLIENT
"Whether to enable CrashReporter integration"
FALSE)

set(SWIFT_DARWIN_ICU_INCLUDE_PATH "" CACHE STRING
"Path to the directory where the ICU headers are located")

#
# User-configurable debugging options.
#
Expand Down
59 changes: 47 additions & 12 deletions cmake/modules/AddSwift.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,18 @@ endfunction()


function(_add_variant_c_compile_link_flags
sdk arch build_type enable_assertions result_var_name)
set(result ${${result_var_name}})
sdk arch build_type enable_assertions use_internal_sdk result_var_name)
set(result
${${result_var_name}}
"-target" "${SWIFT_SDK_${sdk}_ARCH_${arch}_TRIPLE}")

list(APPEND result
"-isysroot" "${SWIFT_SDK_${sdk}_PATH}"
"-target" "${SWIFT_SDK_${sdk}_ARCH_${arch}_TRIPLE}")
if(use_internal_sdk)
list(APPEND result
"-isysroot" "${SWIFT_SDK_${sdk}_INTERNAL_PATH}")
else()
list(APPEND result
"-isysroot" "${SWIFT_SDK_${sdk}_PATH}")
endif()

if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
list(APPEND result
Expand All @@ -59,14 +65,15 @@ function(_add_variant_c_compile_link_flags
endfunction()

function(_add_variant_c_compile_flags
sdk arch build_type enable_assertions result_var_name)
sdk arch build_type enable_assertions use_internal_sdk result_var_name)
set(result ${${result_var_name}})

_add_variant_c_compile_link_flags(
"${sdk}"
"${arch}"
"${build_type}"
"${enable_assertions}"
${use_internal_sdk}
result)

is_build_type_optimized("${build_type}" optimized)
Expand Down Expand Up @@ -135,7 +142,7 @@ function(_add_variant_swift_compile_flags
endfunction()

function(_add_variant_link_flags
sdk arch build_type enable_assertions result_var_name)
sdk arch build_type enable_assertions use_internal_sdk result_var_name)

if("${sdk}" STREQUAL "")
message(FATAL_ERROR "Should specify an SDK")
Expand All @@ -152,6 +159,7 @@ function(_add_variant_link_flags
"${arch}"
"${build_type}"
"${enable_assertions}"
${use_internal_sdk}
result)

if("${sdk}" STREQUAL "LINUX")
Expand Down Expand Up @@ -626,6 +634,7 @@ endfunction()
# _add_swift_library_single(
# target
# name
# [USE_INTERNAL_SDK]
# [SHARED]
# [SDK sdk]
# [ARCHITECTURE architecture]
Expand Down Expand Up @@ -706,12 +715,15 @@ endfunction()
# INSTALL_IN_COMPONENT comp
# The Swift installation component that this library belongs to.
#
# USE_INTERNAL_SDK
# Use the 'internal' sdk variant.
#
# source1 ...
# Sources to add into this library
function(_add_swift_library_single target name)
set(SWIFTLIB_SINGLE_options
SHARED IS_STDLIB IS_STDLIB_CORE IS_SDK_OVERLAY
API_NOTES_NON_OVERLAY DONT_EMBED_BITCODE)
API_NOTES_NON_OVERLAY DONT_EMBED_BITCODE USE_INTERNAL_SDK)
cmake_parse_arguments(SWIFTLIB_SINGLE
"${SWIFTLIB_SINGLE_options}"
"SDK;ARCHITECTURE;INSTALL_IN_COMPONENT"
Expand Down Expand Up @@ -963,9 +975,17 @@ function(_add_swift_library_single target name)
target_link_libraries("${target}" INTERFACE ${SWIFTLIB_SINGLE_LINK_LIBRARIES})
endif()

# Don't add the icucore target.
set(SWIFTLIB_SINGLE_LINK_LIBRARIES_WITHOUT_ICU)
foreach(item ${SWIFTLIB_SINGLE_LINK_LIBRARIES})
if(NOT "${item}" STREQUAL "icucore")
list(APPEND SWIFTLIB_SINGLE_LINK_LIBRARIES_WITHOUT_ICU "{$item}")
endif()
endforeach()

if(target_static)
_list_add_string_suffix(
"${SWIFTLIB_SINGLE_LINK_LIBRARIES}"
"${SWIFTLIB_SINGLE_LINK_LIBRARIES_WITHOUT_ICU}"
"-static"
target_static_depends)
# FIXME: should this be target_link_libraries?
Expand Down Expand Up @@ -1006,12 +1026,14 @@ function(_add_swift_library_single target name)
"${SWIFTLIB_SINGLE_ARCHITECTURE}"
"${build_type}"
"${enable_assertions}"
${SWIFTLIB_SINGLE_USE_INTERNAL_SDK}
c_compile_flags)
_add_variant_link_flags(
"${SWIFTLIB_SINGLE_SDK}"
"${SWIFTLIB_SINGLE_ARCHITECTURE}"
"${build_type}"
"${enable_assertions}"
${SWIFTLIB_SINGLE_USE_INTERNAL_SDK}
link_flags)

# Configure plist creation for OS X.
Expand Down Expand Up @@ -1187,12 +1209,15 @@ endfunction()
# INSTALL_IN_COMPONENT comp
# The Swift installation component that this library belongs to.
#
# USE_INTERNAL_SDK
# Use the 'internal' sdk variant.
#
# source1 ...
# Sources to add into this library.
function(add_swift_library name)
set(SWIFTLIB_options
SHARED IS_STDLIB IS_STDLIB_CORE IS_SDK_OVERLAY TARGET_LIBRARY
API_NOTES_NON_OVERLAY DONT_EMBED_BITCODE)
API_NOTES_NON_OVERLAY DONT_EMBED_BITCODE USE_INTERNAL_SDK)
cmake_parse_arguments(SWIFTLIB
"${SWIFTLIB_options}"
"INSTALL_IN_COMPONENT"
Expand Down Expand Up @@ -1328,6 +1353,7 @@ function(add_swift_library name)
_add_swift_library_single(
${VARIANT_NAME}
${name}
${SWIFTLIB_USE_INTERNAL_SDK_keyword}
${SWIFTLIB_SHARED_keyword}
${SWIFTLIB_SOURCES}
SDK ${sdk}
Expand All @@ -1351,15 +1377,19 @@ function(add_swift_library name)

# Add dependencies on the (not-yet-created) custom lipo target.
foreach(DEP ${SWIFTLIB_LINK_LIBRARIES})
add_dependencies(${VARIANT_NAME}
if (NOT "${DEP}" STREQUAL "icucore")
add_dependencies(${VARIANT_NAME}
"${DEP}-${SWIFT_SDK_${sdk}_LIB_SUBDIR}")
endif()
endforeach()

if (SWIFT_BUILD_STATIC_STDLIB AND SWIFTLIB_IS_STDLIB)
# Add dependencies on the (not-yet-created) custom lipo target.
foreach(DEP ${SWIFTLIB_LINK_LIBRARIES})
add_dependencies("${VARIANT_NAME}-static"
if (NOT "${DEP}" STREQUAL "icucore")
add_dependencies("${VARIANT_NAME}-static"
"${DEP}-${SWIFT_SDK_${sdk}_LIB_SUBDIR}-static")
endif()
endforeach()
endif()

Expand Down Expand Up @@ -1490,6 +1520,7 @@ function(add_swift_library name)
_add_swift_library_single(
${name}
${name}
${SWIFTLIB_USE_INTERNAL_SDK_keyword}
${SWIFTLIB_SHARED_keyword}
${SWIFTLIB_SOURCES}
SDK ${sdk}
Expand Down Expand Up @@ -1563,12 +1594,14 @@ function(_add_swift_executable_single name)
"${SWIFTEXE_SINGLE_ARCHITECTURE}"
"${CMAKE_BUILD_TYPE}"
"${LLVM_ENABLE_ASSERTIONS}"
FALSE
c_compile_flags)
_add_variant_link_flags(
"${SWIFTEXE_SINGLE_SDK}"
"${SWIFTEXE_SINGLE_ARCHITECTURE}"
"${CMAKE_BUILD_TYPE}"
"${LLVM_ENABLE_ASSERTIONS}"
FALSE
link_flags)

list(APPEND link_flags
Expand Down Expand Up @@ -1801,6 +1834,7 @@ function(add_swift_llvm_loadable_module name)
"${arch}"
"${CMAKE_BUILD_TYPE}"
"${LLVM_ENABLE_ASSERTIONS}"
FALSE
c_compile_flags)

set(link_flags)
Expand All @@ -1809,6 +1843,7 @@ function(add_swift_llvm_loadable_module name)
"${arch}"
"${CMAKE_BUILD_TYPE}"
"${LLVM_ENABLE_ASSERTIONS}"
FALSE
link_flags)

# Convert variables to space-separated strings.
Expand Down
20 changes: 20 additions & 0 deletions cmake/modules/SwiftConfigureSDK.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,25 @@ macro(configure_sdk_darwin
set(SWIFT_SDK_${prefix}_PATH "${SWIFT_SDK_${prefix}_PUBLIC_PATH}")
endif()

# Find the internal SDK if the user has not specified to use an external ICU
# library. Otherwise, we will just use the regular SDK.
set(SWIFT_SDK_${prefix}_INTERNAL_PATH "" CACHE PATH "Path to the internal ${name} SDK")
if (NOT SWIFT_DARWIN_ICU_INCLUDE_PATH)
if ("${prefix}" STREQUAL "IOS_SIMULATOR" OR
"${prefix}" STREQUAL "WATCHOS_SIMULATOR" OR
"${prefix}" STREQUAL "TVOS_SIMULATOR")
set(SWIFT_SDK_${prefix}_INTERNAL_PATH "${SWIFT_SDK_${prefix}_PATH}")
else()
execute_process(
COMMAND "xcrun" "--sdk" "${xcrun_name}.internal" "--show-sdk-path"
OUTPUT_VARIABLE SWIFT_SDK_${prefix}_INTERNAL_PATH
OUTPUT_STRIP_TRAILING_WHITESPACE)
endif()
else()
set(SWIFT_SDK_${prefix}_INTERNAL_PATH "${SWIFT_SDK_${prefix}_PATH}")
endif()


if(NOT EXISTS "${SWIFT_SDK_${prefix}_PATH}/System/Library/Frameworks/module.map")
message(FATAL_ERROR "${name} SDK not found at SWIFT_SDK_${prefix}_PATH.")
endif()
Expand Down Expand Up @@ -139,6 +158,7 @@ macro(configure_sdk_unix
set(SWIFT_SDK_${prefix}_NAME "${name}")
set(SWIFT_SDK_${prefix}_PATH "/")
set(SWIFT_SDK_${prefix}_PUBLIC_PATH "/")
set(SWIFT_SDK_${prefix}_INTERNAL_PATH "/")
set(SWIFT_SDK_${prefix}_VERSION "don't use")
set(SWIFT_SDK_${prefix}_BUILD_NUMBER "don't use")
set(SWIFT_SDK_${prefix}_DEPLOYMENT_VERSION "don't use")
Expand Down

0 comments on commit f6224bd

Please sign in to comment.