Skip to content

[macros] pass in additional CMAKE_HOST_Swift_FLAGS when building foun… #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions Sources/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
17 changes: 16 additions & 1 deletion Sources/FoundationMacros/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down