@@ -35,3 +35,59 @@ function(get_swift_host_arch result_var_name)
3535 message (FATAL_ERROR "Unrecognized architecture on host system: ${CMAKE_SYSTEM_PROCESSOR} " )
3636 endif ()
3737endfunction ()
38+
39+ # Returns the os name in a variable
40+ #
41+ # Usage:
42+ # get_swift_host_os(result_var_name)
43+ #
44+ #
45+ # Sets ${result_var_name} with the converted OS name derived from
46+ # CMAKE_SYSTEM_NAME.
47+ function (get_swift_host_os result_var_name)
48+ if (CMAKE_SYSTEM_NAME STREQUAL Darwin)
49+ set (${result_var_name} macosx PARENT_SCOPE)
50+ else ()
51+ string (TOLOWER ${CMAKE_SYSTEM_NAME} cmake_system_name_lc)
52+ set (${result_var_name} ${cmake_system_name_lc} PARENT_SCOPE)
53+ endif ()
54+ endfunction ()
55+
56+ function (_install_target module)
57+ get_swift_host_os(swift_os)
58+ get_target_property (type ${module} TYPE )
59+
60+ if (type STREQUAL STATIC_LIBRARY)
61+ set (swift swift_static)
62+ else ()
63+ set (swift swift)
64+ endif ()
65+
66+ install (TARGETS ${module}
67+ ARCHIVE DESTINATION lib/${swift} /${swift_os}
68+ LIBRARY DESTINATION lib/${swift} /${swift_os}
69+ RUNTIME DESTINATION bin)
70+ if (type STREQUAL EXECUTABLE)
71+ return ()
72+ endif ()
73+
74+ get_swift_host_arch(swift_arch)
75+ get_target_property (module_name ${module} Swift_MODULE_NAME)
76+ if (NOT module_name)
77+ set (module_name ${module} )
78+ endif ()
79+
80+ if (CMAKE_SYSTEM_NAME STREQUAL Darwin)
81+ install (FILES $<TARGET_PROPERTY:${module} ,Swift_MODULE_DIRECTORY>/${module_name} .swiftdoc
82+ DESTINATION lib/${swift} /${swift_os} /${module_name} .swiftmodule
83+ RENAME ${swift_arch} .swiftdoc)
84+ install (FILES $<TARGET_PROPERTY:${module} ,Swift_MODULE_DIRECTORY>/${module_name} .swiftmodule
85+ DESTINATION lib/${swift} /${swift_os} /${module_name} .swiftmodule
86+ RENAME ${swift_arch} .swiftmodule)
87+ else ()
88+ install (FILES
89+ $<TARGET_PROPERTY:${module} ,Swift_MODULE_DIRECTORY>/${module_name} .swiftdoc
90+ $<TARGET_PROPERTY:${module} ,Swift_MODULE_DIRECTORY>/${module_name} .swiftmodule
91+ DESTINATION lib/${swift} /${swift_os} /${swift_arch} )
92+ endif ()
93+ endfunction ()
0 commit comments