Skip to content

Commit 5cf8e8e

Browse files
committed
Merge pull request #282 from orobio/detect-location-of-glibc-headers
Glibc module: detect location of glibc header files
2 parents 2b8efce + 3d91979 commit 5cf8e8e

File tree

2 files changed

+108
-102
lines changed

2 files changed

+108
-102
lines changed

stdlib/public/Glibc/CMakeLists.txt

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,40 @@
11
set(sources
2-
module.map
3-
)
2+
Glibc.swift
3+
)
4+
45
set(output_dir "${SWIFTLIB_DIR}/glibc")
56

6-
set(commands
7-
COMMAND ${CMAKE_COMMAND} "-E" "make_directory" "${output_dir}")
8-
set(outputs)
9-
foreach(input ${sources})
10-
list(APPEND commands
11-
COMMAND
12-
"${CMAKE_COMMAND}" "-E" "copy_if_different"
13-
"${CMAKE_CURRENT_SOURCE_DIR}/${input}"
14-
"${output_dir}/${input}")
15-
list(APPEND outputs "${output_dir}/${input}")
16-
endforeach()
17-
# Put the output dir itself last so that it isn't considered the primary output.
18-
list(APPEND outputs "${output_dir}")
7+
# Set correct paths to glibc headers
8+
set(GLIBC_INCLUDE_PATH "/usr/include")
9+
if(CMAKE_LIBRARY_ARCHITECTURE)
10+
set(GLIBC_ARCH_INCLUDE_PATH "${GLIBC_INCLUDE_PATH}/${CMAKE_LIBRARY_ARCHITECTURE}")
11+
else()
12+
set(GLIBC_ARCH_INCLUDE_PATH "${GLIBC_INCLUDE_PATH}")
13+
endif()
14+
if (NOT EXISTS "${GLIBC_ARCH_INCLUDE_PATH}/sys")
15+
message(FATAL_ERROR "Glibc headers were not found.")
16+
endif()
17+
18+
# Generate module.map
19+
configure_file(module.map.in "${CMAKE_CURRENT_BINARY_DIR}/module.map" @ONLY)
20+
1921
add_custom_command_target(unused_var
20-
${commands}
22+
COMMAND
23+
"${CMAKE_COMMAND}" "-E" "make_directory" "${output_dir}"
24+
COMMAND
25+
"${CMAKE_COMMAND}" "-E" "copy_if_different"
26+
"${CMAKE_CURRENT_BINARY_DIR}/module.map"
27+
"${output_dir}/module.map"
2128
CUSTOM_TARGET_NAME "copy_glibc_module"
22-
OUTPUT "${outputs}"
23-
DEPENDS "${sources}"
29+
OUTPUT "${output_dir}/module.map" "${output_dir}"
30+
DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/module.map"
2431
COMMENT "Copying Glibc module to ${output_dir}")
2532

2633
swift_install_in_component(stdlib
27-
FILES ${sources}
34+
FILES "${output_dir}/module.map"
2835
DESTINATION "lib/swift/glibc")
2936

3037
add_swift_library(swiftGlibc IS_SDK_OVERLAY
31-
Glibc.swift
32-
FILE_DEPENDS copy_glibc_module "${SWIFTLIB_DIR}/glibc"
33-
INSTALL_IN_COMPONENT stdlib-experimental)
34-
38+
${sources}
39+
FILE_DEPENDS copy_glibc_module "${output_dir}"
40+
INSTALL_IN_COMPONENT stdlib-experimental)

0 commit comments

Comments
 (0)