17
17
#
18
18
# Remove once rdar://102202478 is fixed.
19
19
function (target_link_swift_syntax_libraries TARGET )
20
- target_link_libraries (${TARGET} ${ARGN} )
21
-
22
20
cmake_parse_arguments (ARGS "PUBLIC;PRIVATE;INTERFACE" "" "" ${ARGN} )
23
- foreach (DEPENDENCY ${ARGS_UNPARSED_ARGUMENTS} )
21
+ set (link_type)
22
+ if (ARGS_PUBLIC)
23
+ set (link_type PUBLIC )
24
+ elseif (ARGS_PRIVATE)
25
+ set (link_type PRIVATE )
26
+ elseif (ARGS_INTERFACE)
27
+ set (link_type INTERFACE )
28
+ endif ()
29
+
30
+ string (PREPEND TARGET ${SWIFTSYNTAX_TARGET_NAMESPACE} )
31
+ list (TRANSFORM ARGS_UNPARSED_ARGUMENTS PREPEND "${SWIFTSYNTAX_TARGET_NAMESPACE} " OUTPUT_VARIABLE dependencies)
32
+
33
+ target_link_libraries (${TARGET} ${link_type} ${dependencies} )
34
+ foreach (DEPENDENCY ${dependencies} )
24
35
string (REGEX REPLACE [<>:\"/\\|?*] _ sanitized ${DEPENDENCY} )
25
36
add_custom_command (OUTPUT ${CMAKE_CURRENT_BINARY_DIR} /forced-${sanitized} -dep.swift
26
37
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR} /forced-${sanitized} -dep.swift
@@ -36,103 +47,111 @@ endfunction()
36
47
function (add_swift_syntax_library name )
37
48
set (ASHL_SOURCES ${ARGN} )
38
49
39
- # Create the library target.
40
- add_library (${name} ${ASHL_SOURCES} )
41
-
42
- # Determine where Swift modules will be built and installed.
43
- set (module_dir ${CMAKE_LIBRARY_OUTPUT_DIRECTORY} )
44
- set (module_base "${module_dir} /${name} .swiftmodule" )
45
- set (module_file "${module_base} /${SWIFT_HOST_MODULE_TRIPLE} .swiftmodule" )
46
- set (module_interface_file "${module_base} /${SWIFT_HOST_MODULE_TRIPLE} .swiftinterface" )
47
- set (module_private_interface_file "${module_base} /${SWIFT_HOST_MODULE_TRIPLE} .private.swiftinterface" )
48
- set (module_sourceinfo_file "${module_base} /${SWIFT_HOST_MODULE_TRIPLE} .swiftsourceinfo" )
50
+ set (target ${SWIFTSYNTAX_TARGET_NAMESPACE}${name} )
49
51
50
- # Add a custom target to create the module directory.
51
- add_custom_command (
52
- TARGET ${name}
52
+ # Create the library target.
53
+ add_library (${target} ${ASHL_SOURCES} )
54
+
55
+ if (NOT DEFINED SWIFTSYNTAX_EMIT_MODULE OR SWIFTSYNTAX_EMIT_MODULE)
56
+ # Determine where Swift modules will be built and installed.
57
+ set (module_dir ${CMAKE_LIBRARY_OUTPUT_DIRECTORY} )
58
+ set (module_base "${module_dir} /${name} .swiftmodule" )
59
+ set (module_file "${module_base} /${SWIFT_HOST_MODULE_TRIPLE} .swiftmodule" )
60
+ set (module_interface_file "${module_base} /${SWIFT_HOST_MODULE_TRIPLE} .swiftinterface" )
61
+ set (module_private_interface_file "${module_base} /${SWIFT_HOST_MODULE_TRIPLE} .private.swiftinterface" )
62
+ set (module_sourceinfo_file "${module_base} /${SWIFT_HOST_MODULE_TRIPLE} .swiftsourceinfo" )
63
+
64
+ # Add a custom target to create the module directory.
65
+ add_custom_command (
66
+ TARGET ${target}
53
67
PRE_BUILD
54
68
COMMAND "${CMAKE_COMMAND} " -E make_directory ${module_base}
55
- COMMENT "Generating module directory for ${name} " )
69
+ COMMENT "Generating module directory for ${target} " )
70
+
71
+ # Configure the emission of the Swift module files.
72
+ target_compile_options ("${target} " PRIVATE
73
+ $<$<COMPILE_LANGUAGE:Swift>:
74
+ -DRESILIENT_LIBRARIES;
75
+ -enable-library-evolution;
76
+ -emit-module-path ;${module_file} ;
77
+ -emit-module-source -info-path ;${module_sourceinfo_file} ;
78
+ -emit-module-interface -path ;${module_interface_file} ;
79
+ -emit-private -module-interface -path ;${module_private_interface_file}
80
+ >)
81
+ else ()
82
+ set (module_dir ${CMAKE_CURRENT_BINARY_DIR} )
83
+ set (module_base "${module_dir} /${name} .swiftmodule" )
84
+ set (module_file "${module_file} " )
85
+ endif ()
56
86
57
87
# Touch the library and objects to workaround their mtime not being updated
58
88
# when there are no real changes (eg. a file was updated with a comment).
59
89
# Ideally this should be done in the driver, which could only update the
60
90
# files that have changed.
61
91
add_custom_command (
62
- TARGET ${name}
63
- POST_BUILD
64
- COMMAND "${CMAKE_COMMAND} " -E touch_nocreate $<TARGET_FILE:${name} > $<TARGET_OBJECTS:${name} > "${module_base} "
65
- COMMAND_EXPAND_LISTS
66
- COMMENT "Update mtime of library outputs workaround" )
67
-
68
- # Install the Swift module into the appropriate location.
69
- set_target_properties (${name}
70
- PROPERTIES Swift_MODULE_DIRECTORY ${module_dir}
92
+ TARGET ${target}
93
+ POST_BUILD
94
+ COMMAND "${CMAKE_COMMAND} " -E touch_nocreate $<TARGET_FILE:${target} > $<TARGET_OBJECTS:${target} > "${module_base} "
95
+ COMMAND_EXPAND_LISTS
96
+ COMMENT "Update mtime of library outputs workaround" )
97
+
98
+ set_target_properties (${target} PROPERTIES
99
+ Swift_MODULE_NAME ${name}
100
+ Swift_MODULE_DIRECTORY ${module_dir}
101
+ INTERFACE_INCLUDE_DIRECTORIES ${module_dir}
71
102
)
72
103
73
104
# Configure the emission of the Swift module files.
74
- target_compile_options ("${name } " PRIVATE
105
+ target_compile_options ("${target } " PRIVATE
75
106
$<$<COMPILE_LANGUAGE:Swift>:
76
- -DRESILIENT_LIBRARIES;
77
- -module-name ;${name} ;
78
- -enable-library-evolution;
79
- -emit-module-path ;${module_file} ;
80
- -emit-module-source -info-path ;${module_sourceinfo_file} ;
81
- -emit-module-interface -path ;${module_interface_file} ;
82
- -emit-private -module-interface -path ;${module_private_interface_file}
107
+ "SHELL:-module-name ${name} "
108
+ "SHELL:-Xfrontend -module-abi-name -Xfrontend ${SWIFT_MODULE_ABI_NAME_PREFIX}${name} "
83
109
>)
84
- if (SWIFT_MODULE_ABI_NAME_PREFIX)
85
- # ABI name prefix. this can be used to avoid name conflicts.
86
- target_compile_options ("${name} " PRIVATE
87
- $<$<COMPILE_LANGUAGE:Swift>:
88
- "SHELL:-Xfrontend -module-abi-name -Xfrontend ${SWIFT_MODULE_ABI_NAME_PREFIX}${name} "
89
- >)
90
- endif ()
91
110
92
111
if (CMAKE_VERSION VERSION_LESS 3.26.0 AND SWIFT_SYNTAX_ENABLE_WMO_PRE_3_26)
93
- target_compile_options (${name } PRIVATE
112
+ target_compile_options (${target } PRIVATE
94
113
$<$<COMPILE_LANGUAGE:Swift>:-wmo>)
95
114
endif ()
96
115
97
- target_compile_options (${name } PRIVATE
116
+ target_compile_options (${target } PRIVATE
98
117
$<$<COMPILE_LANGUAGE:Swift>:-color-diagnostics>
99
118
)
100
119
101
120
if (LLVM_USE_LINKER)
102
- target_link_options (${name } PRIVATE
121
+ target_link_options (${target } PRIVATE
103
122
"-use-ld=${LLVM_USE_LINKER} "
104
123
)
105
124
endif ()
106
125
107
126
# NOTE: workaround for CMake not setting up include flags yet
108
- set_target_properties (${name } PROPERTIES
127
+ set_target_properties (${target } PROPERTIES
109
128
INTERFACE_INCLUDE_DIRECTORIES ${module_dir}
110
129
)
111
130
112
- set_target_properties (${name } PROPERTIES
131
+ set_target_properties (${target } PROPERTIES
113
132
BUILD_WITH_INSTALL_RPATH YES
114
133
)
115
134
116
135
if (SWIFT_HOST_LIBRARIES_RPATH)
117
136
# Don't add builder's stdlib RPATH automatically.
118
- target_compile_options (${name } PRIVATE -no -toolchain-stdlib-rpath)
119
- set_property (TARGET ${name }
137
+ target_compile_options (${target } PRIVATE -no -toolchain-stdlib-rpath)
138
+ set_property (TARGET ${target }
120
139
PROPERTY INSTALL_RPATH "${SWIFT_HOST_LIBRARIES_RPATH} "
121
140
)
122
141
endif ()
123
142
124
- get_target_property (lib_type ${name } TYPE )
143
+ get_target_property (lib_type ${target } TYPE )
125
144
if (lib_type STREQUAL SHARED_LIBRARY)
126
145
if (CMAKE_SYSTEM_NAME STREQUAL Darwin)
127
146
# Allow install_name_tool to update paths (for rdar://109473564)
128
- set_property (TARGET ${name } APPEND_STRING PROPERTY
147
+ set_property (TARGET ${target } APPEND_STRING PROPERTY
129
148
LINK_FLAGS " -Xlinker -headerpad_max_install_names" )
130
149
endif ()
131
150
endif ()
132
151
133
152
if (PROJECT_IS_TOP_LEVEL OR SWIFT_SYNTAX_INSTALL_TARGETS)
134
153
# Install this target
135
- install (TARGETS ${name }
154
+ install (TARGETS ${target }
136
155
EXPORT SwiftSyntaxTargets
137
156
ARCHIVE DESTINATION lib/${SWIFT_HOST_LIBRARIES_SUBDIRECTORY}
138
157
LIBRARY DESTINATION lib/${SWIFT_HOST_LIBRARIES_SUBDIRECTORY}
@@ -146,7 +165,7 @@ function(add_swift_syntax_library name)
146
165
FILES_MATCHING PATTERN "*.swiftinterface"
147
166
)
148
167
else ()
149
- set_property (GLOBAL APPEND PROPERTY SWIFT_EXPORTS ${name } )
168
+ set_property (GLOBAL APPEND PROPERTY SWIFT_EXPORTS ${target } )
150
169
endif ()
151
- add_library (SwiftSyntax::${name } ALIAS ${name } )
170
+ add_library (SwiftSyntax::${target } ALIAS ${target } )
152
171
endfunction ()
0 commit comments