Skip to content

Commit 1dc9fbc

Browse files
committed
✨ Simplify build presets by inferring system-specific settings
1 parent 2bb567f commit 1dc9fbc

File tree

4 files changed

+40
-27
lines changed

4 files changed

+40
-27
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: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,28 @@
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-
set(
11-
_compiler_flags
12-
"-ffile-prefix-map=${PROJECT_SOURCE_DIR}=/executorch"
13-
"-fdebug-prefix-map=${PROJECT_SOURCE_DIR}=/executorch"
14-
)
15-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_compiler_flags}")
16-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_compiler_flags}")
11+
set(
12+
_compiler_flags
13+
"-ffile-prefix-map=${PROJECT_SOURCE_DIR}=/executorch"
14+
"-fdebug-prefix-map=${PROJECT_SOURCE_DIR}=/executorch"
15+
)
16+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_compiler_flags}")
17+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_compiler_flags}")
18+
19+
# Swift requires Xcode
20+
set_overridable_option(EXECUTORCH_BUILD_EXTENSION_APPLE ON)
21+
else()
22+
message(WARNING "Building Apple targets without Xcode disables some features.")
23+
endif()
1724

1825
set_overridable_option(EXECUTORCH_BUILD_XNNPACK ON)
1926
set_overridable_option(EXECUTORCH_BUILD_COREML ON)
2027
set_overridable_option(EXECUTORCH_BUILD_MPS ON)
2128
set_overridable_option(EXECUTORCH_XNNPACK_SHARED_WORKSPACE ON)
22-
set_overridable_option(EXECUTORCH_BUILD_EXTENSION_APPLE ON)
2329
set_overridable_option(EXECUTORCH_BUILD_EXTENSION_DATA_LOADER ON)
2430
set_overridable_option(EXECUTORCH_BUILD_EXTENSION_MODULE ON)
2531
set_overridable_option(EXECUTORCH_BUILD_EXTENSION_TENSOR ON)

0 commit comments

Comments
 (0)