@@ -535,11 +535,8 @@ function(_add_swift_lipo_target)
535
535
DEPENDS ${source_targets} )
536
536
else ()
537
537
# We don't know how to create fat binaries for other platforms.
538
- add_custom_command_target (unused_var
539
- COMMAND "${CMAKE_COMMAND} " "-E" "copy" "${source_binaries} " "${LIPO_OUTPUT} "
540
- CUSTOM_TARGET_NAME "${LIPO_TARGET} "
541
- OUTPUT "${LIPO_OUTPUT} "
542
- DEPENDS ${source_targets} )
538
+ message (FATAL_ERROR
539
+ "It's not possible to build a universal binary for a non-MachO target" )
543
540
endif ()
544
541
endfunction ()
545
542
@@ -1147,8 +1144,14 @@ function(_add_swift_library_single target name)
1147
1144
set (link_flags ${SWIFTLIB_SINGLE_LINK_FLAGS} )
1148
1145
set (library_search_directories
1149
1146
"${SWIFTLIB_DIR} /${SWIFTLIB_SINGLE_SUBDIR} "
1150
- "${SWIFT_NATIVE_SWIFT_TOOLS_PATH} /../lib/swift/${SWIFTLIB_SINGLE_SUBDIR} "
1151
- "${SWIFT_NATIVE_SWIFT_TOOLS_PATH} /../lib/swift/${SWIFT_SDK_${SWIFTLIB_SINGLE_SDK} _LIB_SUBDIR}" )
1147
+ "${SWIFT_NATIVE_SWIFT_TOOLS_PATH} /../lib/swift/${SWIFTLIB_SINGLE_SUBDIR} " )
1148
+
1149
+ if (IS_DARWIN )
1150
+ # Since we lipo each arch together on Darwin, search in the common directory
1151
+ list (APPEND library_search_directories
1152
+ "${SWIFT_NATIVE_SWIFT_TOOLS_PATH} /../lib/swift/${SWIFT_SDK_${SWIFTLIB_SINGLE_SDK} _LIB_SUBDIR}" )
1153
+ endif ()
1154
+
1152
1155
1153
1156
# Add variant-specific flags.
1154
1157
if (SWIFTLIB_SINGLE_TARGET_LIBRARY )
@@ -1289,8 +1292,12 @@ function(_add_swift_library_single target name)
1289
1292
COMPILE_FLAGS " ${c_compile_flags} " )
1290
1293
set (library_search_directories
1291
1294
"${SWIFTSTATICLIB_DIR} /${SWIFTLIB_SINGLE_SUBDIR} "
1292
- "${SWIFT_NATIVE_SWIFT_TOOLS_PATH} /../lib/swift/${SWIFTLIB_SINGLE_SUBDIR} "
1295
+ "${SWIFT_NATIVE_SWIFT_TOOLS_PATH} /../lib/swift/${SWIFTLIB_SINGLE_SUBDIR} " )
1296
+ if (IS_DARWIN )
1297
+ list (APPEND library_search_directories
1293
1298
"${SWIFT_NATIVE_SWIFT_TOOLS_PATH} /../lib/swift/${SWIFT_SDK_${SWIFTLIB_SINGLE_SDK} _LIB_SUBDIR}" )
1299
+ endif ()
1300
+
1294
1301
swift_target_link_search_directories ("${target_static} " "${library_search_directories} " )
1295
1302
target_link_libraries ("${target_static} " PRIVATE
1296
1303
${SWIFTLIB_SINGLE_PRIVATE_LINK_LIBRARIES} )
@@ -1592,6 +1599,7 @@ function(add_swift_library name)
1592
1599
continue ()
1593
1600
endif ()
1594
1601
1602
+ is_darwin_based_sdk ("${sdk} " IS_DARWIN )
1595
1603
set (THIN_INPUT_TARGETS )
1596
1604
1597
1605
# For each architecture supported by this SDK
@@ -1784,47 +1792,105 @@ function(add_swift_library name)
1784
1792
)
1785
1793
1786
1794
if (NOT SWIFTLIB_OBJECT_LIBRARY )
1787
- # Add dependencies on the (not-yet-created) custom lipo target.
1788
- foreach (DEP ${SWIFTLIB_LINK_LIBRARIES} )
1789
- if (NOT "${DEP} " STREQUAL "icucore" )
1790
- add_dependencies (${VARIANT_NAME}
1791
- "${DEP} -${SWIFT_SDK_${sdk} _LIB_SUBDIR}" )
1795
+ # On Darwin we use lipo'd libraries for dependencies.
1796
+ # On other targets without universal binaries we just install the target lib
1797
+ if (IS_DARWIN )
1798
+ # Add dependencies on the (not-yet-created) custom lipo target.
1799
+ foreach (DEP ${SWIFTLIB_LINK_LIBRARIES} )
1800
+ if (NOT "${DEP} " STREQUAL "icucore" )
1801
+ add_dependencies (${VARIANT_NAME}
1802
+ "${DEP} -${SWIFT_SDK_{sdk}_LIB_SUBDIR}" )
1803
+ endif ()
1804
+ endforeach ()
1805
+
1806
+ if (SWIFTLIB_IS_STDLIB AND SWIFTLIB_STATIC )
1807
+ # Add dependencies on the (not-yet-created) custom lipo target.
1808
+ foreach (DEP ${SWIFTLIB_LINK_LIBRARIES} )
1809
+ if (NOT "${DEP} " STREQUAL "icucore" )
1810
+ add_dependencies ("${VARIANT_NAME} -static"
1811
+ "${DEP} -${SWIFT_SDK_${SDK} _LIB_SUBDIR}-static" )
1812
+ endif ()
1813
+ endforeach ()
1792
1814
endif ()
1793
- endforeach ()
1794
1815
1795
- if ( SWIFTLIB_IS_STDLIB AND SWIFTLIB_STATIC )
1796
- # Add dependencies on the (not-yet-created) custom lipo target.
1816
+ list ( APPEND THIN_INPUT_TARGETS ${VARIANT_NAME} )
1817
+ else ()
1797
1818
foreach (DEP ${SWIFTLIB_LINK_LIBRARIES} )
1798
1819
if (NOT "${DEP} " STREQUAL "icucore" )
1799
- add_dependencies (" ${VARIANT_NAME} -static"
1800
- "${DEP} -${SWIFT_SDK_${sdk} _LIB_SUBDIR}-static " )
1820
+ add_dependencies (${VARIANT_NAME}
1821
+ "${DEP} -${SWIFT_SDK_${sdk} _LIB_SUBDIR}-${arch} " )
1801
1822
endif ()
1802
1823
endforeach ()
1803
- endif ()
1804
1824
1805
- # Note this thin library.
1806
- list (APPEND THIN_INPUT_TARGETS ${VARIANT_NAME} )
1825
+ if (SWIFTLIB_IS_STDLIB AND SWIFTLIB_STATIC )
1826
+ foreach (DEP ${SWIFTLIB_LINK_LIBRARIES} )
1827
+ if (NOT "${DEP} " STREQUAL "icucore" )
1828
+ add_dependencies ("${VARIANT_NAME} -static"
1829
+ "${DEP} -${SWIFT_SDK_${sdk} _LIB_SUBDIR}-${arch} -static" )
1830
+ endif ()
1831
+ endforeach ()
1832
+ endif ()
1833
+
1834
+ if (SWIFTLIB_TARGET_LIBRARY )
1835
+ foreach (arch ${SWIFT_SDK_${sdk}_ARCHITECTURES} )
1836
+ set (VARIANT_SUFFIX "-${SWIFT_SDK_${sdk} _LIB_SUBDIR}-${arch} " )
1837
+ if (TARGET "swift-stdlib${VARIANT_SUFFIX} " AND TARGET "swift-test-stdlib${VARIANT_SUFFIX} " )
1838
+ add_dependencies ("swift-stdlib${VARIANT_SUFFIX} "
1839
+ "${VARIANT_NAME} " )
1840
+ if (SWIFTLIB_IS_STDLIB AND SWIFTLIB_STATIC )
1841
+ add_dependencies ("swift-stdlib${VARIANT_SUFFIX} "
1842
+ "${VARIANT_NAME} -static" )
1843
+ endif ()
1844
+
1845
+ if ((NOT "${name} " STREQUAL "swiftStdlibCollectionUnittest" ) AND
1846
+ (NOT "${name} " STREQUAL "swiftStdlibUnicodeUnittest" ))
1847
+ add_dependencies ("swift-test-stdlib${VARIANT_SUFFIX} "
1848
+ "${VARIANT_NAME} " )
1849
+ if (SWIFTLIB_IS_STDLIB AND SWIFTLIB_STATIC )
1850
+ add_dependencies ("swift-test-stdlib${VARIANT_SUFFIX} "
1851
+ "${VARIANT_NAME} -static" )
1852
+ endif ()
1853
+ endif ()
1854
+ endif ()
1855
+
1856
+ if (SWIFTLIB_SHARED )
1857
+ set (resource_dir "swift" )
1858
+ set (file_permissions
1859
+ OWNER_READ OWNER_WRITE
1860
+ GROUP_READ
1861
+ WORLD_READ )
1862
+ set (install_libpath
1863
+ "${SWIFTLIB_DIR} /${SWIFT_SDK_${sdk} _LIB_SUBDIR}/${arch} /${CMAKE_SHARED_LIBRARY_PREFIX}${name}${CMAKE_SHARED_LIBRARY_SUFFIX} " )
1864
+ else ()
1865
+ set (resource_dir "swift_static" )
1866
+ set (file_permissions
1867
+ OWNER_READ OWNER_WRITE
1868
+ GROUP_READ
1869
+ WORLD_READ )
1870
+ set (install_libpath
1871
+ "${SWIFTLIB_DIR} /${SWIFT_SDK_${sdk} _LIB_SUBDIR}/${arch} /${CMAKE_STATIC_LIBRARY_PREFIX}${name}${CMAKE_STATIC_LIBRARY_SUFFIX} " )
1872
+ endif ()
1873
+
1874
+ swift_install_in_component ("${SWIFTLIB_INSTALL_IN_COMPONENT} "
1875
+ FILES "${install_libpath} "
1876
+ DESTINATION "lib${LLVM_LIBDIR_SUFFIX} /${resource_dir} /${SWIFT_SDK_${sdk} _LIB_SUBDIR}/${arch} "
1877
+ PERMISSIONS ${file_permissions} )
1878
+ endforeach ()
1879
+ endif ()
1880
+ endif ()
1807
1881
endif ()
1808
1882
endforeach ()
1883
+
1809
1884
1810
- if (NOT SWIFTLIB_OBJECT_LIBRARY )
1885
+ # Only Darwin supports universal binaries.
1886
+ if (NOT SWIFTLIB_OBJECT_LIBRARY AND IS_DARWIN )
1811
1887
# Determine the name of the universal library.
1812
1888
if (SWIFTLIB_SHARED )
1813
- if ("${sdk} " STREQUAL "WINDOWS" )
1814
- set (UNIVERSAL_LIBRARY_NAME
1815
- "${SWIFTLIB_DIR} /${SWIFT_SDK_${sdk} _LIB_SUBDIR}/${name} .dll" )
1816
- else ()
1817
- set (UNIVERSAL_LIBRARY_NAME
1818
- "${SWIFTLIB_DIR} /${SWIFT_SDK_${sdk} _LIB_SUBDIR}/${CMAKE_SHARED_LIBRARY_PREFIX}${name}${CMAKE_SHARED_LIBRARY_SUFFIX} " )
1819
- endif ()
1889
+ set (UNIVERSAL_LIBRARY_NAME
1890
+ "${SWIFTLIB_DIR} /${SWIFT_SDK_${sdk} _LIB_SUBDIR}/${CMAKE_SHARED_LIBRARY_PREFIX}${name}${CMAKE_SHARED_LIBRARY_SUFFIX} " )
1820
1891
else ()
1821
- if ("${sdk} " STREQUAL "WINDOWS" )
1822
- set (UNIVERSAL_LIBRARY_NAME
1823
- "${SWIFTLIB_DIR} /${SWIFT_SDK_${sdk} _LIB_SUBDIR}/${name} .lib" )
1824
- else ()
1825
- set (UNIVERSAL_LIBRARY_NAME
1826
- "${SWIFTLIB_DIR} /${SWIFT_SDK_${sdk} _LIB_SUBDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}${name}${CMAKE_STATIC_LIBRARY_SUFFIX} " )
1827
- endif ()
1892
+ set (UNIVERSAL_LIBRARY_NAME
1893
+ "${SWIFTLIB_DIR} /${SWIFT_SDK_${sdk} _LIB_SUBDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}${name}${CMAKE_STATIC_LIBRARY_SUFFIX} " )
1828
1894
endif ()
1829
1895
1830
1896
set (lipo_target "${name} -${SWIFT_SDK_${sdk} _LIB_SUBDIR}" )
@@ -1866,6 +1932,7 @@ function(add_swift_library name)
1866
1932
WORLD_READ )
1867
1933
endif ()
1868
1934
1935
+ # On Darwin we install the lipo'd universal binary
1869
1936
swift_install_in_component ("${SWIFTLIB_INSTALL_IN_COMPONENT} "
1870
1937
FILES "${UNIVERSAL_LIBRARY_NAME} "
1871
1938
DESTINATION "lib${LLVM_LIBDIR_SUFFIX} /${resource_dir} /${resource_dir_sdk_subdir} "
@@ -2039,9 +2106,16 @@ function(_add_swift_executable_single name)
2039
2106
set (c_compile_flags )
2040
2107
set (link_flags )
2041
2108
2042
- # Prepare linker search directories.
2043
- set (library_search_directories
2109
+ # Prepare linker search directories. On Darwin, we want the fat library paths. On
2110
+ # non-Darwin we want the architecture specific versions.
2111
+ is_darwin_based_sdk ("${SWIFTEXE_SINGLE_SDK} " IS_DARWIN )
2112
+ if (IS_DARWIN )
2113
+ set (library_search_directories
2044
2114
"${SWIFTLIB_DIR} /${SWIFT_SDK_${SWIFTEXE_SINGLE_SDK} _LIB_SUBDIR}" )
2115
+ else ()
2116
+ set (library_search_directories
2117
+ "${SWIFTLIB_DIR} /${SWIFT_SDK_${SWIFTEXE_SINGLE_SDK} _LIB_SUBDIR}/${SWIFTEXE_SINGLE_ARCHITECTURE} " )
2118
+ endif ()
2045
2119
2046
2120
# Add variant-specific flags.
2047
2121
_add_variant_c_compile_flags (
@@ -2067,7 +2141,6 @@ function(_add_swift_executable_single name)
2067
2141
list (APPEND link_flags "-Wl,-no_pie" )
2068
2142
endif ()
2069
2143
2070
- is_darwin_based_sdk ("${SWIFTEXE_SINGLE_SDK} " IS_DARWIN )
2071
2144
if (IS_DARWIN )
2072
2145
list (APPEND link_flags
2073
2146
"-Xlinker" "-rpath"
@@ -2076,12 +2149,19 @@ function(_add_swift_executable_single name)
2076
2149
2077
2150
# Find the names of dependency library targets.
2078
2151
#
2079
- # We don't add the ${ARCH} to the target suffix because we want to link
2152
+ # We don't add the ${ARCH} to the target suffix on Darwin because we want to link
2080
2153
# against fat libraries.
2081
- _list_add_string_suffix (
2082
- "${SWIFTEXE_SINGLE_LINK_FAT_LIBRARIES} "
2083
- "-${SWIFT_SDK_${SWIFTEXE_SINGLE_SDK} _LIB_SUBDIR}"
2084
- SWIFTEXE_SINGLE_LINK_FAT_LIBRARIES_TARGETS )
2154
+ if (IS_DARWIN )
2155
+ _list_add_string_suffix (
2156
+ "${SWIFTEXE_SINGLE_LINK_FAT_LIBRARIES} "
2157
+ "-${SWIFT_SDK_${SWIFTEXE_SINGLE_SDK} _LIB_SUBDIR}"
2158
+ SWIFTEXE_SINGLE_LINK_FAT_LIBRARIES_TARGETS )
2159
+ else ()
2160
+ _list_add_string_suffix (
2161
+ "${SWIFTEXE_SINGLE_LINK_FAT_LIBRARIES} "
2162
+ "-${SWIFT_SDK_${SWIFTEXE_SINGLE_SDK} _LIB_SUBDIR}-${SWIFTEXE_SINGLE_ARCHITECTURE} "
2163
+ SWIFTEXE_SINGLE_LINK_FAT_LIBRARIES_TARGETS )
2164
+ endif ()
2085
2165
2086
2166
handle_swift_sources (
2087
2167
dependency_target
@@ -2191,12 +2271,19 @@ function(add_swift_target_executable name)
2191
2271
add_dependencies ("swift-test-stdlib${VARIANT_SUFFIX} " ${VARIANT_NAME} )
2192
2272
endif ()
2193
2273
2194
- # Don 't add the ${arch} to the suffix. We want to link against fat
2274
+ # On Darwin, don 't add the ${arch} to the suffix. We want to link against fat
2195
2275
# libraries.
2196
- _list_add_string_suffix (
2197
- "${SWIFTEXE_TARGET_DEPENDS} "
2198
- "-${SWIFT_SDK_${sdk} _LIB_SUBDIR}"
2199
- SWIFTEXE_TARGET_DEPENDS_with_suffix )
2276
+ if (IS_DARWIN )
2277
+ _list_add_string_suffix (
2278
+ "${SWIFTEXE_TARGET_DEPENDS} "
2279
+ "-${SWIFT_SDK_${sdk} _LIB_SUBDIR}"
2280
+ SWIFTEXE_TARGET_DEPENDS_with_suffix )
2281
+ else ()
2282
+ _list_add_string_suffix (
2283
+ "${SWIFTEXE_TARGET_DEPENDS} "
2284
+ "${VARIANT_SUFFIX} "
2285
+ SWIFTEXE_TARGET_DEPENDS_with_suffix )
2286
+ endif ()
2200
2287
_add_swift_executable_single (
2201
2288
${VARIANT_NAME}
2202
2289
${SWIFTEXE_TARGET_SOURCES}
0 commit comments