@@ -50,6 +50,43 @@ function(add_sourcekit_symbol_exports target_name export_file)
5050 endif ()
5151endfunction ()
5252
53+ # Add default compiler and linker flags to 'target'.
54+ #
55+ # FIXME: this is a HACK. All SourceKit CMake code using this function
56+ # should be rewritten to use 'add_swift_library'.
57+ function (add_sourcekit_default_compiler_flags target )
58+ set (sdk "${SWIFT_HOST_VARIANT_SDK} " )
59+ set (arch "${SWIFT_HOST_VARIANT_ARCH} " )
60+ set (c_compile_flags)
61+ set (link_flags )
62+
63+ # Add variant-specific flags.
64+ set (build_type "${CMAKE_BUILD_TYPE} " )
65+ set (enable_assertions "${LLVM_ENABLE_ASSERTIONS} " )
66+ _add_variant_c_compile_flags(
67+ "${sdk} "
68+ "${arch} "
69+ "${build_type} "
70+ "${enable_assertions} "
71+ c_compile_flags)
72+ _add_variant_link_flags(
73+ "${sdk} "
74+ "${arch} "
75+ "${build_type} "
76+ "${enable_assertions} "
77+ link_flags )
78+
79+ # Convert variables to space-separated strings.
80+ _list_escape_for_shell("${c_compile_flags} " c_compile_flags)
81+ _list_escape_for_shell("${link_flags} " link_flags )
82+
83+ # Set compilation and link flags.
84+ set_property (TARGET "${target} " APPEND_STRING PROPERTY
85+ COMPILE_FLAGS " ${c_compile_flags} " )
86+ set_property (TARGET "${target} " APPEND_STRING PROPERTY
87+ LINK_FLAGS " ${link_flags} " )
88+ endfunction ()
89+
5390# Add a new SourceKit library.
5491#
5592# Usage:
@@ -152,6 +189,7 @@ macro(add_sourcekit_library name)
152189 ARCHIVE DESTINATION "lib${LLVM_LIBDIR_SUFFIX} "
153190 RUNTIME DESTINATION "bin" )
154191 set_target_properties (${name} PROPERTIES FOLDER "SourceKit libraries" )
192+ add_sourcekit_default_compiler_flags("${name} " )
155193endmacro ()
156194
157195# Add a new SourceKit executable.
@@ -198,6 +236,7 @@ macro(add_sourcekit_executable name)
198236 LINK_FLAGS "-Wl,-exported_symbol,_main" )
199237 endif ()
200238 endif ()
239+ add_sourcekit_default_compiler_flags("${name} " )
201240endmacro ()
202241
203242# Add a new SourceKit framework.
@@ -313,6 +352,7 @@ macro(add_sourcekit_framework name)
313352 COMMAND ${CMAKE_COMMAND} -E copy "${hdr} " "${framework_location} /Headers/${hdrname} " )
314353 endforeach ()
315354 endif ()
355+ add_sourcekit_default_compiler_flags("${name} " )
316356endmacro (add_sourcekit_framework)
317357
318358# Add a new SourceKit XPC service to a framework.
@@ -384,6 +424,7 @@ macro(add_sourcekit_xpc_service name framework_target)
384424 LINK_FLAGS "-Wl,-exported_symbol,_main" )
385425 endif ()
386426 endif ()
427+ add_sourcekit_default_compiler_flags("${name} " )
387428endmacro ()
388429
389430if ("${CMAKE_SYSTEM_NAME} " STREQUAL "Darwin" )
0 commit comments