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