Skip to content

Commit 8f81e1d

Browse files
authored
Merge pull request swiftlang#77507 from etcwilde/ewilde/stdlib-rebuild-private-extension-points
[cmake] Provide private extension points to the build
2 parents 24cec30 + 2df8a18 commit 8f81e1d

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

Runtimes/Core/CMakeLists.txt

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131

3232
cmake_minimum_required(VERSION 3.26...3.29)
3333

34-
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules")
34+
set(SwiftCore_CMAKE_MODULES_DIR "${CMAKE_SOURCE_DIR}/cmake/modules")
35+
list(APPEND CMAKE_MODULE_PATH ${SwiftCore_CMAKE_MODULES_DIR})
3536
include(CMakeWorkarounds)
3637
project(SwiftCore LANGUAGES C CXX Swift VERSION 6.1)
3738

@@ -47,6 +48,13 @@ set(SwiftCore_SWIFTC_SOURCE_DIR
4748
"${PROJECT_SOURCE_DIR}/../../"
4849
CACHE FILEPATH "Path to the root source directory of the Swift compiler")
4950

51+
# Hook point for vendor-specific extensions to the build system
52+
# Allowed extension points:
53+
# - DefaultSettings.cmake
54+
# - Settings.cmake
55+
set(SwiftCore_VENDOR_MODULE_DIR "${SwiftCore_CMAKE_MODULES_DIR}/vendor"
56+
CACHE FILEPATH "Location for private build system extension")
57+
5058
include(GNUInstallDirs)
5159
include(AvailabilityMacros)
5260
include(CompilerSettings)
@@ -55,6 +63,8 @@ include(EmitSwiftInterface)
5563
include(PlatformInfo)
5664
include(gyb)
5765

66+
include("${SwiftCore_VENDOR_MODULE_DIR}/Settings.cmake" OPTIONAL)
67+
5868
defaulted_option(SwiftCore_ENABLE_LIBRARY_EVOLUTION "Generate ABI resilient runtime libraries")
5969

6070
defaulted_option(SwiftCore_ENABLE_CRASH_REPORTER_CLIENT "Enable Apple CrashReporter integration")
@@ -66,12 +76,12 @@ defaulted_option(SwiftCore_ENABLE_COMMANDLINE_SUPPORT "Enable command line argum
6676
defaulted_option(SwiftCore_ENABLE_RUNTIME_FUNCTION_COUNTERS "Enable runtime function counter support")
6777

6878
defaulted_option(SwiftCore_ENABLE_BACKTRACING "Enable backtracing runtime support")
69-
set(SwiftCore_BACKTRACER_PATH ${SwiftCore_BACKTRACER_PATH_default} CACHE STRING "Set a fixed path to the Swift backtracer")
79+
defaulted_set(SwiftCore_BACKTRACER_PATH STRING "Set a fixed path to the Swift backtracer")
7080

7181
option(SwiftCore_ENABLE_CLOBBER_FREED_OBJECTS "" OFF)
7282
option(SwiftCore_ENABLE_RUNTIME_LEAK_CHECKER "" OFF)
7383

74-
set(SwiftCore_OBJECT_FORMAT "${SwiftCore_OBJECT_FORMAT_default}" CACHE STRING "Object format")
84+
defaulted_set(SwiftCore_OBJECT_FORMAT STRING "Object format: ELF COFF")
7585

7686
add_compile_definitions(
7787
$<$<BOOL:${SwiftCore_ENABLE_OBJC_INTEROP}>:-DSWIFT_OBJC_INTEROP>
@@ -82,7 +92,7 @@ add_compile_definitions(
8292
$<$<COMPILE_LANGUAGE:C,CXX>:-DSWIFT_RUNTIME_ENABLE_LEAK_CHECKER=$<BOOL:${SwiftCore_ENABLE_RUNTIME_LEAK_CHECKER}>>
8393
$<$<COMPILE_LANGUAGE:C,CXX>:-DSWIFT_RUNTIME_CLOBBER_FREED_OBJECTS=$<BOOL:${SwiftCore_ENABLE_CLOBBER_FREED_OBJECTS}>>)
8494

85-
add_compile_options( $<$<AND:$<COMPILE_LANGUAGE:Swift>,$<BOOL:${SwiftCore_ENABLE_LIBRARY_EVOLUTION}>>:-enable-library-evolution>)
95+
add_compile_options($<$<AND:$<COMPILE_LANGUAGE:Swift>,$<BOOL:${SwiftCore_ENABLE_LIBRARY_EVOLUTION}>>:-enable-library-evolution>)
8696

8797
include_directories(include)
8898

Runtimes/Core/cmake/modules/DefaultSettings.cmake

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
# that configuring a build for a given platform is likely to build
33
# out-of-the-box without customization. This does not mean that it is the only
44
# way that will work, or that it represents a shipping configuration.
5+
# User-specified configurations should be done through cache files or by setting
6+
# the variable with `-DSwiftCore_*` on the commandline.
57

68
set(SwiftCore_ENABLE_BACKTRACING_default OFF) # TODO: enable this by default
79
set(SwiftCore_ENABLE_COMMANDLINE_SUPPORT_default OFF) # TODO: enable this by default
@@ -10,13 +12,25 @@ set(SwiftCore_ENABLE_TYPE_PRINTING_default ON)
1012

1113
set(SwiftCore_BACKTRACER_PATH_default "")
1214

15+
# Provide a boolean option that a user can optionally enable.
16+
# Variables are defaulted based on the value of `<variable>_default`.
17+
# If no such default variable exists, the option is defaults to `OFF`.
1318
macro(defaulted_option variable helptext)
1419
if(NOT DEFINED ${variable}_default)
1520
set(${variable}_default OFF)
1621
endif()
1722
option(${variable} ${helptext} ${${variable}_default})
1823
endmacro()
1924

25+
# Create a defaulted cache entry
26+
# Entries are defaulted on the value of `<variable>_default`.
27+
# If no such default variable exists, the variable is not created.
28+
macro(defaulted_set variable type helptext)
29+
if(DEFINED ${variable}_default)
30+
set(${variable} ${variable}_default CACHE ${type} ${helptext})
31+
endif()
32+
endmacro()
33+
2034
if(APPLE)
2135
set(SwiftCore_ENABLE_LIBRARY_EVOLUTION_default ON)
2236
set(SwiftCore_ENABLE_CRASH_REPORTER_CLIENT_default ON)
@@ -29,3 +43,5 @@ elseif(LINUX OR ANDROID OR BSD)
2943
elseif(WIN32)
3044
set(SwiftCore_OBJECT_FORMAT_default "coff")
3145
endif()
46+
47+
include("${SwiftCore_VENDOR_MODULE_DIR}/DefaultSettings.cmake" OPTIONAL)

0 commit comments

Comments
 (0)