diff --git a/Sources/CMakeLists.txt b/Sources/CMakeLists.txt index f7f7ba156..ad8ecf178 100644 --- a/Sources/CMakeLists.txt +++ b/Sources/CMakeLists.txt @@ -12,12 +12,31 @@ ## ##===----------------------------------------------------------------------===## -add_subdirectory(_FoundationCShims) - -# Disable the macro build on Windows until we can correctly build it for the host architecture -if(NOT CMAKE_SYSTEM_NAME STREQUAL Windows) - add_subdirectory(FoundationMacros) +include(ExternalProject) +if(CMAKE_HOST_WIN32) + set(_flags "-use-ld=lld") + if(DEFINED CMAKE_HOST_Swift_FLAGS) + set(_flags "${_flags} ${CMAKE_HOST_Swift_FLAGS}") + endif() + set(_FoundationMacrosSwiftFlags "-DCMAKE_Swift_FLAGS=${_flags}") +endif() +ExternalProject_Add(FoundationMacros + SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/FoundationMacros" + PREFIX "${CMAKE_BINARY_DIR}/_deps" + BINARY_DIR "macros" + CMAKE_ARGS + -DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM} + ${_FoundationMacrosSwiftFlags} + INSTALL_COMMAND "") +ExternalProject_Get_Property(FoundationMacros BINARY_DIR) +if(CMAKE_HOST_WIN32) + set(_SwiftFoundation_PredicateMacro "${BINARY_DIR}/FoundationMacros.exe#PredicateMacro") + set(_SwiftFoundation_ExpressionMacro "${BINARY_DIR}/FoundationMacros.exe#ExpressionMacro") +else() + set(_SwiftFoundation_PredicateMacro "${BINARY_DIR}/FoundationMacros#PredicateMacro") + set(_SwiftFoundation_ExpressionMacro "${BINARY_DIR}/FoundationMacros#ExpressionMacro") endif() +add_subdirectory(_FoundationCShims) add_subdirectory(FoundationEssentials) add_subdirectory(FoundationInternationalization) diff --git a/Sources/FoundationMacros/CMakeLists.txt b/Sources/FoundationMacros/CMakeLists.txt index bbc7bd628..239dd6c44 100644 --- a/Sources/FoundationMacros/CMakeLists.txt +++ b/Sources/FoundationMacros/CMakeLists.txt @@ -12,10 +12,25 @@ ## ##===----------------------------------------------------------------------===## +cmake_minimum_required(VERSION 3.22) + +if(POLICY CMP0156) + # Deduplicate linked libraries where appropriate + cmake_policy(SET CMP0156 NEW) +endif() +if(POLICY CMP0157) + # New Swift build model: improved incremental build performance and LSP support + cmake_policy(SET CMP0157 NEW) +endif() + +project(FoundationMacros + LANGUAGES Swift) + # SwiftSyntax Dependency -include(FetchContent) find_package(SwiftSyntax) if(NOT SwiftSyntax_FOUND) + include(FetchContent) + # If building at desk, check out and link against the SwiftSyntax repo's targets FetchContent_Declare(SwiftSyntax GIT_REPOSITORY https://github.com/swiftlang/swift-syntax.git