@@ -3,44 +3,57 @@ set(sources
3
3
Misc.c
4
4
)
5
5
6
- set (output_dir "${SWIFTLIB_DIR} /glibc" )
6
+ # When cross-compiling the stdlib on Unix platforms, we'll need a separate
7
+ # glibc for each target.
8
+ foreach (SDK ${SWIFT_SDKS} )
9
+ foreach (arch ${SWIFT_SDK_${SDK}_ARCHITECTURES} )
10
+ # Don't generate Glibc module maps for Darwin targets.
11
+ if ("${SDK} " STREQUAL "LINUX" OR "${SDK} " STREQUAL "FREEBSD" )
12
+ set (output_dir "${SWIFTLIB_DIR} /${SWIFT_SDK_${SDK} _LIB_SUBDIR}/${arch} " )
7
13
8
- # Set correct paths to glibc headers
9
- set (GLIBC_INCLUDE_PATH "/usr/include" )
10
- if (CMAKE_LIBRARY_ARCHITECTURE )
11
- set (GLIBC_ARCH_INCLUDE_PATH "${GLIBC_INCLUDE_PATH} /${CMAKE_LIBRARY_ARCHITECTURE} " )
12
- else ()
13
- set (GLIBC_ARCH_INCLUDE_PATH "${GLIBC_INCLUDE_PATH} " )
14
- endif ()
15
- if (NOT EXISTS "${GLIBC_ARCH_INCLUDE_PATH} /sys" )
16
- message (FATAL_ERROR "Glibc headers were not found." )
17
- endif ()
14
+ # Determine the location of glibc based on the target.
15
+ set (GLIBC_INCLUDE_PATH "/usr/include" )
16
+ set (GLIBC_ARCH_INCLUDE_PATH "${GLIBC_INCLUDE_PATH} " )
17
+ if (("${SDK} " STREQUAL "LINUX" OR "${SDK} " STREQUAL "FREEBSD" ) AND CMAKE_LIBRARY_ARCHITECTURE )
18
+ # FIXME: Some distributions install headers in
19
+ # "/usr/include/x86_64-linux-gnu/sys/...". Here we use the host
20
+ # machine's path, regardless of the SDK target we're building for.
21
+ # This will break if cross-compiling from a distro that uses the
22
+ # architecture as part of the path to a distro that does not.
23
+ set (GLIBC_ARCH_INCLUDE_PATH "${GLIBC_INCLUDE_PATH} /${CMAKE_LIBRARY_ARCHITECTURE} " )
24
+ endif ()
18
25
19
- # Generate module.map
20
- if (CMAKE_SYSTEM_NAME STREQUAL "Linux" )
21
- configure_file (module.map.in "${CMAKE_CURRENT_BINARY_DIR} /module.map" @ONLY )
22
- endif ()
23
- if (CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" )
24
- configure_file (module.freebsd.map.in "${CMAKE_CURRENT_BINARY_DIR} /module.map" @ONLY )
25
- endif ()
26
+ # Configure the module map based on the target. Each platform needs to
27
+ # reference different headers, based on what's available in their glibc.
28
+ set (modulemap_path "${CMAKE_CURRENT_BINARY_DIR} /${SWIFT_SDK_${SDK} _LIB_SUBDIR}/${arch} /module.map" )
29
+ if ("${SDK} " STREQUAL "FREEBSD" )
30
+ configure_file (module.freebsd.map.in "${modulemap_path} " @ONLY )
31
+ else ()
32
+ configure_file (module.map.in "${modulemap_path} " @ONLY )
33
+ endif ()
26
34
27
- add_custom_command_target (unused_var
28
- COMMAND
29
- "${CMAKE_COMMAND} " "-E" "make_directory" "${output_dir} "
30
- COMMAND
31
- "${CMAKE_COMMAND} " "-E" "copy_if_different"
32
- "${CMAKE_CURRENT_BINARY_DIR} /module.map"
33
- "${output_dir} /module.map"
34
- CUSTOM_TARGET_NAME "copy_glibc_module"
35
- OUTPUT "${output_dir} /module.map" "${output_dir} "
36
- DEPENDS "${CMAKE_CURRENT_BINARY_DIR} /module.map"
37
- COMMENT "Copying Glibc module to ${output_dir} " )
35
+ set (VARIANT_SUFFIX "-${SWIFT_SDK_${SDK} _LIB_SUBDIR}-${arch} " )
36
+ add_custom_command_target (unused_var
37
+ COMMAND
38
+ "${CMAKE_COMMAND} " "-E" "make_directory" "${output_dir} "
39
+ COMMAND
40
+ "${CMAKE_COMMAND} " "-E" "copy_if_different"
41
+ "${modulemap_path} "
42
+ "${output_dir} /glibc.modulemap"
43
+ CUSTOM_TARGET_NAME "copy_glibc_module${VARIANT_SUFFIX} "
44
+ OUTPUT "${output_dir} /glibc.modulemap" "${output_dir} "
45
+ DEPENDS "${modulemap_path} "
46
+ COMMENT "Copying Glibc module to ${output_dir} " )
38
47
39
- swift_install_in_component (stdlib
40
- FILES "${output_dir} /module.map "
41
- DESTINATION "lib/swift/glibc " )
48
+ swift_install_in_component (stdlib
49
+ FILES "${output_dir} /glibc.modulemap "
50
+ DESTINATION "${output_dir} " )
42
51
43
- add_swift_library (swiftGlibc IS_SDK_OVERLAY
44
- ${sources}
45
- FILE_DEPENDS copy_glibc_module "${output_dir} "
46
- INSTALL_IN_COMPONENT stdlib-experimental )
52
+ add_swift_library (swiftGlibc IS_SDK_OVERLAY
53
+ ${sources}
54
+ FILE_DEPENDS "copy_glibc_module${VARIANT_SUFFIX} " "${output_dir} "
55
+ TARGET_SDKS "${SDK} "
56
+ INSTALL_IN_COMPONENT stdlib-experimental )
57
+ endif ()
58
+ endforeach ()
59
+ endforeach ()
0 commit comments