diff --git a/CMakeLists.txt b/CMakeLists.txt index 523d679516b..4b0aba3a9de 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -120,8 +120,7 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -s") endif() -option(OPTIMIZE_SIZE "Build executorch runtime optimizing for binary size" OFF) -if(OPTIMIZE_SIZE) +if(EXECUTORCH_OPTIMIZE_SIZE) # -Os: Optimize for size. set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Os") else() diff --git a/docs/source/using-executorch-building-from-source.md b/docs/source/using-executorch-building-from-source.md index e2657e69b55..76237971e2d 100644 --- a/docs/source/using-executorch-building-from-source.md +++ b/docs/source/using-executorch-building-from-source.md @@ -164,7 +164,7 @@ The release build offers optimizations intended to improve performance and reduc To further optimize the release build for size, use both: ```bash -DCMAKE_BUILD_TYPE=Release \ --DOPTIMIZE_SIZE=ON +-DEXECUTORCH_OPTIMIZE_SIZE=ON ``` See [CMakeLists.txt](https://github.com/pytorch/executorch/blob/main/CMakeLists.txt) diff --git a/test/build_optimized_size_test.sh b/test/build_optimized_size_test.sh index 181c2ce617d..d7b055559f0 100644 --- a/test/build_optimized_size_test.sh +++ b/test/build_optimized_size_test.sh @@ -27,7 +27,7 @@ cmake_install_executorch_lib() { -DCMAKE_BUILD_TYPE=MinSizeRel \ -DEXECUTORCH_BUILD_EXECUTOR_RUNNER=OFF \ -DEXECUTORCH_BUILD_KERNELS_OPTIMIZED=ON \ - -DOPTIMIZE_SIZE=ON \ + -DEXECUTORCH_OPTIMIZE_SIZE=ON \ -DPYTHON_EXECUTABLE="$PYTHON_EXECUTABLE" \ -Bcmake-out . cmake --build cmake-out -j9 --target install --config MinSizeRel diff --git a/test/build_size_test.sh b/test/build_size_test.sh index cae5a015280..d020ab58c95 100644 --- a/test/build_size_test.sh +++ b/test/build_size_test.sh @@ -28,7 +28,7 @@ cmake_install_executorch_lib() { -DCMAKE_INSTALL_PREFIX=cmake-out \ -DCMAKE_BUILD_TYPE=Release \ -DEXECUTORCH_BUILD_EXECUTOR_RUNNER=OFF \ - -DOPTIMIZE_SIZE=ON \ + -DEXECUTORCH_OPTIMIZE_SIZE=ON \ -DPYTHON_EXECUTABLE="$PYTHON_EXECUTABLE" \ ${EXTRA_BUILD_ARGS} \ -Bcmake-out . diff --git a/tools/cmake/preset/default.cmake b/tools/cmake/preset/default.cmake index 900d1320287..8020c20667f 100644 --- a/tools/cmake/preset/default.cmake +++ b/tools/cmake/preset/default.cmake @@ -54,6 +54,11 @@ define_overridable_option( "Build with ET_EVENT_TRACER_ENABLED" BOOL OFF ) +define_overridable_option( + EXECUTORCH_OPTIMIZE_SIZE + "Build executorch runtime optimizing for binary size" + BOOL OFF +) # MARK: - Validations # At this point all the options should be configured with their final value.