@@ -31,65 +31,58 @@ function cmake_os(p::AbstractPlatform)
31
31
end
32
32
end
33
33
34
- function toolchain_file (bt:: CMake , p:: AbstractPlatform ; is_host:: Bool = false )
34
+ function toolchain_file (bt:: CMake , p:: AbstractPlatform , host_platform :: AbstractPlatform ; is_host:: Bool = false )
35
35
target = triplet (p)
36
36
aatarget = aatriplet (p)
37
37
38
- # CMake uses the setting of `HOST_SYSTEM_NAME` and `SYSTEM_NAME` to decide
39
- # whether the current build is a cross-compilation or not:
40
- # <https://cmake.org/cmake/help/latest/variable/CMAKE_CROSSCOMPILING.html>.
41
- # We want to have the host toolchain always setting `HOST_SYSTEM_NAME`, and
42
- # the target toolchain always setting `SYSTEM_NAME`.
43
- system_name_var = if is_host
44
- " CMAKE_HOST_SYSTEM_NAME"
45
- else
46
- " CMAKE_SYSTEM_NAME"
38
+ # In order to get the version of the host system we need to call `/bin/uname -r`.
39
+ file = """
40
+ # CMake toolchain file for $(c_compiler (bt)) running on $(target)
41
+ set(CMAKE_HOST_SYSTEM_NAME $(cmake_os (host_platform)) )
42
+ set(CMAKE_HOST_SYSTEM_PROCESSOR $(cmake_arch (host_platform)) )
43
+ execute_process(COMMAND /bin/uname -r OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_VERSION)
44
+ """
45
+
46
+ if ! is_host
47
+ # CMake checks whether `SYSTEM_NAME` is set manually to decide whether the current
48
+ # build is a cross-compilation or not:
49
+ # <https://cmake.org/cmake/help/latest/variable/CMAKE_CROSSCOMPILING.html>. We
50
+ # always set `HOST_SYSTEM_NAME`, but set `SYSTEM_NAME` only for the target
51
+ # toolchain.
52
+ file *= """
53
+ set(CMAKE_SYSTEM_NAME $(cmake_os (p)) )
54
+ set(CMAKE_SYSTEM_PROCESSOR $(cmake_arch (p)) )
55
+ """
47
56
end
48
57
49
58
if Sys. isapple (p)
50
59
darwin_ver = something (os_version (p), v " 14.5.0" )
51
60
maj_ver = darwin_ver. major
52
61
min_ver = darwin_ver. minor
53
- return """
54
- # CMake toolchain file for $(c_compiler (bt)) running on $(target)
55
- set($(system_name_var) $(cmake_os (p)) )
56
- set(CMAKE_SYSTEM_PROCESSOR $(cmake_arch (p)) )
62
+ file *= """
57
63
set(CMAKE_SYSTEM_VERSION $(maj_ver) .$(min_ver) )
58
64
set(DARWIN_MAJOR_VERSION $(maj_ver) )
59
65
set(DARWIN_MINOR_VERSION $(min_ver) )
60
66
61
- # Enable rpath support
62
- set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-Wl,-rpath,")
63
-
64
67
set(CMAKE_SYSROOT /opt/$(aatarget) /$(aatarget) /sys-root)
65
68
set(CMAKE_SYSTEM_FRAMEWORK_PATH
66
69
\$ {CMAKE_SYSROOT}/System/Library/Frameworks
67
70
\$ {CMAKE_SYSROOT}/System/Library/PrivateFrameworks
68
71
)
69
- set(CMAKE_INSTALL_PREFIX \$ ENV{prefix})
70
-
71
- set(CMAKE_C_COMPILER /opt/bin/$(target) /$(aatarget) -$(c_compiler (bt)) )
72
- set(CMAKE_CXX_COMPILER /opt/bin/$(target) /$(aatarget) -$(cxx_compiler (bt)) )
73
- set(CMAKE_Fortran_COMPILER /opt/bin/$(target) /$(aatarget) -$(fortran_compiler (bt)) )
74
-
75
- set(CMAKE_LINKER /opt/bin/$(target) /$(aatarget) -ld)
76
- set(CMAKE_OBJCOPY /opt/bin/$(target) /$(aatarget) -objcopy)
77
-
78
- set(CMAKE_AR /opt/bin/$(target) /$(aatarget) -ar)
79
- set(CMAKE_NM /opt/bin/$(target) /$(aatarget) -nm)
80
- set(CMAKE_RANLIB /opt/bin/$(target) /$(aatarget) -ranlib)
81
-
82
- if( \$ ENV{CC} MATCHES ccache )
83
- set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
84
- endif()
85
72
"""
86
73
else
87
- return """
88
- # CMake toolchain file for $(c_compiler (bt)) running on $(target)
89
- set($(system_name_var) $(cmake_os (p)) )
90
- set(CMAKE_SYSTEM_PROCESSOR $(cmake_arch (p)) )
74
+ if ! is_host
75
+ file *= """
76
+ execute_process(COMMAND /usr/bin/uname -r OUTPUT_VARIABLE CMAKE_SYSTEM_VERSION)
91
77
78
+ """
79
+ end
80
+ file *= """
92
81
set(CMAKE_SYSROOT /opt/$(aatarget) /$(aatarget) /sys-root/)
82
+ """
83
+ end
84
+
85
+ file *= """
93
86
set(CMAKE_INSTALL_PREFIX \$ ENV{prefix})
94
87
95
88
set(CMAKE_C_COMPILER /opt/bin/$(target) /$(aatarget) -$(c_compiler (bt)) )
@@ -107,7 +100,6 @@ function toolchain_file(bt::CMake, p::AbstractPlatform; is_host::Bool=false)
107
100
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
108
101
endif()
109
102
"""
110
- end
111
103
end
112
104
113
105
meson_c_args (p:: AbstractPlatform , envs:: Dict{String,String} ; is_host:: Bool = false ) =
@@ -229,12 +221,12 @@ function generate_toolchain_files!(platform::AbstractPlatform, envs::Dict{String
229
221
for compiler in (:clang , :gcc )
230
222
# Target toolchains
231
223
if platforms_match (p, platform)
232
- write (joinpath (dir, " target_$(aatriplet (p)) _$(compiler) .cmake" ), toolchain_file (CMake {compiler} (), p; is_host= false ))
224
+ write (joinpath (dir, " target_$(aatriplet (p)) _$(compiler) .cmake" ), toolchain_file (CMake {compiler} (), p, host_platform ; is_host= false ))
233
225
write (joinpath (dir, " target_$(aatriplet (p)) _$(compiler) .meson" ), toolchain_file (Meson {compiler} (), p, envs; is_host= false ))
234
226
end
235
227
# Host toolchains
236
228
if platforms_match (p, host_platform)
237
- write (joinpath (dir, " host_$(aatriplet (p)) _$(compiler) .cmake" ), toolchain_file (CMake {compiler} (), p; is_host= true ))
229
+ write (joinpath (dir, " host_$(aatriplet (p)) _$(compiler) .cmake" ), toolchain_file (CMake {compiler} (), p, host_platform ; is_host= true ))
238
230
write (joinpath (dir, " host_$(aatriplet (p)) _$(compiler) .meson" ), toolchain_file (Meson {compiler} (), p, envs; is_host= true ))
239
231
end
240
232
end
0 commit comments