Skip to content

Commit 033c341

Browse files
committed
create macro
1 parent 910b7a8 commit 033c341

File tree

3 files changed

+50
-3
lines changed

3 files changed

+50
-3
lines changed

CMakeLists.txt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@
4444

4545
cmake_minimum_required(VERSION 3.24)
4646
project(executorch)
47+
48+
# MARK: - Start EXECUTORCH_H12025_BUILD_MIGRATION --------------------------------------------------
49+
50+
include(${PROJECT_SOURCE_DIR}/tools/cmake/common/preset.cmake)
51+
include(${PROJECT_SOURCE_DIR}/tools/cmake/preset/default.cmake)
52+
53+
# MARK: - End EXECUTORCH_H12025_BUILD_MIGRATION ----------------------------------------------------
54+
4755
include(tools/cmake/Utils.cmake)
4856
include(CMakeDependentOption)
4957

@@ -96,9 +104,6 @@ set(EXECUTORCH_PAL_DEFAULT
96104
"Which PAL default implementation to use: one of {posix, minimal}"
97105
)
98106

99-
option(EXECUTORCH_ENABLE_LOGGING "Build with ET_LOG_ENABLED"
100-
${_default_release_disabled_options}
101-
)
102107
if(NOT EXECUTORCH_ENABLE_LOGGING)
103108
# Avoid pulling in the logging strings, which can be large. Note that this
104109
# will set the compiler flag for all targets in this directory, and for all

tools/cmake/common/preset.cmake

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
# Enforce config names to always start with EXECUTORCH_, else raise an error.
8+
function(enforce_executorch_config_name NAME)
9+
if(NOT "${NAME}" MATCHES "^EXECUTORCH_")
10+
message(FATAL_ERROR "Config name '${NAME}' must start with EXECUTORCH_")
11+
endif()
12+
endfunction()
13+
14+
# Define an overridable config.
15+
# 1) If the config is already defined in the process, then store that in cache
16+
# 2) If the config is NOT set, then store the default value in cache
17+
macro(define_overridable_config NAME DESCRIPTION DEFAULT_VALUE)
18+
enforce_executorch_config_name(${NAME})
19+
20+
if(DEFINED ${NAME})
21+
set(${NAME} ${${NAME}} CACHE STRING ${DESCRIPTION} FORCE)
22+
else()
23+
set(${NAME} ${DEFAULT_VALUE} CACHE STRING ${DESCRIPTION})
24+
endif()
25+
endmacro()

tools/cmake/preset/default.cmake

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
if(CMAKE_BUILD_TYPE STREQUAL "Release")
8+
set(_is_build_type_release ON)
9+
set(_is_build_type_debug OFF)
10+
else()
11+
set(_is_build_type_release OFF)
12+
set(_is_build_type_debug ON)
13+
endif()
14+
15+
# MARK: - Definitions
16+
17+
define_overridable_config(EXECUTORCH_ENABLE_LOGGING "Build with ET_LOG_ENABLED" ${_is_build_type_debug})

0 commit comments

Comments
 (0)