@@ -808,143 +808,101 @@ function(add_swift_host_library name)
808
808
endif ()
809
809
endfunction ()
810
810
811
- # Add an executable compiled for a given variant.
812
- #
813
- # Don't use directly, use add_swift_executable and add_swift_target_executable
814
- # instead.
815
- #
816
- # See add_swift_executable for detailed documentation.
817
- #
818
- # Additional parameters:
819
- # [SDK sdk]
820
- # SDK to build for.
821
- #
822
- # [ARCHITECTURE architecture]
823
- # Architecture to build for.
824
- function (_add_swift_host_executable_single name )
811
+ macro (add_swift_tool_subdirectory name )
812
+ add_llvm_subdirectory (SWIFT TOOL ${name} )
813
+ endmacro ()
814
+
815
+ macro (add_swift_lib_subdirectory name )
816
+ add_llvm_subdirectory (SWIFT LIB ${name} )
817
+ endmacro ()
818
+
819
+ function (add_swift_host_tool executable )
825
820
set (options )
826
- set (single_parameter_options
827
- ARCHITECTURE
828
- SDK )
829
- set (multiple_parameter_options
830
- LLVM_LINK_COMPONENTS )
831
- cmake_parse_arguments (SWIFTEXE_SINGLE
821
+ set (single_parameter_options SWIFT_COMPONENT )
822
+ set (multiple_parameter_options LLVM_LINK_COMPONENTS )
823
+
824
+ cmake_parse_arguments (ASHT
832
825
"${options} "
833
826
"${single_parameter_options} "
834
827
"${multiple_parameter_options} "
835
828
${ARGN} )
836
829
837
- set (SWIFTEXE_SINGLE_SOURCES ${SWIFTEXE_SINGLE_UNPARSED_ARGUMENTS} )
838
-
839
- # Check arguments.
840
- precondition (SWIFTEXE_SINGLE_SDK MESSAGE "Should specify an SDK" )
841
- precondition (SWIFTEXE_SINGLE_ARCHITECTURE MESSAGE "Should specify an architecture" )
830
+ precondition (ASHT_SWIFT_COMPONENT
831
+ MESSAGE "Swift Component is required to add a host tool" )
842
832
843
833
# Determine compiler flags.
844
834
set (c_compile_flags )
845
835
set (link_flags )
846
-
847
- # Prepare linker search directories.
836
+ set (link_libraries )
848
837
set (library_search_directories
849
- " ${SWIFTLIB_DIR} /${SWIFT_SDK_${SWIFTEXE_SINGLE_SDK } _LIB_SUBDIR}" )
838
+ ${SWIFTLIB_DIR} /${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK }_LIB_SUBDIR} )
850
839
851
- # Add variant-specific flags.
852
840
_add_host_variant_c_compile_flags (
853
- SDK " ${SWIFTEXE_SINGLE_SDK} "
854
- ARCH " ${SWIFTEXE_SINGLE_ARCHITECTURE} "
855
- BUILD_TYPE " ${CMAKE_BUILD_TYPE} "
856
- ENABLE_ASSERTIONS " ${LLVM_ENABLE_ASSERTIONS} "
857
- ENABLE_LTO " ${SWIFT_TOOLS_ENABLE_LTO} "
858
- ANALYZE_CODE_COVERAGE " ${SWIFT_ANALYZE_CODE_COVERAGE} "
841
+ SDK ${SWIFT_HOST_VARIANT_SDK}
842
+ ARCH ${SWIFT_HOST_VARIANT_ARCH}
843
+ BUILD_TYPE ${CMAKE_BUILD_TYPE}
844
+ ENABLE_ASSERTIONS ${LLVM_ENABLE_ASSERTIONS}
845
+ ENABLE_LTO ${SWIFT_TOOLS_ENABLE_LTO}
846
+ ANALYZE_CODE_COVERAGE ${SWIFT_ANALYZE_CODE_COVERAGE}
859
847
RESULT_VAR_NAME c_compile_flags )
860
848
_add_host_variant_link_flags (
861
- SDK " ${SWIFTEXE_SINGLE_SDK} "
862
- ARCH " ${SWIFTEXE_SINGLE_ARCHITECTURE} "
863
- BUILD_TYPE " ${CMAKE_BUILD_TYPE} "
864
- ENABLE_ASSERTIONS " ${LLVM_ENABLE_ASSERTIONS} "
865
- ENABLE_LTO " ${SWIFT_TOOLS_ENABLE_LTO} "
866
- LTO_OBJECT_NAME "${name } -${SWIFTEXE_SINGLE_SDK } -${SWIFTEXE_SINGLE_ARCHITECTURE } "
867
- ANALYZE_CODE_COVERAGE " ${SWIFT_ANALYZE_CODE_COVERAGE} "
849
+ SDK ${SWIFT_HOST_VARIANT_SDK}
850
+ ARCH ${SWIFT_HOST_VARIANT_ARCH}
851
+ BUILD_TYPE ${CMAKE_BUILD_TYPE}
852
+ ENABLE_ASSERTIONS ${LLVM_ENABLE_ASSERTIONS}
853
+ ENABLE_LTO ${SWIFT_TOOLS_ENABLE_LTO}
854
+ LTO_OBJECT_NAME "${executable } -${SWIFT_HOST_VARIANT_SDK } -${SWIFT_HOST_VARIANT_ARCH } "
855
+ ANALYZE_CODE_COVERAGE ${SWIFT_ANALYZE_CODE_COVERAGE}
868
856
RESULT_VAR_NAME link_flags
869
857
LINK_LIBRARIES_VAR_NAME link_libraries
870
858
LIBRARY_SEARCH_DIRECTORIES_VAR_NAME library_search_directories )
871
859
872
- add_executable (${name}
873
- ${SWIFTEXE_SINGLE_SOURCES}
874
- ${SWIFTEXE_SINGLE_EXTERNAL_SOURCES} )
860
+ add_executable (${executable} ${ASHT_UNPARSED_ARGUMENTS} )
861
+ target_compile_options (${executable} PRIVATE
862
+ ${c_compile_flags} )
863
+ target_link_directories (${executable} PRIVATE
864
+ ${library_search_directories} )
865
+ target_link_options (${executable} PRIVATE
866
+ ${link_flags} )
867
+ target_link_libraries (${executable} PRIVATE
868
+ ${link_libraries} )
869
+
870
+ set_target_properties (${executable} PROPERTIES
871
+ FOLDER "Swift executables" )
872
+ if (SWIFT_PARALLEL_LINK_JOBS )
873
+ set_target_properties (${executable} PROPERTIES
874
+ JOB_POOL_LINK swift_link_job_pool )
875
+ endif ()
876
+ if (${SWIFT_HOST_VARIANT_SDK} IN_LIST SWIFT_APPLE_PLATFORMS )
877
+ set_target_properties (${executable} PROPERTIES
878
+ BUILD_WITH_INSTALL_RPATH YES
879
+ INSTALL_RPATH "@executable_path/../lib/swift/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK} _LIB_SUBDIR}" )
880
+ endif ()
875
881
876
882
add_dependencies_multiple_targets (
877
- TARGETS ${name}
878
- DEPENDS ${LLVM_COMMON_DEPENDS} )
879
- llvm_update_compile_flags ("${name} " )
883
+ TARGETS ${executable}
884
+ DEPENDS ${LLVM_COMMON_DEPENDS} )
885
+ llvm_update_compile_flags (${executable} )
886
+ swift_common_llvm_config (${executable} ${ASHT_LLVM_LINK_COMPONENTS} )
887
+ set_output_directory (${executable}
888
+ BINARY_DIR ${SWIFT_RUNTIME_OUTPUT_INTDIR}
889
+ LIBRARY_DIR ${SWIFT_LIBRARY_OUTPUT_INTDIR} )
880
890
881
- if (SWIFTEXE_SINGLE_SDK STREQUAL WINDOWS )
882
- swift_windows_include_for_arch (${SWIFTEXE_SINGLE_ARCHITECTURE }
883
- ${SWIFTEXE_SINGLE_ARCHITECTURE } _INCLUDE )
884
- target_include_directories (${name } SYSTEM PRIVATE
885
- ${${SWIFTEXE_SINGLE_ARCHITECTURE }_INCLUDE} )
891
+ if (SWIFT_HOST_VARIANT_SDK STREQUAL WINDOWS )
892
+ swift_windows_include_for_arch (${SWIFT_HOST_VARIANT_ARCH }
893
+ ${SWIFT_HOST_VARIANT_ARCH } _INCLUDE )
894
+ target_include_directories (${executable } SYSTEM PRIVATE
895
+ ${${SWIFT_HOST_VARIANT_ARCH }_INCLUDE} )
886
896
887
897
if (NOT ${CMAKE_C_COMPILER_ID} STREQUAL MSVC )
888
898
# MSVC doesn't support -Xclang. We don't need to manually specify
889
899
# the dependent libraries as `cl` does so.
890
- target_compile_options (${name } PRIVATE
900
+ target_compile_options (${executable } PRIVATE
891
901
"SHELL:-Xclang --dependent-lib=oldnames"
892
902
# TODO(compnerd) handle /MT, /MTd
893
903
"SHELL:-Xclang --dependent-lib=msvcrt$<$<CONFIG:Debug>:d>" )
894
904
endif ()
895
905
endif ()
896
- target_compile_options (${name} PRIVATE
897
- ${c_compile_flags} )
898
- target_link_directories (${name} PRIVATE
899
- ${library_search_directories} )
900
- target_link_options (${name} PRIVATE
901
- ${link_flags} )
902
- target_link_libraries (${name} PRIVATE
903
- ${link_libraries} )
904
- if (SWIFT_PARALLEL_LINK_JOBS )
905
- set_property (TARGET ${name} PROPERTY JOB_POOL_LINK swift_link_job_pool )
906
- endif ()
907
- if (${SWIFTEXE_SINGLE_SDK} IN_LIST SWIFT_APPLE_PLATFORMS )
908
- set_target_properties (${name} PROPERTIES
909
- BUILD_WITH_INSTALL_RPATH YES
910
- INSTALL_RPATH "@executable_path/../lib/swift/${SWIFT_SDK_${SWIFTEXE_SINGLE_SDK} _LIB_SUBDIR}" )
911
- endif ()
912
- set_output_directory (${name}
913
- BINARY_DIR ${SWIFT_RUNTIME_OUTPUT_INTDIR}
914
- LIBRARY_DIR ${SWIFT_LIBRARY_OUTPUT_INTDIR} )
915
-
916
- swift_common_llvm_config ("${name} " ${SWIFTEXE_SINGLE_LLVM_LINK_COMPONENTS} )
917
-
918
- set_target_properties (${name} PROPERTIES FOLDER "Swift executables" )
919
- endfunction ()
920
-
921
- macro (add_swift_tool_subdirectory name )
922
- add_llvm_subdirectory (SWIFT TOOL ${name} )
923
- endmacro ()
924
-
925
- macro (add_swift_lib_subdirectory name )
926
- add_llvm_subdirectory (SWIFT LIB ${name} )
927
- endmacro ()
928
-
929
- function (add_swift_host_tool executable )
930
- set (options )
931
- set (single_parameter_options SWIFT_COMPONENT )
932
- set (multiple_parameter_options )
933
-
934
- cmake_parse_arguments (ASHT
935
- "${options} "
936
- "${single_parameter_options} "
937
- "${multiple_parameter_options} "
938
- ${ARGN} )
939
-
940
- precondition (ASHT_SWIFT_COMPONENT
941
- MESSAGE "Swift Component is required to add a host tool" )
942
-
943
- # Create the executable rule.
944
- _add_swift_host_executable_single (${executable}
945
- SDK ${SWIFT_HOST_VARIANT_SDK}
946
- ARCHITECTURE ${SWIFT_HOST_VARIANT_ARCH}
947
- ${ASHT_UNPARSED_ARGUMENTS} )
948
906
949
907
add_dependencies (${ASHT_SWIFT_COMPONENT} ${executable} )
950
908
swift_install_in_component (TARGETS ${executable}
0 commit comments