Skip to content

Commit 380c4f1

Browse files
authored
Allow options to be set by presets (#10767)
### Summary In this diff we create a helper that will allow presets to set options. Again this is mostly a helper to check if the option has been defined already, then no-oping. To test it, I also create the first preset `macos-arm64`. I will test it in upcoming diffs. ### Test plan pytest for now, manual test in future diffs cc @larryliu0820
1 parent a37b369 commit 380c4f1

File tree

6 files changed

+89
-6
lines changed

6 files changed

+89
-6
lines changed

CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,6 @@ option(EXECUTORCH_BUILD_ARM_BAREMETAL
178178
"Build the Arm Baremetal flow for Cortex-M and Ethos-U" OFF
179179
)
180180

181-
option(EXECUTORCH_BUILD_COREML "Build the Core ML backend" OFF)
182-
183181
option(EXECUTORCH_BUILD_KERNELS_CUSTOM "Build the custom kernels" OFF)
184182

185183
option(EXECUTORCH_BUILD_KERNELS_CUSTOM_AOT "Build the custom ops lib for AOT"

tools/cmake/Utils.cmake

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@ function(executorch_print_configuration_summary)
4545
message(STATUS " EXECUTORCH_BUILD_CADENCE : "
4646
"${EXECUTORCH_BUILD_CADENCE}"
4747
)
48-
message(
49-
STATUS
50-
" EXECUTORCH_BUILD_COREML : ${EXECUTORCH_BUILD_COREML}"
51-
)
5248
message(
5349
STATUS
5450
" EXECUTORCH_BUILD_CPUINFO : ${EXECUTORCH_BUILD_CPUINFO}"

tools/cmake/common/preset.cmake

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ function(announce_configured_options NAME)
2626
endif()
2727
endfunction()
2828

29+
2930
# Print the configured options.
3031
function(print_configured_options)
3132
get_property(_options GLOBAL PROPERTY _announce_configured_options)
@@ -52,13 +53,15 @@ function(print_configured_options)
5253
message(STATUS "---------------------------")
5354
endfunction()
5455

56+
5557
# Enforce option names to always start with EXECUTORCH.
5658
function(enforce_executorch_option_name NAME)
5759
if(NOT "${NAME}" MATCHES "^EXECUTORCH_")
5860
message(FATAL_ERROR "Option name '${NAME}' must start with EXECUTORCH_")
5961
endif()
6062
endfunction()
6163

64+
6265
# Define an overridable option.
6366
# 1) If the option is already defined in the process, then store that in cache
6467
# 2) If the option is NOT set, then store the default value in cache
@@ -77,3 +80,14 @@ macro(define_overridable_option NAME DESCRIPTION VALUE_TYPE DEFAULT_VALUE)
7780

7881
announce_configured_options(${NAME})
7982
endmacro()
83+
84+
85+
# Set an overridable option.
86+
macro(set_overridable_option NAME VALUE)
87+
# If the user has explitily set the option, do not override it.
88+
if(DEFINED ${NAME})
89+
return()
90+
endif()
91+
92+
set(${NAME} ${VALUE} CACHE STRING "")
93+
endmacro()

tools/cmake/common/preset_test.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,3 +223,70 @@ def test_define_overridable_option_cli_override_with_set_override(self):
223223
self.run_cmake(cmake_args=["-DEXECUTORCH_TEST_MESSAGE='cli value'"])
224224
# If an option is set through cmake, it should NOT be overridable from the CLI.
225225
self.assert_cmake_cache("EXECUTORCH_TEST_MESSAGE", "set value", "STRING")
226+
227+
def test_set_overridable_option_before(self):
228+
_cmake_lists_txt = """
229+
cmake_minimum_required(VERSION 3.24)
230+
project(test_preset)
231+
include(${PROJECT_SOURCE_DIR}/preset.cmake)
232+
set_overridable_option(EXECUTORCH_TEST_MESSAGE "from set_overridable_option")
233+
add_subdirectory(build)
234+
"""
235+
_build_cmake_lists_txt = """
236+
define_overridable_option(EXECUTORCH_TEST_MESSAGE "test message" STRING "move fast")
237+
"""
238+
self.create_workspace(
239+
{
240+
"CMakeLists.txt": _cmake_lists_txt,
241+
"build": {
242+
"CMakeLists.txt": _build_cmake_lists_txt,
243+
},
244+
}
245+
)
246+
self.run_cmake()
247+
self.assert_cmake_cache(
248+
"EXECUTORCH_TEST_MESSAGE", "from set_overridable_option", "STRING"
249+
)
250+
251+
def test_set_overridable_option_after(self):
252+
_cmake_lists_txt = """
253+
cmake_minimum_required(VERSION 3.24)
254+
project(test_preset)
255+
include(${PROJECT_SOURCE_DIR}/preset.cmake)
256+
add_subdirectory(build)
257+
set_overridable_option(EXECUTORCH_TEST_MESSAGE "from set_overridable_option")
258+
"""
259+
_build_cmake_lists_txt = """
260+
define_overridable_option(EXECUTORCH_TEST_MESSAGE "test message" STRING "move fast")
261+
"""
262+
self.create_workspace(
263+
{
264+
"CMakeLists.txt": _cmake_lists_txt,
265+
"build": {
266+
"CMakeLists.txt": _build_cmake_lists_txt,
267+
},
268+
}
269+
)
270+
self.run_cmake()
271+
self.assert_cmake_cache("EXECUTORCH_TEST_MESSAGE", "move fast", "STRING")
272+
273+
def test_set_overridable_option_with_cli_override(self):
274+
_cmake_lists_txt = """
275+
cmake_minimum_required(VERSION 3.24)
276+
project(test_preset)
277+
include(${PROJECT_SOURCE_DIR}/preset.cmake)
278+
add_subdirectory(build)
279+
"""
280+
_build_cmake_lists_txt = """
281+
define_overridable_option(EXECUTORCH_TEST_MESSAGE "test message" STRING "move fast")
282+
"""
283+
self.create_workspace(
284+
{
285+
"CMakeLists.txt": _cmake_lists_txt,
286+
"build": {
287+
"CMakeLists.txt": _build_cmake_lists_txt,
288+
},
289+
}
290+
)
291+
self.run_cmake(cmake_args=["-DEXECUTORCH_TEST_MESSAGE='from the cli'"])
292+
self.assert_cmake_cache("EXECUTORCH_TEST_MESSAGE", "from the cli", "STRING")

tools/cmake/preset/default.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ endif()
1515
# MARK: - Definitions
1616

1717
define_overridable_option(EXECUTORCH_ENABLE_LOGGING "Build with ET_LOG_ENABLED" BOOL ${_is_build_type_debug})
18+
define_overridable_option(EXECUTORCH_BUILD_COREML "Build the Core ML backend" BOOL OFF)

tools/cmake/preset/macos-arm64.cmake

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
set_overridable_option(EXECUTORCH_BUILD_COREML ON)

0 commit comments

Comments
 (0)