Skip to content

Commit bab7ce3

Browse files
committed
build: make -O3 actually reach the optimized runtime
CMake appends CMAKE_CXX_FLAGS_<CONFIG> after CMAKE_CXX_FLAGS, and clang honours the last -O on the command line. AGP builds the release variant as RelWithDebInfo, whose default flags are "-O2 -g -DNDEBUG", so the -O3 set in CMAKE_CXX_FLAGS was overridden and every shipped runtime was compiled at -O2. Append -O3 to CMAKE_CXX_FLAGS_RELWITHDEBINFO inside the same branch so it comes last. The -O3 in CMAKE_CXX_FLAGS stays: CMAKE_CXX_FLAGS_DEBUG carries no -O, so a Debug-config build with -Poptimized still needs it.
1 parent e63df3d commit bab7ce3

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

test-app/runtime/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ include_directories(
6363
# must carry the release flags. Only a local Debug build keeps plain -g.
6464
if (OPTIMIZED_BUILD OR OPTIMIZED_WITH_INSPECTOR_BUILD OR NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
6565
set(CMAKE_CXX_FLAGS "${COMMON_CMAKE_ARGUMENTS} -O3 -fvisibility=hidden -ffunction-sections -fno-data-sections")
66+
# CMake appends CMAKE_CXX_FLAGS_<CONFIG> after CMAKE_CXX_FLAGS and clang honours the
67+
# last -O, so the -O3 above only survives in configs that carry no -O of their own
68+
# (Debug). AGP builds the release variant as RelWithDebInfo, whose default -O2 would
69+
# otherwise win.
70+
string(APPEND CMAKE_CXX_FLAGS_RELWITHDEBINFO " -O3")
6671
else ()
6772
set(CMAKE_CXX_FLAGS "${COMMON_CMAKE_ARGUMENTS} -g")
6873
endif ()

0 commit comments

Comments
 (0)