mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
Meta: Create a common Swift settings flow
This commit is contained in:
parent
7f8103da7a
commit
07d387af96
Notes:
github-actions[bot]
2024-07-31 00:39:13 +00:00
Author: https://github.com/ADKaster Commit: https://github.com/LadybirdBrowser/ladybird/commit/07d387af964 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/821
4 changed files with 122 additions and 15 deletions
|
@ -17,7 +17,6 @@ add_library(ladybird_impl STATIC
|
|||
)
|
||||
target_include_directories(ladybird_impl PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
|
||||
|
||||
target_compile_options(ladybird_impl PRIVATE "SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xcc -std=c++23 -cxx-interoperability-mode=default>")
|
||||
target_compile_options(ladybird_impl PUBLIC
|
||||
$<$<COMPILE_LANGUAGE:CXX>:-fobjc-arc>
|
||||
$<$<COMPILE_LANGUAGE:CXX>:-Wno-deprecated-anon-enum-enum-conversion> # Required for CGImageCreate
|
||||
|
@ -25,19 +24,6 @@ target_compile_options(ladybird_impl PUBLIC
|
|||
target_compile_features(ladybird_impl PUBLIC cxx_std_23)
|
||||
|
||||
if (ENABLE_SWIFT)
|
||||
enable_language(Swift)
|
||||
if (CMAKE_Swift_COMPILER_VERSION VERSION_LESS 6.0)
|
||||
message(FATAL_ERROR
|
||||
"Swift 6.0 or newer is required to parse AK C++ headers in C++23 mode"
|
||||
)
|
||||
endif()
|
||||
if (NOT CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
|
||||
message(FATAL_ERROR
|
||||
"Swift files must use Clang that was bundled with swiftc"
|
||||
)
|
||||
endif()
|
||||
include(Swift/GenerateSwiftHeader)
|
||||
|
||||
target_sources(ladybird_impl PRIVATE
|
||||
UI/TaskManager.swift
|
||||
UI/TaskManagerController.swift
|
||||
|
|
99
Meta/CMake/Swift/InitializeSwift.cmake
Normal file
99
Meta/CMake/Swift/InitializeSwift.cmake
Normal file
|
@ -0,0 +1,99 @@
|
|||
# This source file is part of the Swift open source project
|
||||
#
|
||||
# Copyright (c) 2023 Apple Inc. and the Swift project authors.
|
||||
# Licensed under Apache License v2.0 with Runtime Library Exception
|
||||
#
|
||||
# See https://swift.org/LICENSE.txt for license information
|
||||
|
||||
# Compute the name of the architecture directory on Windows from the CMake
|
||||
# system processor name.
|
||||
function(_swift_windows_arch_name output_variable_name target_arch)
|
||||
if(NOT WIN32)
|
||||
return()
|
||||
endif()
|
||||
|
||||
if("${target_arch}" STREQUAL "AMD64")
|
||||
set("${output_variable_name}" "x86_64" PARENT_SCOPE)
|
||||
elseif("${target_arch}" STREQUAL "ARM64")
|
||||
set("${output_variable_name}" "aarch64" PARENT_SCOPE)
|
||||
else()
|
||||
message(FATAL_ERROR "Unknown windows architecture: ${target_arch}")
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
# Compute flags and search paths
|
||||
# NOTE: This logic will eventually move to CMake
|
||||
function(_setup_swift_paths)
|
||||
# If we haven't set the swift library search paths, do that now
|
||||
if(NOT SWIFT_LIBRARY_SEARCH_PATHS OR NOT SWIFT_INCLUDE_PATHS)
|
||||
if(APPLE)
|
||||
set(SDK_FLAGS "-sdk" "${CMAKE_OSX_SYSROOT}")
|
||||
endif()
|
||||
|
||||
# Note: This does not handle cross-compiling correctly.
|
||||
# To handle it correctly, we would need to pass the target triple and
|
||||
# flags to this compiler invocation.
|
||||
execute_process(
|
||||
COMMAND ${CMAKE_Swift_COMPILER} ${SDK_FLAGS} -print-target-info
|
||||
OUTPUT_VARIABLE SWIFT_TARGET_INFO
|
||||
)
|
||||
|
||||
# extract search paths from swift driver response
|
||||
string(JSON SWIFT_TARGET_PATHS GET ${SWIFT_TARGET_INFO} "paths")
|
||||
|
||||
string(JSON SWIFT_TARGET_LIBRARY_PATHS GET ${SWIFT_TARGET_PATHS} "runtimeLibraryPaths")
|
||||
string(JSON SWIFT_TARGET_LIBRARY_PATHS_LENGTH LENGTH ${SWIFT_TARGET_LIBRARY_PATHS})
|
||||
math(EXPR SWIFT_TARGET_LIBRARY_PATHS_LENGTH "${SWIFT_TARGET_LIBRARY_PATHS_LENGTH} - 1 ")
|
||||
|
||||
string(JSON SWIFT_TARGET_LIBRARY_IMPORT_PATHS GET ${SWIFT_TARGET_PATHS} "runtimeLibraryImportPaths")
|
||||
string(JSON SWIFT_TARGET_LIBRARY_IMPORT_PATHS_LENGTH LENGTH ${SWIFT_TARGET_LIBRARY_IMPORT_PATHS})
|
||||
math(EXPR SWIFT_TARGET_LIBRARY_IMPORT_PATHS_LENGTH "${SWIFT_TARGET_LIBRARY_IMPORT_PATHS_LENGTH} - 1 ")
|
||||
|
||||
string(JSON SWIFT_SDK_IMPORT_PATH ERROR_VARIABLE errno GET ${SWIFT_TARGET_PATHS} "sdkPath")
|
||||
|
||||
foreach(JSON_ARG_IDX RANGE ${SWIFT_TARGET_LIBRARY_PATHS_LENGTH})
|
||||
string(JSON SWIFT_LIB GET ${SWIFT_TARGET_LIBRARY_PATHS} ${JSON_ARG_IDX})
|
||||
list(APPEND SWIFT_SEARCH_PATHS ${SWIFT_LIB})
|
||||
endforeach()
|
||||
|
||||
foreach(JSON_ARG_IDX RANGE ${SWIFT_TARGET_LIBRARY_IMPORT_PATHS_LENGTH})
|
||||
string(JSON SWIFT_LIB GET ${SWIFT_TARGET_LIBRARY_IMPORT_PATHS} ${JSON_ARG_IDX})
|
||||
list(APPEND SWIFT_SEARCH_PATHS ${SWIFT_LIB})
|
||||
endforeach()
|
||||
|
||||
if(SWIFT_SDK_IMPORT_PATH)
|
||||
list(APPEND SWIFT_SEARCH_PATHS ${SWIFT_SDK_IMPORT_PATH})
|
||||
endif()
|
||||
|
||||
# Save the swift library search paths
|
||||
set(SWIFT_LIBRARY_SEARCH_PATHS ${SWIFT_SEARCH_PATHS} CACHE FILEPATH "Swift driver search paths")
|
||||
|
||||
string(JSON SWIFT_RUNTIME_RESOURCE_PATH GET ${SWIFT_TARGET_PATHS} "runtimeResourcePath")
|
||||
set(SWIFT_TOOLCHAIN_INCLUDE_DIR "${SWIFT_RUNTIME_RESOURCE_PATH}/../../include")
|
||||
cmake_path(ABSOLUTE_PATH SWIFT_TOOLCHAIN_INCLUDE_DIR NORMALIZE)
|
||||
if (NOT IS_DIRECTORY "${SWIFT_TOOLCHAIN_INCLUDE_DIR}")
|
||||
message(WARNING "Expected toolchain include dir ${SWIFT_TOOLCHAIN_INCLUDE_DIR} does not exist")
|
||||
endif()
|
||||
set(SWIFT_INCLUDE_PATHS ${SWIFT_TOOLCHAIN_INCLUDE_DIR} CACHE FILEPATH "Swift interop include paths")
|
||||
endif()
|
||||
|
||||
link_directories(${SWIFT_LIBRARY_SEARCH_PATHS})
|
||||
include_directories(${SWIFT_INCLUDE_PATHS})
|
||||
|
||||
if(WIN32)
|
||||
_swift_windows_arch_name(SWIFT_WIN_ARCH_DIR "${CMAKE_SYSTEM_PROCESSOR}")
|
||||
set(SWIFT_SWIFTRT_FILE "$ENV{SDKROOT}/usr/lib/swift/windows/${SWIFT_WIN_ARCH_DIR}/swiftrt.obj")
|
||||
add_link_options("$<$<LINK_LANGUAGE:Swift>:${SWIFT_SWIFTRT_FILE}>")
|
||||
elseif(NOT APPLE)
|
||||
find_file(SWIFT_SWIFTRT_FILE
|
||||
swiftrt.o
|
||||
PATHS ${SWIFT_LIBRARY_SEARCH_PATHS}
|
||||
NO_CACHE
|
||||
REQUIRED
|
||||
NO_DEFAULT_PATH)
|
||||
add_link_options("$<$<LINK_LANGUAGE:Swift>:${SWIFT_SWIFTRT_FILE}>")
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
_setup_swift_paths()
|
||||
|
19
Meta/CMake/Swift/swift-settings.cmake
Normal file
19
Meta/CMake/Swift/swift-settings.cmake
Normal file
|
@ -0,0 +1,19 @@
|
|||
enable_language(Swift)
|
||||
|
||||
if (CMAKE_Swift_COMPILER_VERSION VERSION_LESS 6.0)
|
||||
message(FATAL_ERROR
|
||||
"Swift 6.0 or newer is required to parse C++ headers in C++23 mode"
|
||||
)
|
||||
endif()
|
||||
|
||||
# FIXME: How to verify this on non-Apple?
|
||||
if (APPLE AND NOT CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
|
||||
message(FATAL_ERROR
|
||||
"Swift files must use Clang that was bundled with swiftc"
|
||||
)
|
||||
endif()
|
||||
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/InitializeSwift.cmake)
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/GenerateSwiftHeader.cmake)
|
||||
|
||||
add_compile_options("SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xcc -std=c++23 -cxx-interoperability-mode=default>")
|
|
@ -34,6 +34,9 @@ serenity_option(ENABLE_CLANG_PLUGINS OFF CACHE BOOL "Enable building with the Cl
|
|||
serenity_option(ENABLE_CLANG_PLUGINS_INVALID_FUNCTION_MEMBERS OFF CACHE BOOL "Enable detecting invalid function types as members of GC-allocated objects")
|
||||
|
||||
serenity_option(ENABLE_GUI_TARGETS ON CACHE BOOL "Enable building GUI targets")
|
||||
serenity_option(ENABLE_INSTALL_HEADERS ON CACHE BOOL "Enable installing headers")
|
||||
serenity_option(ENABLE_SWIFT OFF CACHE BOOL "Enable building Swift files")
|
||||
|
||||
serenity_option(ENABLE_INSTALL_HEADERS ON CACHE BOOL "Enable installing headers")
|
||||
if (ENABLE_SWIFT)
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/Swift/swift-settings.cmake)
|
||||
endif()
|
||||
|
|
Loading…
Reference in a new issue