From ef4e5c40b8c795cb87f1c3b6a549ea9f05ed6b8a Mon Sep 17 00:00:00 2001 From: jathu Date: Wed, 7 May 2025 19:08:05 -0700 Subject: [PATCH] announce option --- CMakeLists.txt | 3 ++ tools/cmake/Utils.cmake | 4 --- tools/cmake/common/preset.cmake | 50 +++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 45993721a66..2d3f8e5f907 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,6 +50,9 @@ project(executorch) include(${PROJECT_SOURCE_DIR}/tools/cmake/common/preset.cmake) include(${PROJECT_SOURCE_DIR}/tools/cmake/preset/default.cmake) +# Print all the configs that were called with announce_configured_options. +print_configured_options() + # MARK: - End EXECUTORCH_H12025_BUILD_MIGRATION ---------------------------------------------------- include(tools/cmake/Utils.cmake) diff --git a/tools/cmake/Utils.cmake b/tools/cmake/Utils.cmake index 0a09f51fd28..3155c3fc16e 100644 --- a/tools/cmake/Utils.cmake +++ b/tools/cmake/Utils.cmake @@ -30,10 +30,6 @@ function(executorch_print_configuration_summary) message(STATUS " BUCK2 : ${BUCK2}") message(STATUS " PYTHON_EXECUTABLE : ${PYTHON_EXECUTABLE}") message(STATUS " FLATC_EXECUTABLE : ${FLATC_EXECUTABLE}") - message( - STATUS - " EXECUTORCH_ENABLE_LOGGING : ${EXECUTORCH_ENABLE_LOGGING}" - ) message(STATUS " EXECUTORCH_ENABLE_PROGRAM_VERIFICATION : " "${EXECUTORCH_ENABLE_PROGRAM_VERIFICATION}" ) diff --git a/tools/cmake/common/preset.cmake b/tools/cmake/common/preset.cmake index 0fde24bae6a..0affdf04bdd 100644 --- a/tools/cmake/common/preset.cmake +++ b/tools/cmake/common/preset.cmake @@ -4,6 +4,54 @@ # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. +# Announce the name and value of a cmake variable in the summary of the build. +function(announce_configured_options NAME) + get_property(_options GLOBAL PROPERTY _announce_configured_options) + if(NOT _options) + set_property(GLOBAL PROPERTY _announce_configured_options) + get_property(_options GLOBAL PROPERTY _announce_configured_options) + endif() + + set(option_exists FALSE) + foreach(_option IN LISTS _options) + if(_option STREQUAL "${NAME}") + set(option_exists TRUE) + break() + endif() + endforeach() + + if(NOT option_exists) + set(_options ${_options} "${NAME}") + set_property(GLOBAL PROPERTY _announce_configured_options "${_options}") + endif() +endfunction() + +# Print the configured options. +function(print_configured_options) + get_property(_options GLOBAL PROPERTY _announce_configured_options) + + set(_longest_name_length 0) + foreach(_option IN LISTS _options) + string(LENGTH "${_option}" length) + if(length GREATER _longest_name_length) + set(_longest_name_length ${length}) + endif() + endforeach() + + message(STATUS "--- Configurated Options ---\n") + foreach(_option IN LISTS _options) + string(LENGTH "${_option}" _option_length) + math(EXPR num_spaces "${_longest_name_length} - ${_option_length}") + set(padding "") + while(num_spaces GREATER 0) + set(padding "${padding} ") + math(EXPR num_spaces "${num_spaces} - 1") + endwhile() + message(STATUS "${_option}${padding} : ${${_option}}") + endforeach() + message(STATUS "---------------------------") +endfunction() + # Enforce option names to always start with EXECUTORCH. function(enforce_executorch_option_name NAME) if(NOT "${NAME}" MATCHES "^EXECUTORCH_") @@ -26,4 +74,6 @@ macro(define_overridable_option NAME DESCRIPTION VALUE_TYPE DEFAULT_VALUE) else() set(${NAME} ${DEFAULT_VALUE} CACHE ${VALUE_TYPE} ${DESCRIPTION}) endif() + + announce_configured_options(${NAME}) endmacro()