@@ -69,6 +69,28 @@ function(get_swift_host_os result_var_name)
6969 endif ()
7070endfunction ()
7171
72+ if (NOT Swift_MODULE_TRIPLE)
73+ # Attempt to get the module triple from the Swift compiler.
74+ set (module_triple_command "${CMAKE_Swift_COMPILER} " -print-target -info)
75+ if (CMAKE_Swift_COMPILER_TARGET)
76+ list (APPEND module_triple_command -target ${CMAKE_Swift_COMPILER_TARGET} )
77+ endif ()
78+ execute_process (COMMAND ${module_triple_command}
79+ OUTPUT_VARIABLE target_info_json)
80+ string (JSON module_triple GET "${target_info_json} " "target" "moduleTriple" )
81+
82+ # Exit now if we failed to infer the triple.
83+ if (NOT module_triple)
84+ message (FATAL_ERROR
85+ "Failed to get module triple from Swift compiler. "
86+ "Compiler output: ${target_info_json} " )
87+ endif ()
88+
89+ # Cache the module triple for future use.
90+ set (Swift_MODULE_TRIPLE "${module_triple} " CACHE STRING "swift module triple used for installed swiftmodule and swiftinterface files" )
91+ mark_as_advanced (Swift_MODULE_TRIPLE)
92+ endif ()
93+
7294function (_install_target module)
7395 get_swift_host_os(swift_os)
7496 get_target_property (type ${module} TYPE )
@@ -79,24 +101,20 @@ function(_install_target module)
79101 set (swift swift)
80102 endif ()
81103
82- install (TARGETS ${module}
83- ARCHIVE DESTINATION lib/${swift} /${swift_os}
84- LIBRARY DESTINATION lib/${swift} /${swift_os}
85- RUNTIME DESTINATION bin)
104+ install (TARGETS ${module} )
86105 if (type STREQUAL EXECUTABLE)
87106 return ()
88107 endif ()
89108
90- get_swift_host_arch(swift_arch)
91109 get_target_property (module_name ${module} Swift_MODULE_NAME)
92110 if (NOT module_name)
93111 set (module_name ${module} )
94112 endif ()
95113
96114 install (FILES $<TARGET_PROPERTY:${module} ,Swift_MODULE_DIRECTORY>/${module_name} .swiftdoc
97- DESTINATION lib /${swift} /${swift_os} /${module_name} .swiftmodule
98- RENAME ${swift_arch } .swiftdoc)
115+ DESTINATION ${CMAKE_INSTALL_LIBDIR} /${swift} /${swift_os} /${module_name} .swiftmodule
116+ RENAME ${Swift_MODULE_TRIPLE } .swiftdoc)
99117 install (FILES $<TARGET_PROPERTY:${module} ,Swift_MODULE_DIRECTORY>/${module_name} .swiftmodule
100- DESTINATION lib /${swift} /${swift_os} /${module_name} .swiftmodule
101- RENAME ${swift_arch } .swiftmodule)
118+ DESTINATION ${CMAKE_INSTALL_LIBDIR} /${swift} /${swift_os} /${module_name} .swiftmodule
119+ RENAME ${Swift_MODULE_TRIPLE } .swiftmodule)
102120endfunction ()
0 commit comments