@@ -159,41 +159,34 @@ function(_add_host_variant_c_compile_link_flags)
159
159
endfunction ()
160
160
161
161
162
- function (_add_host_variant_c_compile_flags )
163
- set (oneValueArgs RESULT_VAR_NAME )
164
- cmake_parse_arguments (CFLAGS
165
- ""
166
- "${oneValueArgs} "
167
- ""
168
- ${ARGN} )
169
-
170
- set (result ${${CFLAGS_RESULT_VAR_NAME}} )
171
-
162
+ function (_add_host_variant_c_compile_flags target )
172
163
_add_host_variant_c_compile_link_flags (
173
164
ANALYZE_CODE_COVERAGE FALSE
174
165
RESULT_VAR_NAME result )
166
+ target_compile_options (${target} PRIVATE
167
+ ${result} )
175
168
176
169
is_build_type_optimized ("${CMAKE_BUILD_TYPE} " optimized )
177
170
if (optimized )
178
- list ( APPEND result " -O2" )
171
+ target_compile_options ( ${target} PRIVATE -O2 )
179
172
180
173
# Omit leaf frame pointers on x86 production builds (optimized, no debug
181
174
# info, and no asserts).
182
175
is_build_type_with_debuginfo ("${CMAKE_BUILD_TYPE} " debug )
183
176
if (NOT debug AND NOT LLVM_ENABLE_ASSERTIONS )
184
177
if (SWIFT_HOST_VARIANT_ARCH MATCHES "i?86" )
185
178
if (NOT SWIFT_COMPILER_IS_MSVC_LIKE )
186
- list ( APPEND result " -momit-leaf-frame-pointer" )
179
+ target_compile_options ( ${target} PRIVATE -momit-leaf-frame-pointer )
187
180
else ()
188
- list ( APPEND result " /Oy" )
181
+ target_compile_options ( ${target} PRIVATE /Oy )
189
182
endif ()
190
183
endif ()
191
184
endif ()
192
185
else ()
193
186
if (NOT SWIFT_COMPILER_IS_MSVC_LIKE )
194
- list ( APPEND result " -O0" )
187
+ target_compile_options ( ${target} PRIVATE -O0 )
195
188
else ()
196
- list ( APPEND result " /Od" )
189
+ target_compile_options ( ${target} PRIVATE /Od )
197
190
endif ()
198
191
endif ()
199
192
@@ -203,64 +196,73 @@ function(_add_host_variant_c_compile_flags)
203
196
if (debuginfo )
204
197
_compute_lto_flag ("${SWIFT_TOOLS_ENABLE_LTO} " _lto_flag_out )
205
198
if (_lto_flag_out )
206
- list ( APPEND result " -gline-tables-only" )
199
+ target_compile_options ( ${target} PRIVATE -gline-tables-only )
207
200
else ()
208
- list ( APPEND result "-g" )
201
+ target_compile_options ( ${target} PRIVATE -g )
209
202
endif ()
210
203
else ()
211
- list ( APPEND result " -g0" )
204
+ target_compile_options ( ${target} PRIVATE -g0 )
212
205
endif ()
213
206
endif ()
214
207
215
208
if (SWIFT_HOST_VARIANT_SDK STREQUAL WINDOWS )
216
209
# MSVC/clang-cl don't support -fno-pic or -fms-compatibility-version.
217
210
if (NOT SWIFT_COMPILER_IS_MSVC_LIKE )
218
- list (APPEND result -fno-pic )
219
- list (APPEND result "-fms-compatibility-version=1900" )
211
+ target_compile_options (${target} PRIVATE
212
+ -fms-compatibility-version=1900
213
+ -fno-pic )
220
214
endif ()
221
215
222
- list (APPEND result "-DLLVM_ON_WIN32" )
223
- list (APPEND result "-D_CRT_SECURE_NO_WARNINGS" )
224
- list (APPEND result "-D_CRT_NONSTDC_NO_WARNINGS" )
216
+ target_compile_definitions (${target} PRIVATE
217
+ LLVM_ON_WIN32
218
+ _CRT_SECURE_NO_WARNINGS
219
+ _CRT_NONSTDC_NO_WARNINGS )
225
220
if (NOT "${CMAKE_C_COMPILER_ID} " STREQUAL "MSVC" )
226
- list (APPEND result "-D_CRT_USE_BUILTIN_OFFSETOF" )
221
+ target_compile_definitions (${target} PRIVATE
222
+ _CRT_USE_BUILTIN_OFFSETOF )
227
223
endif ()
228
224
# TODO(compnerd) permit building for different families
229
- list (APPEND result "-D_CRT_USE_WINAPI_FAMILY_DESKTOP_APP" )
225
+ target_compile_definitions (${target} PRIVATE
226
+ _CRT_USE_WINAPI_FAMILY_DESKTOP_APP )
230
227
if (SWIFT_HOST_VARIANT_ARCH MATCHES arm )
231
- list (APPEND result "-D_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE" )
228
+ target_compile_definitions (${target} PRIVATE
229
+ _ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE )
232
230
endif ()
233
- list (APPEND result "-D_MT" )
234
- # TODO(compnerd) handle /MT
235
- list (APPEND result "-D_DLL" )
236
- # NOTE: We assume that we are using VS 2015 U2+
237
- list (APPEND result "-D_ENABLE_ATOMIC_ALIGNMENT_FIX" )
238
- # NOTE: We use over-aligned values for the RefCount side-table
239
- # (see revision d913eefcc93f8c80d6d1a6de4ea898a2838d8b6f)
240
- # This is required to build with VS2017 15.8+
241
- list (APPEND result "-D_ENABLE_EXTENDED_ALIGNED_STORAGE=1" )
231
+ target_compile_definitions (${target} PRIVATE
232
+ # TODO(compnerd) handle /MT
233
+ _MD
234
+ _DLL
235
+ # NOTE: We assume that we are using VS 2015 U2+
236
+ _ENABLE_ATOMIC_ALIGNMENT_FIX
237
+ # NOTE: We use over-aligned values for the RefCount side-table
238
+ # (see revision d913eefcc93f8c80d6d1a6de4ea898a2838d8b6f)
239
+ # This is required to build with VS2017 15.8+
240
+ _ENABLE_EXTENDED_ALIGNED_STORAGE=1 )
242
241
243
242
# msvcprt's std::function requires RTTI, but we do not want RTTI data.
244
243
# Emulate /GR-.
245
244
# TODO(compnerd) when moving up to VS 2017 15.3 and newer, we can disable
246
245
# RTTI again
247
246
if (SWIFT_COMPILER_IS_MSVC_LIKE )
248
- list ( APPEND result /GR- )
247
+ target_compile_options ( ${target} PRIVATE /GR- )
249
248
else ()
250
- list (APPEND result -frtti )
251
- list (APPEND result -Xclang;-fno-rtti-data )
249
+ target_compile_options (${target} PRIVATE
250
+ -frtti
251
+ "SHELL:-Xclang -fno-rtti-data" )
252
252
endif ()
253
253
254
254
# NOTE: VS 2017 15.3 introduced this to disable the static components of
255
255
# RTTI as well. This requires a newer SDK though and we do not have
256
256
# guarantees on the SDK version currently.
257
- list (APPEND result "-D_HAS_STATIC_RTTI=0" )
257
+ target_compile_definitions (${target} PRIVATE
258
+ _HAS_STATIC_RTTI=0 )
258
259
259
260
# NOTE(compnerd) workaround LLVM invoking `add_definitions(-D_DEBUG)` which
260
261
# causes failures for the runtime library when cross-compiling due to
261
262
# undefined symbols from the standard library.
262
263
if (NOT CMAKE_BUILD_TYPE STREQUAL Debug )
263
- list (APPEND result "-U_DEBUG" )
264
+ target_compile_options (${target} PRIVATE
265
+ -U_DEBUG )
264
266
endif ()
265
267
endif ()
266
268
@@ -274,52 +276,54 @@ function(_add_host_variant_c_compile_flags)
274
276
# the build.
275
277
if (CMAKE_C_COMPILER_ID MATCHES Clang AND CMAKE_C_COMPILER_VERSION
276
278
VERSION_LESS 9.0.0 )
277
- list ( APPEND result -mcx16 )
279
+ target_compile_options ( ${target} PRIVATE -mcx16 )
278
280
endif ()
279
281
endif ()
280
282
endif ()
281
283
282
284
if (LLVM_ENABLE_ASSERTIONS )
283
- list ( APPEND result " -UNDEBUG" )
285
+ target_compile_options ( ${target} PRIVATE -UNDEBUG )
284
286
else ()
285
- list ( APPEND result " -DNDEBUG" )
287
+ target_compile_definitions ( ${target} PRIVATE -DNDEBUG )
286
288
endif ()
287
-
289
+
288
290
if (SWIFT_ENABLE_RUNTIME_FUNCTION_COUNTERS )
289
- list (APPEND result "-DSWIFT_ENABLE_RUNTIME_FUNCTION_COUNTERS" )
291
+ target_compile_definitions (${target} PRIVATE
292
+ SWIFT_ENABLE_RUNTIME_FUNCTION_COUNTERS )
290
293
endif ()
291
294
292
295
if (SWIFT_ANALYZE_CODE_COVERAGE )
293
- list (APPEND result "-fprofile-instr-generate"
294
- "-fcoverage-mapping" )
296
+ target_compile_options (${target} PRIVATE
297
+ -fprofile-instr-generate
298
+ -fcoverage-mapping )
295
299
endif ()
296
300
297
301
if ((SWIFT_HOST_VARIANT_ARCH STREQUAL armv7 OR
298
302
SWIFT_HOST_VARIANT_ARCH STREQUAL aarch64 ) AND
299
303
(SWIFT_HOST_VARIANT_SDK STREQUAL LINUX OR
300
304
SWIFT_HOST_VARIANT_SDK STREQUAL ANDROID ))
301
- list ( APPEND result -funwind-tables )
305
+ target_compile_options ( ${target} PRIVATE -funwind-tables )
302
306
endif ()
303
307
304
308
if (SWIFT_HOST_VARIANT_SDK STREQUAL ANDROID )
305
- list ( APPEND result -nostdinc++ )
309
+ target_compile_options ( ${target} PRIVATE -nostdinc++ )
306
310
swift_android_libcxx_include_paths (CFLAGS_CXX_INCLUDES )
307
311
swift_android_include_for_arch ("${SWIFT_HOST_VARIANT_ARCH} "
308
312
"${SWIFT_HOST_VARIANT_ARCH} _INCLUDE" )
309
- foreach (path IN LISTS CFLAGS_CXX_INCLUDES ${SWIFT_HOST_VARIANT_ARCH} _INCLUDE )
310
- list (APPEND result "SHELL:${CMAKE_INCLUDE_SYSTEM_FLAG_C}${path} " )
311
- endforeach ()
312
- list (APPEND result "-D__ANDROID_API__=${SWIFT_ANDROID_API_LEVEL} " )
313
+ target_include_directories (${target} SYSTEM PRIVATE
314
+ ${CFLAGS_CXX_INCLUDES}
315
+ ${${SWIFT_HOST_VARIANT_ARCH}_INCLUDE} )
316
+ target_compile_definitions (${target} PRIVATE
317
+ __ANDROID_API__=${SWIFT_ANDROID_API_LEVEL} )
313
318
endif ()
314
319
315
320
if (SWIFT_HOST_VARIANT_SDK STREQUAL "LINUX" )
316
321
if (SWIFT_HOST_VARIANT_ARCH STREQUAL x86_64 )
317
- # this is the minimum architecture that supports 16 byte CAS, which is necessary to avoid a dependency to libatomic
318
- list (APPEND result "-march=core2" )
322
+ # this is the minimum architecture that supports 16 byte CAS, which is
323
+ # necessary to avoid a dependency to libatomic
324
+ target_compile_options (${target} PRIVATE -march=core2 )
319
325
endif ()
320
326
endif ()
321
-
322
- set ("${CFLAGS_RESULT_VAR_NAME} " "${result} " PARENT_SCOPE )
323
327
endfunction ()
324
328
325
329
function (_add_host_variant_link_flags target )
@@ -586,18 +590,16 @@ function(_add_swift_host_library_single target)
586
590
# Call llvm_config() only for libraries that are part of the compiler.
587
591
swift_common_llvm_config ("${target} " ${ASHLS_LLVM_LINK_COMPONENTS} )
588
592
589
- # Collect compile and link flags for the static and non-static targets.
590
- # Don't set PROPERTY COMPILE_FLAGS or LINK_FLAGS directly.
591
- set (c_compile_flags ${ASHLS_C_COMPILE_FLAGS} )
592
- set (link_flags )
593
-
594
- _add_host_variant_c_compile_flags (RESULT_VAR_NAME c_compile_flags )
595
-
593
+ target_compile_options (${target} PRIVATE
594
+ ${ASHLS_C_COMPILE_FLAGS} )
596
595
if (SWIFT_HOST_VARIANT_SDK STREQUAL WINDOWS )
597
596
if (libkind STREQUAL SHARED )
598
- list (APPEND c_compile_flags -D_WINDLL )
597
+ target_compile_definitions (${target} PRIVATE
598
+ _WINDLL )
599
599
endif ()
600
600
endif ()
601
+
602
+ _add_host_variant_c_compile_flags (${target} )
601
603
_add_host_variant_link_flags (${target} )
602
604
603
605
# Set compilation and link flags.
@@ -621,8 +623,6 @@ function(_add_swift_host_library_single target)
621
623
endif ()
622
624
endif ()
623
625
624
- target_compile_options (${target} PRIVATE
625
- ${c_compile_flags} )
626
626
if (${SWIFT_HOST_VARIANT_SDK} IN_LIST SWIFT_APPLE_PLATFORMS )
627
627
target_link_options (${target} PRIVATE
628
628
"LINKER:-compatibility_version,1" )
@@ -743,11 +743,9 @@ function(add_swift_host_tool executable)
743
743
precondition (ASHT_SWIFT_COMPONENT
744
744
MESSAGE "Swift Component is required to add a host tool" )
745
745
746
- _add_host_variant_c_compile_flags (RESULT_VAR_NAME c_compile_flags )
747
746
748
747
add_executable (${executable} ${ASHT_UNPARSED_ARGUMENTS} )
749
- target_compile_options (${executable} PRIVATE
750
- ${c_compile_flags} )
748
+ _add_host_variant_c_compile_flags (${executable} )
751
749
_add_host_variant_link_flags (${executable} )
752
750
target_link_directories (${executable} PRIVATE
753
751
${SWIFTLIB_DIR} /${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR} )
0 commit comments