@@ -401,17 +401,16 @@ function(_add_host_variant_link_flags target)
401
401
endif ()
402
402
endfunction ()
403
403
404
- # Add a single variant of a new Swift library.
404
+ # Add a new Swift host library.
405
405
#
406
406
# Usage:
407
- # _add_swift_host_library_single(
408
- # target
407
+ # add_swift_host_library(name
409
408
# [SHARED]
410
409
# [STATIC]
411
410
# [LLVM_LINK_COMPONENTS comp1 ...]
412
411
# source1 [source2 source3 ...])
413
412
#
414
- # target
413
+ # name
415
414
# Name of the library (e.g., swiftParse).
416
415
#
417
416
# SHARED
@@ -424,229 +423,142 @@ endfunction()
424
423
# LLVM components this library depends on.
425
424
#
426
425
# source1 ...
427
- # Sources to add into this library
428
- function (_add_swift_host_library_single target )
426
+ # Sources to add into this library.
427
+ function (add_swift_host_library name )
429
428
set (options
430
429
SHARED
431
430
STATIC )
432
431
set (single_parameter_options )
433
432
set (multiple_parameter_options
434
433
LLVM_LINK_COMPONENTS )
435
434
436
- cmake_parse_arguments (ASHLS
435
+ cmake_parse_arguments (ASHL
437
436
"${options} "
438
437
"${single_parameter_options} "
439
438
"${multiple_parameter_options} "
440
439
${ARGN} )
441
- set (ASHLS_SOURCES ${ASHLS_UNPARSED_ARGUMENTS } )
440
+ set (ASHL_SOURCES ${ASHL_UNPARSED_ARGUMENTS } )
442
441
443
- translate_flags (ASHLS "${options} " )
442
+ translate_flags (ASHL "${options} " )
444
443
445
- if (NOT ASHLS_SHARED AND NOT ASHLS_STATIC )
444
+ if (NOT ASHL_SHARED AND NOT ASHL_STATIC )
446
445
message (FATAL_ERROR "Either SHARED or STATIC must be specified" )
447
446
endif ()
448
447
449
- # Include LLVM Bitcode slices for iOS, Watch OS, and Apple TV OS device libraries.
450
- set (embed_bitcode_arg )
451
- if (SWIFT_EMBED_BITCODE_SECTION )
452
- if (SWIFT_HOST_VARIANT_SDK MATCHES "(I|TV|WATCH)OS" )
453
- list (APPEND ASHLS_C_COMPILE_FLAGS "-fembed-bitcode" )
454
- set (embed_bitcode_arg EMBED_BITCODE )
455
- endif ()
456
- endif ()
457
-
458
448
if (XCODE )
459
- string ( REGEX MATCHALL "/[^/]+" split_path ${CMAKE_CURRENT_SOURCE_DIR} )
460
- list ( GET split_path -1 dir )
461
- file (GLOB_RECURSE ASHLS_HEADERS
449
+ get_filename_component ( dir ${CMAKE_CURRENT_SOURCE_DIR} DIRECTORY )
450
+
451
+ file (GLOB_RECURSE ASHL_HEADERS
462
452
${SWIFT_SOURCE_DIR} /include/swift${dir}/*.h
463
453
${SWIFT_SOURCE_DIR} /include/swift${dir}/*.def
464
454
${CMAKE_CURRENT_SOURCE_DIR} /*.def )
465
-
466
- file (GLOB_RECURSE ASHLS_TDS
455
+ file (GLOB_RECURSE ASHL_TDS
467
456
${SWIFT_SOURCE_DIR} /include/swift${dir}/*.td )
468
457
469
- set_source_files_properties (${ASHLS_HEADERS} ${ASHLS_TDS}
470
- PROPERTIES
458
+ set_source_files_properties (${ASHL_HEADERS} ${ASHL_TDS} PROPERTIES
471
459
HEADER_FILE_ONLY true )
472
- source_group ("TableGen descriptions" FILES ${ASHLS_TDS } )
460
+ source_group ("TableGen descriptions" FILES ${ASHL_TDS } )
473
461
474
- set (ASHLS_SOURCES ${ASHLS_SOURCES } ${ASHLS_HEADERS } ${ASHLS_TDS } )
462
+ set (ASHL_SOURCES ${ASHL_SOURCES } ${ASHL_HEADERS } ${ASHL_TDS } )
475
463
endif ()
476
464
477
- if (ASHLS_SHARED )
465
+ if (ASHL_SHARED )
478
466
set (libkind SHARED )
479
- elseif (ASHLS_STATIC )
467
+ elseif (ASHL_STATIC )
480
468
set (libkind STATIC )
481
469
endif ()
482
470
483
- add_library ("${target} " ${libkind} ${ASHLS_SOURCES} )
484
- _set_target_prefix_and_suffix ("${target} " "${libkind} " "${SWIFT_HOST_VARIANT_SDK} " )
485
- add_dependencies (${target} ${LLVM_COMMON_DEPENDS} )
486
-
487
- if (SWIFT_HOST_VARIANT_SDK STREQUAL WINDOWS )
488
- swift_windows_include_for_arch (${SWIFT_HOST_VARIANT_ARCH} SWIFTLIB_INCLUDE )
489
- target_include_directories ("${target} " SYSTEM PRIVATE ${SWIFTLIB_INCLUDE} )
490
- set_target_properties (${target}
491
- PROPERTIES
492
- CXX_STANDARD 14 )
493
- endif ()
494
-
495
- if (SWIFT_HOST_VARIANT_SDK STREQUAL WINDOWS )
496
- set_property (TARGET "${target} " PROPERTY NO_SONAME ON )
497
- endif ()
498
-
499
- llvm_update_compile_flags (${target} )
500
-
501
- set_output_directory (${target}
471
+ add_library (${name} ${libkind} ${ASHL_SOURCES} )
472
+ add_dependencies (${name} ${LLVM_COMMON_DEPENDS} )
473
+ llvm_update_compile_flags (${name} )
474
+ swift_common_llvm_config (${name} ${ASHL_LLVM_LINK_COMPONENTS} )
475
+ set_output_directory (${name}
502
476
BINARY_DIR ${SWIFT_RUNTIME_OUTPUT_INTDIR}
503
477
LIBRARY_DIR ${SWIFT_LIBRARY_OUTPUT_INTDIR} )
504
478
505
479
if (SWIFT_HOST_VARIANT_SDK IN_LIST SWIFT_APPLE_PLATFORMS )
506
- set_target_properties (" ${target} "
480
+ set_target_properties (${name}
507
481
PROPERTIES
508
482
INSTALL_NAME_DIR "@rpath" )
509
483
elseif (SWIFT_HOST_VARIANT_SDK STREQUAL LINUX )
510
- set_target_properties (" ${target} "
484
+ set_target_properties (${name}
511
485
PROPERTIES
512
486
INSTALL_RPATH "$ORIGIN:/usr/lib/swift/linux" )
513
487
elseif (SWIFT_HOST_VARIANT_SDK STREQUAL CYGWIN )
514
- set_target_properties (" ${target} "
488
+ set_target_properties (${name}
515
489
PROPERTIES
516
490
INSTALL_RPATH "$ORIGIN:/usr/lib/swift/cygwin" )
517
491
elseif (SWIFT_HOST_VARIANT_SDK STREQUAL "ANDROID" )
518
- set_target_properties (" ${target} "
492
+ set_target_properties (${name}
519
493
PROPERTIES
520
494
INSTALL_RPATH "$ORIGIN" )
521
495
endif ()
522
496
523
- set_target_properties ("${target} " PROPERTIES BUILD_WITH_INSTALL_RPATH YES )
524
- set_target_properties ("${target} " PROPERTIES FOLDER "Swift libraries" )
525
-
526
- # Call llvm_config() only for libraries that are part of the compiler.
527
- swift_common_llvm_config ("${target} " ${ASHLS_LLVM_LINK_COMPONENTS} )
528
-
529
- target_compile_options (${target} PRIVATE
530
- ${ASHLS_C_COMPILE_FLAGS} )
531
- if (SWIFT_HOST_VARIANT_SDK STREQUAL WINDOWS )
532
- if (libkind STREQUAL SHARED )
533
- target_compile_definitions (${target} PRIVATE
534
- _WINDLL )
535
- endif ()
536
- endif ()
537
- # Double-check that we're not trying to build a dynamic library for WASM.
538
- if (SWIFTLIB_SINGLE_SDK MATCHES WASM )
539
- if (libkind STREQUAL SHARED )
540
- message (FATAL_ERROR "WASM does not support shared libraries." )
541
- endif ()
542
- endif ()
497
+ set_target_properties (${name} PROPERTIES
498
+ BUILD_WITH_INSTALL_RPATH YES
499
+ FOLDER "Swift libraries" )
543
500
544
- _add_host_variant_c_compile_flags (${target} )
545
- _add_host_variant_link_flags (${target} )
501
+ _add_host_variant_c_compile_flags (${name} )
502
+ _add_host_variant_link_flags (${name} )
503
+ _set_target_prefix_and_suffix (${name} "${libkind} " "${SWIFT_HOST_VARIANT_SDK} " )
546
504
547
505
# Set compilation and link flags.
548
506
if (SWIFT_HOST_VARIANT_SDK STREQUAL WINDOWS )
549
507
swift_windows_include_for_arch (${SWIFT_HOST_VARIANT_ARCH}
550
508
${SWIFT_HOST_VARIANT_ARCH} _INCLUDE )
551
- target_include_directories (${target } SYSTEM PRIVATE
509
+ target_include_directories (${name } SYSTEM PRIVATE
552
510
${${SWIFT_HOST_VARIANT_ARCH}_INCLUDE} )
553
511
512
+ if (libkind STREQUAL SHARED )
513
+ target_compile_definitions (${name} PRIVATE
514
+ _WINDLL )
515
+ endif ()
516
+
554
517
if (NOT ${CMAKE_C_COMPILER_ID} STREQUAL MSVC )
555
- swift_windows_get_sdk_vfs_overlay (ASHLS_VFS_OVERLAY )
556
- target_compile_options (${target } PRIVATE
557
- "SHELL:-Xclang -ivfsoverlay -Xclang ${ASHLS_VFS_OVERLAY } " )
518
+ swift_windows_get_sdk_vfs_overlay (ASHL_VFS_OVERLAY )
519
+ target_compile_options (${name } PRIVATE
520
+ "SHELL:-Xclang -ivfsoverlay -Xclang ${ASHL_VFS_OVERLAY } " )
558
521
559
522
# MSVC doesn't support -Xclang. We don't need to manually specify
560
523
# the dependent libraries as `cl` does so.
561
- target_compile_options (${target } PRIVATE
524
+ target_compile_options (${name } PRIVATE
562
525
"SHELL:-Xclang --dependent-lib=oldnames"
563
526
# TODO(compnerd) handle /MT, /MTd
564
527
"SHELL:-Xclang --dependent-lib=msvcrt$<$<CONFIG:Debug>:d>" )
565
528
endif ()
529
+
530
+ set_target_properties (${name} PROPERTIES
531
+ CXX_STANDARD 14
532
+ NO_SONAME YES )
566
533
endif ()
567
534
568
535
if (${SWIFT_HOST_VARIANT_SDK} IN_LIST SWIFT_APPLE_PLATFORMS )
569
- target_link_options (${target} PRIVATE
570
- "LINKER:-compatibility_version,1" )
571
- if (SWIFT_COMPILER_VERSION )
572
- target_link_options (${target} PRIVATE
573
- "LINKER:-current_version,${SWIFT_COMPILER_VERSION} " )
574
- endif ()
575
536
# Include LLVM Bitcode slices for iOS, Watch OS, and Apple TV OS device libraries.
576
537
if (SWIFT_EMBED_BITCODE_SECTION )
577
- if (${SWIFT_HOST_VARIANT_SDK} MATCHES "(I|TV|WATCH)OS" )
578
- target_link_options (${target} PRIVATE
579
- "LINKER:-bitcode_bundle"
580
- "LINKER:-lto_library,${LLVM_LIBRARY_DIR} /libLTO.dylib" )
581
-
582
- # Please note that using a generator expression to fit
583
- # this in a single target_link_options does not work
584
- # (at least in CMake 3.15 and 3.16),
585
- # since that seems not to allow the LINKER: prefix to be
586
- # evaluated (i.e. it will be added as-is to the linker parameters)
587
- if (SWIFT_EMBED_BITCODE_SECTION_HIDE_SYMBOLS )
588
- target_link_options (${target} PRIVATE
589
- "LINKER:-bitcode_hide_symbols" )
590
- endif ()
538
+ target_compile_options (${name} PRIVATE
539
+ -fembed-bitcode )
540
+ target_link_options (${name} PRIVATE
541
+ "LINKER:-bitcode_bundle"
542
+ "LINKER:-lto_library,${LLVM_LIBRARY_DIR} /libLTO.dylib" )
543
+
544
+ # Please note that using a generator expression to fit this in a single
545
+ # target_link_options does not work (at least in CMake 3.15 and 3.16),
546
+ # since that seems not to allow the LINKER: prefix to be evaluated (i.e.
547
+ # it will be added as-is to the linker parameters)
548
+ if (SWIFT_EMBED_BITCODE_SECTION_HIDE_SYMBOLS )
549
+ target_link_options (${name} PRIVATE
550
+ "LINKER:-bitcode_hide_symbols" )
591
551
endif ()
592
552
endif ()
593
- endif ()
594
553
595
- # Do not add code here.
596
- endfunction ()
597
-
598
- # Add a new Swift host library.
599
- #
600
- # Usage:
601
- # add_swift_host_library(name
602
- # [SHARED]
603
- # [STATIC]
604
- # [LLVM_LINK_COMPONENTS comp1 ...]
605
- # source1 [source2 source3 ...])
606
- #
607
- # name
608
- # Name of the library (e.g., swiftParse).
609
- #
610
- # SHARED
611
- # Build a shared library.
612
- #
613
- # STATIC
614
- # Build a static library.
615
- #
616
- # LLVM_LINK_COMPONENTS
617
- # LLVM components this library depends on.
618
- #
619
- # source1 ...
620
- # Sources to add into this library.
621
- function (add_swift_host_library name )
622
- set (options
623
- SHARED
624
- STATIC )
625
- set (single_parameter_options )
626
- set (multiple_parameter_options
627
- LLVM_LINK_COMPONENTS )
628
-
629
- cmake_parse_arguments (ASHL
630
- "${options} "
631
- "${single_parameter_options} "
632
- "${multiple_parameter_options} "
633
- ${ARGN} )
634
- set (ASHL_SOURCES ${ASHL_UNPARSED_ARGUMENTS} )
635
-
636
- translate_flags (ASHL "${options} " )
637
-
638
- if (NOT ASHL_SHARED AND NOT ASHL_STATIC )
639
- message (FATAL_ERROR "Either SHARED or STATIC must be specified" )
554
+ target_link_options (${name} PRIVATE
555
+ "LINKER:-compatibility_version,1" )
556
+ if (SWIFT_COMPILER_VERSION )
557
+ target_link_options (${name} PRIVATE
558
+ "LINKER:-current_version,${SWIFT_COMPILER_VERSION} " )
559
+ endif ()
640
560
endif ()
641
561
642
- _add_swift_host_library_single (
643
- ${name}
644
- ${ASHL_SHARED_keyword}
645
- ${ASHL_STATIC_keyword}
646
- ${ASHL_SOURCES}
647
- LLVM_LINK_COMPONENTS ${ASHL_LLVM_LINK_COMPONENTS}
648
- )
649
-
650
562
add_dependencies (dev ${name} )
651
563
if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY )
652
564
swift_install_in_component (TARGETS ${name}
0 commit comments