@@ -38,23 +38,24 @@ foreach(sdk ${SWIFT_SDKS})
38
38
set (arch_subdir "${SWIFT_SDK_${sdk} _LIB_SUBDIR}/${arch} " )
39
39
set (module_dir "${SWIFTLIB_DIR} /${arch_subdir} " )
40
40
41
- # Determine the location of glibc based on the target.
41
+ # Determine the location of glibc headers based on the target.
42
+ set (GLIBC_NATIVE_INCLUDE_PATH "/usr/include" )
43
+ set (GLIBC_NATIVE_ARCH_INCLUDE_PATH ${GLIBC_NATIVE_INCLUDE_PATH} )
44
+ # Some SDKs place their headers in architecture-specific subfolders.
45
+ if ((${sdk} STREQUAL "LINUX" OR ${sdk} STREQUAL "FREEBSD" ) AND CMAKE_LIBRARY_ARCHITECTURE )
46
+ set (GLIBC_NATIVE_ARCH_INCLUDE_PATH "${GLIBC_NATIVE_ARCH_INCLUDE_PATH} /${CMAKE_LIBRARY_ARCHITECTURE} " )
47
+ endif ()
48
+
49
+ # Android uses a different sysroot variable, although there are pending PRs to refactor this
42
50
if (${sdk} STREQUAL "ANDROID" )
43
- set (GLIBC_INCLUDE_PATH "${SWIFT_ANDROID_SDK_PATH} /usr/include" )
44
- set (GLIBC_ARCH_INCLUDE_PATH ${GLIBC_INCLUDE_PATH} )
51
+ set (GLIBC_SYSTEM_ROOT "${SWIFT_ANDROID_SDK_PATH} " )
45
52
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 ()
53
+ set (GLIBC_SYSTEM_ROOT "${CMAKE_SYSROOT} " )
56
54
endif ()
57
55
56
+ set (GLIBC_INCLUDE_PATH "${GLIBC_SYSTEM_ROOT} /${GLIBC_NATIVE_INCLUDE_PATH} " )
57
+ set (GLIBC_ARCH_INCLUDE_PATH ${GLIBC_SYSTEM_ROOT} /${GLIBC_NATIVE_ARCH_INCLUDE_PATH} )
58
+
58
59
set (glibc_modulemap_source "glibc.modulemap.gyb" )
59
60
set (glibc_modulemap_out "${module_dir} /glibc.modulemap" )
60
61
@@ -68,11 +69,28 @@ foreach(sdk ${SWIFT_SDKS})
68
69
"-DGLIBC_INCLUDE_PATH=${GLIBC_INCLUDE_PATH} "
69
70
"-DGLIBC_ARCH_INCLUDE_PATH=${GLIBC_ARCH_INCLUDE_PATH} " )
70
71
72
+ list (APPEND glibc_modulemap_target_list ${glibc_modulemap_target} )
73
+
74
+ # If cross-compiling, generate a native modulemap without the sysroot prefix
75
+ # The prefixed one is still the 'glibc.modulemap' which we'll look at during the build process
76
+ if (CMAKE_CROSSCOMPILING )
77
+ set (glibc_native_modulemap_out "${module_dir} /native-substitutes/glibc.modulemap" )
78
+ handle_gyb_source_single (glibc_modulemap_native_target
79
+ SOURCE "${glibc_modulemap_source} "
80
+ OUTPUT "${glibc_native_modulemap_out} "
81
+ FLAGS
82
+ "-DCMAKE_SDK=${sdk} "
83
+ "-DGLIBC_INCLUDE_PATH=${GLIBC_NATIVE_INCLUDE_PATH} "
84
+ "-DGLIBC_ARCH_INCLUDE_PATH=${GLIBC_NATIVE_ARCH_INCLUDE_PATH} " )
85
+
86
+ list (APPEND glibc_modulemap_target_list ${glibc_modulemap_native_target} )
87
+ set (glibc_modulemap_out ${glibc_native_modulemap_out} )
88
+ endif ()
89
+
71
90
swift_install_in_component (sdk-overlay
72
91
FILES "${glibc_modulemap_out} "
73
92
DESTINATION "lib/swift/${arch_subdir} " )
74
93
75
- list (APPEND glibc_modulemap_target_list ${glibc_modulemap_target} )
76
94
endforeach ()
77
95
endif ()
78
96
endforeach ()
0 commit comments