@@ -3,44 +3,56 @@ set(sources
33 Misc.c
44)
55
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+ set (output_dir "${SWIFTLIB_DIR} /${SWIFT_SDK_${SDK} _LIB_SUBDIR}/${arch} " )
711
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 ()
12+ # Determine the location of glibc based on the target.
13+ set (GLIBC_INCLUDE_PATH "/usr/include" )
14+ set (GLIBC_ARCH_INCLUDE_PATH "${GLIBC_INCLUDE_PATH} " )
15+ if (("${SDK} " STREQUAL "LINUX" OR "${SDK} " STREQUAL "FREEBSD" ) AND CMAKE_LIBRARY_ARCHITECTURE )
16+ # FIXME: Some distributions install headers in
17+ # "/usr/include/x86_64-linux-gnu/sys/...". Here we use the host
18+ # machine's path, regardless of the SDK target we're building for.
19+ # This will break if cross-compiling from a distro that uses the
20+ # architecture as part of the path to a distro that does not.
21+ set (GLIBC_ARCH_INCLUDE_PATH "${GLIBC_INCLUDE_PATH} /${CMAKE_LIBRARY_ARCHITECTURE} " )
22+ endif ()
1823
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 ()
24+ # Configure the modulemap based on the target. Each platform needs to
25+ # reference different headers, based on what's available in their glibc.
26+ set (modulemap_path "${CMAKE_CURRENT_BINARY_DIR} /${SWIFT_SDK_${SDK} _LIB_SUBDIR}/${arch} /module.map" )
27+ if ("${SDK} " STREQUAL "FREEBSD" )
28+ configure_file (module.freebsd.map.in "${modulemap_path} " @ONLY)
29+ else ()
30+ configure_file (module.map.in "${modulemap_path} " @ONLY)
31+ endif ()
2632
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} " )
33+ set (VARIANT_SUFFIX "-${SWIFT_SDK_${SDK} _LIB_SUBDIR}-${arch} " )
34+ add_custom_command_target(unused_var
35+ COMMAND
36+ "${CMAKE_COMMAND} " "-E" "make_directory" "${output_dir} "
37+ COMMAND
38+ "${CMAKE_COMMAND} " "-E" "copy_if_different"
39+ "${modulemap_path} "
40+ "${output_dir} /glibc.modulemap"
41+ CUSTOM_TARGET_NAME "copy_glibc_module${VARIANT_SUFFIX} "
42+ OUTPUT "${output_dir} /glibc.modulemap" "${output_dir} "
43+ DEPENDS "${modulemap_path} "
44+ COMMENT "Copying Glibc module to ${output_dir} " )
3845
39- swift_install_in_component(stdlib
40- FILES "${output_dir} /module.map "
41- DESTINATION "lib/swift/glibc " )
46+ swift_install_in_component(stdlib
47+ FILES "${output_dir} /glibc.modulemap "
48+ DESTINATION "${output_dir} " )
4249
43- add_swift_library(swiftGlibc IS_SDK_OVERLAY
44- ${sources}
45- FILE_DEPENDS copy_glibc_module "${output_dir} "
46- INSTALL_IN_COMPONENT stdlib-experimental)
50+ if ("${SDK} " STREQUAL "LINUX" OR "${SDK} " STREQUAL "${FREEBSD} " )
51+ add_swift_library(swiftGlibc IS_SDK_OVERLAY
52+ ${sources}
53+ FILE_DEPENDS "copy_glibc_module${VARIANT_SUFFIX} " "${output_dir} "
54+ TARGET_SDKS "${SDK} "
55+ INSTALL_IN_COMPONENT stdlib-experimental)
56+ endif ()
57+ endforeach ()
58+ endforeach ()
0 commit comments