Skip to content

Use ${CMAKE_C_FLAGS_${BUILD_TYPE_UPPER}} to gain some performance - #7

Open
moi15moi wants to merge 1 commit into
peerless2012:masterfrom
moi15moi:Use-c-flags-dependend-build-type
Open

moi15moi wants to merge 1 commit into
peerless2012:masterfrom
moi15moi:Use-c-flags-dependend-build-type

Conversation

@moi15moi

Copy link
Copy Markdown
Contributor

When compiling with android studio, android studio call set CMAKE_TOOLCHAIN_FILE to ${ANDROID_NDK_ROOT}/build/cmake/android.toolchain.cmake

This file import android-legacy.toolchain.cmake and I realised that depending on the build type, it is setting different variant of CFLAGS, CXXFLAGS and LDFLAGS.

This is their values (CMAKE_CXX_FLAGS_XXX is the same as CMAKE_C_FLAGS_XXX):

CMAKE_C_FLAGS_RELEASE: -O3 -DNDEBUG
CMAKE_C_FLAGS_DEBUG: -fno-limit-debug-info
CMAKE_C_FLAGS_RELWITHDEBINFO: -O2 -g -DNDEBUG

CMAKE_SHARED_LINKER_FLAGS_RELEASE: -Wl,--gc-sections
CMAKE_SHARED_LINKER_FLAGS_DEBUG is empty
CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO: -Wl,--gc-sections

Unfortunatly, CMAKE_C_FLAGS always contains the "-g" flags, so even release build have symbol:

-g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security

PS: CMAKE_CXX_FLAGS is equal to CMAKE_C_FLAGS.

When compiling with android studio, android studio call set CMAKE_TOOLCHAIN_FILE to ${ANDROID_NDK_ROOT}/build/cmake/android.toolchain.cmake

This file import android-legacy.toolchain.cmake and I realised that depending on the build type, it is setting different variant of CFLAGS, CXXFLAGS and LDFLAGS.

This is their values (CMAKE_CXX_FLAGS_XXX is the same as CMAKE_C_FLAGS_XXX):
```
CMAKE_C_FLAGS_RELEASE: -O3 -DNDEBUG
CMAKE_C_FLAGS_DEBUG: -fno-limit-debug-info
CMAKE_C_FLAGS_RELWITHDEBINFO: -O2 -g -DNDEBUG

CMAKE_SHARED_LINKER_FLAGS_RELEASE: -Wl,--gc-sections
CMAKE_SHARED_LINKER_FLAGS_DEBUG is empty
CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO: -Wl,--gc-sections
```

Unfortunatly, CMAKE_C_FLAGS always contains the "-g" flags, so even release build have symbol:
```
-g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security
```
PS: CMAKE_CXX_FLAGS is equal to CMAKE_C_FLAGS.
@moi15moi

moi15moi commented Oct 2, 2026

Copy link
Copy Markdown
Contributor Author

By default, it seems that if CMAKE_BUILD_TYPE isn't specified, it is empty.
I should verify if android studio specify a CMAKE_BUILD_TYPE or not.
Currently, with the CI, we don't specify CMAKE_BUILD_TYPE, so it is empty so ${CMAKE_C_FLAGS_${BUILD_TYPE_UPPER}} doesn't inject anything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant