Skip to content

Commit d574358

Browse files
committed
✨ Simplify build presets by inferring system-specific settings
1 parent 120eb85 commit d574358

File tree

4 files changed

+36
-23
lines changed

4 files changed

+36
-23
lines changed

CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ if(NOT CMAKE_SYSTEM_PROCESSOR)
6565
endif()
6666
announce_configured_options(CMAKE_SYSTEM_PROCESSOR)
6767

68+
if(NOT CMAKE_SYSTEM_NAME)
69+
set(CMAKE_SYSTEM_NAME ${CMAKE_HOST_SYSTEM_NAME})
70+
endif()
71+
announce_configured_options(CMAKE_SYSTEM_NAME)
72+
6873
if(NOT CMAKE_BUILD_TYPE)
6974
set(CMAKE_BUILD_TYPE Debug)
7075
endif()
@@ -83,7 +88,7 @@ announce_configured_options(BUCK2)
8388
announce_configured_options(CMAKE_CXX_COMPILER_ID)
8489
announce_configured_options(CMAKE_TOOLCHAIN_FILE)
8590

86-
load_build_preset()
91+
load_executorch_build_preset_file()
8792
include(${PROJECT_SOURCE_DIR}/tools/cmake/preset/default.cmake)
8893

8994
# Print all the configs that were called with announce_configured_options.

CMakePresets.json

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
"generator": "Xcode",
1414
"cacheVariables": {
1515
"CMAKE_TOOLCHAIN_FILE": "${sourceDir}/third-party/ios-cmake/ios.toolchain.cmake",
16-
"EXECUTORCH_BUILD_PRESET_FILE": "${sourceDir}/tools/cmake/preset/macos.cmake",
1716
"PLATFORM": "MAC_ARM64",
1817
"DEPLOYMENT_TARGET": "12.0"
1918
},
@@ -30,7 +29,6 @@
3029
"generator": "Xcode",
3130
"cacheVariables": {
3231
"CMAKE_TOOLCHAIN_FILE": "${sourceDir}/third-party/ios-cmake/ios.toolchain.cmake",
33-
"EXECUTORCH_BUILD_PRESET_FILE": "${sourceDir}/tools/cmake/preset/ios.cmake",
3432
"PLATFORM": "OS64",
3533
"DEPLOYMENT_TARGET": "17.0"
3634
},
@@ -47,7 +45,6 @@
4745
"generator": "Xcode",
4846
"cacheVariables": {
4947
"CMAKE_TOOLCHAIN_FILE": "${sourceDir}/third-party/ios-cmake/ios.toolchain.cmake",
50-
"EXECUTORCH_BUILD_PRESET_FILE": "${sourceDir}/tools/cmake/preset/ios.cmake",
5148
"PLATFORM": "SIMULATORARM64",
5249
"DEPLOYMENT_TARGET": "17.0"
5350
},
@@ -62,8 +59,7 @@
6259
"displayName": "Build everything buildable on Linux",
6360
"inherits": ["common"],
6461
"cacheVariables": {
65-
"CMAKE_SYSTEM_NAME": "Linux",
66-
"EXECUTORCH_BUILD_PRESET_FILE": "${sourceDir}/tools/cmake/preset/linux.cmake"
62+
"CMAKE_SYSTEM_NAME": "Linux"
6763
},
6864
"condition": {
6965
"lhs": "${hostSystemName}",
@@ -88,21 +84,15 @@
8884
{
8985
"name": "llm",
9086
"displayName": "Build LLM libraries",
91-
"inherits": [
92-
"common"
93-
],
87+
"inherits": ["common"],
9488
"cacheVariables": {
9589
"EXECUTORCH_BUILD_PRESET_FILE": "${sourceDir}/tools/cmake/preset/llm.cmake",
9690
"CMAKE_OSX_DEPLOYMENT_TARGET": "12.0"
9791
},
9892
"condition": {
9993
"type": "inList",
10094
"string": "${hostSystemName}",
101-
"list": [
102-
"Darwin",
103-
"Linux",
104-
"Windows"
105-
]
95+
"list": ["Darwin", "Linux", "Windows"]
10696
}
10797
}
10898
]

tools/cmake/common/preset.cmake

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,27 @@ macro(set_overridable_option NAME VALUE)
9494
endif()
9595
endmacro()
9696

97+
9798
# Detemine the build preset and load it.
98-
macro(load_build_preset)
99+
macro(load_executorch_build_preset_file)
100+
# If EXECUTORCH_BUILD_PRESET_FILE is not set, then try to infer it.
101+
if(NOT DEFINED EXECUTORCH_BUILD_PRESET_FILE)
102+
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
103+
set(EXECUTORCH_BUILD_PRESET_FILE "${PROJECT_SOURCE_DIR}/tools/cmake/preset/macos.cmake")
104+
elseif(CMAKE_SYSTEM_NAME STREQUAL "iOS")
105+
set(EXECUTORCH_BUILD_PRESET_FILE "${PROJECT_SOURCE_DIR}/tools/cmake/preset/ios.cmake")
106+
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
107+
set(EXECUTORCH_BUILD_PRESET_FILE "${PROJECT_SOURCE_DIR}/tools/cmake/preset/linux.cmake")
108+
else()
109+
message(WARNING "Unknown CMAKE_SYSTEM_NAME, unable to determine EXECUTORCH_BUILD_PRESET_FILE")
110+
endif()
111+
endif()
112+
99113
if(DEFINED EXECUTORCH_BUILD_PRESET_FILE)
100114
announce_configured_options(EXECUTORCH_BUILD_PRESET_FILE)
101115
message(STATUS "Loading build preset: ${EXECUTORCH_BUILD_PRESET_FILE}")
102116
include(${EXECUTORCH_BUILD_PRESET_FILE})
103117
endif()
104-
# For now, just continue if the preset file is not set. In the future, we will
105-
# try to determine a preset file.
106118
endmacro()
107119

108120

tools/cmake/preset/apple_common.cmake

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,24 @@
44
# This source code is licensed under the BSD-style license found in the
55
# LICENSE file in the root directory of this source tree.
66

7-
set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD "c++${CMAKE_CXX_STANDARD}")
8-
set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++")
7+
if(CMAKE_GENERATOR STREQUAL "Xcode")
8+
set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD "c++${CMAKE_CXX_STANDARD}")
9+
set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++")
910

10-
# Clean up the paths LLDB sees in DWARF.
11-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -gno-record-gcc-switches")
12-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -gno-record-gcc-switches")
11+
# Clean up the paths LLDB sees in DWARF.
12+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -gno-record-gcc-switches")
13+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -gno-record-gcc-switches")
14+
15+
# Swift requires Xcode
16+
set_overridable_option(EXECUTORCH_BUILD_EXTENSION_APPLE ON)
17+
else()
18+
message(WARNING "Building Apple targets without Xcode disables some features.")
19+
endif()
1320

1421
set_overridable_option(EXECUTORCH_BUILD_XNNPACK ON)
1522
set_overridable_option(EXECUTORCH_BUILD_COREML ON)
1623
set_overridable_option(EXECUTORCH_BUILD_MPS ON)
1724
set_overridable_option(EXECUTORCH_XNNPACK_SHARED_WORKSPACE ON)
18-
set_overridable_option(EXECUTORCH_BUILD_EXTENSION_APPLE ON)
1925
set_overridable_option(EXECUTORCH_BUILD_EXTENSION_DATA_LOADER ON)
2026
set_overridable_option(EXECUTORCH_BUILD_EXTENSION_MODULE ON)
2127
set_overridable_option(EXECUTORCH_BUILD_EXTENSION_FLAT_TENSOR ON)

0 commit comments

Comments
 (0)