@@ -37,29 +37,26 @@ foreach(sdk ${SWIFT_SDKS})
37
37
foreach (arch ${SWIFT_SDK_${sdk}_ARCHITECTURES} )
38
38
set (arch_subdir "${SWIFT_SDK_${sdk} _LIB_SUBDIR}/${arch} " )
39
39
set (module_dir "${SWIFTLIB_DIR} /${arch_subdir} " )
40
-
41
- # Determine the location of glibc based on the target.
42
- if (${sdk} STREQUAL "ANDROID" )
43
- set (GLIBC_INCLUDE_PATH "${SWIFT_ANDROID_SDK_PATH} /usr/include" )
44
- set (GLIBC_ARCH_INCLUDE_PATH ${GLIBC_INCLUDE_PATH} )
45
- else ()
46
- set (GLIBC_INCLUDE_PATH "/usr/include" )
47
- set (GLIBC_ARCH_INCLUDE_PATH ${GLIBC_INCLUDE_PATH} )
48
- if ((${sdk} STREQUAL "LINUX" OR ${sdk} STREQUAL "FREEBSD" ) AND CMAKE_LIBRARY_ARCHITECTURE )
49
- # FIXME: Some distributions install headers in
50
- # "/usr/include/x86_64-linux-gnu/sys/...". Here we use the host
51
- # machine's path, regardless of the SDK target we're building for.
52
- # This will break if cross-compiling from a distro that uses the
53
- # architecture as part of the path to a distro that does not.
54
- set (GLIBC_ARCH_INCLUDE_PATH "${GLIBC_INCLUDE_PATH} /${CMAKE_LIBRARY_ARCHITECTURE} " )
55
- endif ()
40
+
41
+ # Determine the location of glibc headers based on the target.
42
+ set (GLIBC_SYSROOT_RELATIVE_INCLUDE_PATH "/usr/include" )
43
+ set (GLIBC_SYSROOT_REALTIVE_ARCH_INCLUDE_PATH ${GLIBC_SYSROOT_RELATIVE_INCLUDE_PATH} )
44
+
45
+ # Some SDKs place their headers in architecture-specific subfolders.
46
+ if ((${sdk} STREQUAL "LINUX" OR ${sdk} STREQUAL "FREEBSD" ) AND CMAKE_LIBRARY_ARCHITECTURE )
47
+ set (GLIBC_SYSROOT_REALTIVE_ARCH_INCLUDE_PATH "${GLIBC_SYSROOT_REALTIVE_ARCH_INCLUDE_PATH} /${CMAKE_LIBRARY_ARCHITECTURE} " )
56
48
endif ()
57
49
50
+ set (GLIBC_INCLUDE_PATH "${SWIFT_SDK_${sdk} _PATH}/${GLIBC_SYSROOT_RELATIVE_INCLUDE_PATH} " )
51
+ set (GLIBC_ARCH_INCLUDE_PATH "${SWIFT_SDK_${sdk} _PATH}/${GLIBC_SYSROOT_REALTIVE_ARCH_INCLUDE_PATH} " )
52
+
58
53
set (glibc_modulemap_source "glibc.modulemap.gyb" )
59
54
set (glibc_modulemap_out "${module_dir} /glibc.modulemap" )
60
55
61
56
# Configure the module map based on the target. Each platform needs to
62
57
# reference different headers, based on what's available in their glibc.
58
+ # This is the 'glibc.modulemap' in the 'resource-dir', so
59
+ # it's the one we'll look at during the build process.
63
60
handle_gyb_source_single (glibc_modulemap_target
64
61
SOURCE "${glibc_modulemap_source} "
65
62
OUTPUT "${glibc_modulemap_out} "
@@ -68,11 +65,34 @@ foreach(sdk ${SWIFT_SDKS})
68
65
"-DGLIBC_INCLUDE_PATH=${GLIBC_INCLUDE_PATH} "
69
66
"-DGLIBC_ARCH_INCLUDE_PATH=${GLIBC_ARCH_INCLUDE_PATH} " )
70
67
68
+ list (APPEND glibc_modulemap_target_list ${glibc_modulemap_target} )
69
+
70
+ # If this SDK is a target for a non-native host, create a native modulemap
71
+ # without a sysroot prefix. This is the one we'll install instead.
72
+ if (NOT "${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK} _PATH}" STREQUAL "/" )
73
+
74
+ set (glibc_sysroot_relative_modulemap_out "${module_dir} /sysroot-relative-modulemaps/glibc.modulemap" )
75
+ handle_gyb_source_single (glibc_modulemap_native_target
76
+ SOURCE "${glibc_modulemap_source} "
77
+ OUTPUT "${glibc_sysroot_relative_modulemap_out} "
78
+ FLAGS
79
+ "-DCMAKE_SDK=${sdk} "
80
+ "-DGLIBC_INCLUDE_PATH=${GLIBC_SYSROOT_RELATIVE_INCLUDE_PATH} "
81
+ "-DGLIBC_ARCH_INCLUDE_PATH=${GLIBC_SYSROOT_REALTIVE_ARCH_INCLUDE_PATH} " )
82
+
83
+ list (APPEND glibc_modulemap_target_list ${glibc_modulemap_native_target} )
84
+ set (glibc_modulemap_out ${glibc_sysroot_relative_modulemap_out} )
85
+ endif ()
86
+
87
+ # FIXME: When SDK is a cross-compile target (SDK != Host), the generated
88
+ # modulemap will be relative to the Host, with hardcoded paths.
89
+ # It is not relocatable to the target platform itself.
90
+ # This only affects ANDROID right now, but could affect cross-compiled LINUX targets
91
+
71
92
swift_install_in_component (sdk-overlay
72
93
FILES "${glibc_modulemap_out} "
73
94
DESTINATION "lib/swift/${arch_subdir} " )
74
95
75
- list (APPEND glibc_modulemap_target_list ${glibc_modulemap_target} )
76
96
endforeach ()
77
97
endif ()
78
98
endforeach ()
0 commit comments