diff --git a/CMakeLists.txt b/CMakeLists.txt index 2d3f8e5f907..03e36186c94 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -178,8 +178,6 @@ option(EXECUTORCH_BUILD_ARM_BAREMETAL "Build the Arm Baremetal flow for Cortex-M and Ethos-U" OFF ) -option(EXECUTORCH_BUILD_COREML "Build the Core ML backend" OFF) - option(EXECUTORCH_BUILD_KERNELS_CUSTOM "Build the custom kernels" OFF) option(EXECUTORCH_BUILD_KERNELS_CUSTOM_AOT "Build the custom ops lib for AOT" diff --git a/tools/cmake/Utils.cmake b/tools/cmake/Utils.cmake index 3155c3fc16e..edbd682c7e3 100644 --- a/tools/cmake/Utils.cmake +++ b/tools/cmake/Utils.cmake @@ -45,10 +45,6 @@ function(executorch_print_configuration_summary) message(STATUS " EXECUTORCH_BUILD_CADENCE : " "${EXECUTORCH_BUILD_CADENCE}" ) - message( - STATUS - " EXECUTORCH_BUILD_COREML : ${EXECUTORCH_BUILD_COREML}" - ) message( STATUS " EXECUTORCH_BUILD_CPUINFO : ${EXECUTORCH_BUILD_CPUINFO}" diff --git a/tools/cmake/common/preset.cmake b/tools/cmake/common/preset.cmake index 0affdf04bdd..8f886abab36 100644 --- a/tools/cmake/common/preset.cmake +++ b/tools/cmake/common/preset.cmake @@ -26,6 +26,7 @@ function(announce_configured_options NAME) endif() endfunction() + # Print the configured options. function(print_configured_options) get_property(_options GLOBAL PROPERTY _announce_configured_options) @@ -52,6 +53,7 @@ function(print_configured_options) message(STATUS "---------------------------") endfunction() + # Enforce option names to always start with EXECUTORCH. function(enforce_executorch_option_name NAME) if(NOT "${NAME}" MATCHES "^EXECUTORCH_") @@ -59,6 +61,7 @@ function(enforce_executorch_option_name NAME) endif() endfunction() + # Define an overridable option. # 1) If the option is already defined in the process, then store that in cache # 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) announce_configured_options(${NAME}) endmacro() + + +# Set an overridable option. +macro(set_overridable_option NAME VALUE) + # If the user has explitily set the option, do not override it. + if(DEFINED ${NAME}) + return() + endif() + + set(${NAME} ${VALUE} CACHE STRING "") +endmacro() diff --git a/tools/cmake/common/preset_test.py b/tools/cmake/common/preset_test.py index eb564eadace..1748062f166 100644 --- a/tools/cmake/common/preset_test.py +++ b/tools/cmake/common/preset_test.py @@ -223,3 +223,70 @@ def test_define_overridable_option_cli_override_with_set_override(self): self.run_cmake(cmake_args=["-DEXECUTORCH_TEST_MESSAGE='cli value'"]) # If an option is set through cmake, it should NOT be overridable from the CLI. self.assert_cmake_cache("EXECUTORCH_TEST_MESSAGE", "set value", "STRING") + + def test_set_overridable_option_before(self): + _cmake_lists_txt = """ + cmake_minimum_required(VERSION 3.24) + project(test_preset) + include(${PROJECT_SOURCE_DIR}/preset.cmake) + set_overridable_option(EXECUTORCH_TEST_MESSAGE "from set_overridable_option") + add_subdirectory(build) + """ + _build_cmake_lists_txt = """ + define_overridable_option(EXECUTORCH_TEST_MESSAGE "test message" STRING "move fast") + """ + self.create_workspace( + { + "CMakeLists.txt": _cmake_lists_txt, + "build": { + "CMakeLists.txt": _build_cmake_lists_txt, + }, + } + ) + self.run_cmake() + self.assert_cmake_cache( + "EXECUTORCH_TEST_MESSAGE", "from set_overridable_option", "STRING" + ) + + def test_set_overridable_option_after(self): + _cmake_lists_txt = """ + cmake_minimum_required(VERSION 3.24) + project(test_preset) + include(${PROJECT_SOURCE_DIR}/preset.cmake) + add_subdirectory(build) + set_overridable_option(EXECUTORCH_TEST_MESSAGE "from set_overridable_option") + """ + _build_cmake_lists_txt = """ + define_overridable_option(EXECUTORCH_TEST_MESSAGE "test message" STRING "move fast") + """ + self.create_workspace( + { + "CMakeLists.txt": _cmake_lists_txt, + "build": { + "CMakeLists.txt": _build_cmake_lists_txt, + }, + } + ) + self.run_cmake() + self.assert_cmake_cache("EXECUTORCH_TEST_MESSAGE", "move fast", "STRING") + + def test_set_overridable_option_with_cli_override(self): + _cmake_lists_txt = """ + cmake_minimum_required(VERSION 3.24) + project(test_preset) + include(${PROJECT_SOURCE_DIR}/preset.cmake) + add_subdirectory(build) + """ + _build_cmake_lists_txt = """ + define_overridable_option(EXECUTORCH_TEST_MESSAGE "test message" STRING "move fast") + """ + self.create_workspace( + { + "CMakeLists.txt": _cmake_lists_txt, + "build": { + "CMakeLists.txt": _build_cmake_lists_txt, + }, + } + ) + self.run_cmake(cmake_args=["-DEXECUTORCH_TEST_MESSAGE='from the cli'"]) + self.assert_cmake_cache("EXECUTORCH_TEST_MESSAGE", "from the cli", "STRING") diff --git a/tools/cmake/preset/default.cmake b/tools/cmake/preset/default.cmake index eafa8a7a937..5fbb47b1396 100644 --- a/tools/cmake/preset/default.cmake +++ b/tools/cmake/preset/default.cmake @@ -15,3 +15,4 @@ endif() # MARK: - Definitions define_overridable_option(EXECUTORCH_ENABLE_LOGGING "Build with ET_LOG_ENABLED" BOOL ${_is_build_type_debug}) +define_overridable_option(EXECUTORCH_BUILD_COREML "Build the Core ML backend" BOOL OFF) diff --git a/tools/cmake/preset/macos-arm64.cmake b/tools/cmake/preset/macos-arm64.cmake new file mode 100644 index 00000000000..84e60c50b92 --- /dev/null +++ b/tools/cmake/preset/macos-arm64.cmake @@ -0,0 +1,7 @@ +# Copyright (c) Meta Platforms, Inc. and affiliates. +# All rights reserved. +# +# This source code is licensed under the BSD-style license found in the +# LICENSE file in the root directory of this source tree. + +set_overridable_option(EXECUTORCH_BUILD_COREML ON)