Reputation: 2121
To demonstrate this issue, I made a minimum CMakeLists.txt:
cmake_minimum_required(VERSION 3.12)
project(FlagsTest)
add_executable(myapp myapp.cpp)
I configure this cmake project with toolchain file inside Android NDK. Ninja generator is used, and cmake cached variable ANDROID_ABI
is set to armeabi-v7a
. The versions of software and toolchain are:
C:/Users/my_name/AppData/Local/Android/Sdk/ndk/20.0.5594570/build/cmake/android.toolchain.cmake
The whole stuff successfully configured and generated. However, cmake cache variables CMAKE_CXX_FLAGS_DEBUG
, CMAKE_CXX_FLAGS_RELEASE
, CMAKE_C_FLAGS_DEBUG
and CMAKE_C_FLAGS_RELEASE
are all blank. This caused in no debug symbol in debug build, and no optimization in release build, which bothered us for a lot.
At current, I made a workaround by manually specify these variables from cmake command line. But as these variables should be automatically set by cmake, I'm wondering whether it is a bug in cmake, or a bug in Android SDK.
Upvotes: 0
Views: 547
Reputation: 2121
This is caused by incorrect configuration in the ndk toolchain file. It set empty initial value for CMAKE_CXX_FLAGS_DEBUG
and CMAKE_CXX_FLAGS_RELEASE
that prevents CMake using the default value:
set(CMAKE_C_FLAGS_DEBUG ""
CACHE STRING "Flags used by the compiler during debug builds.")
set(CMAKE_CXX_FLAGS_DEBUG ""
CACHE STRING "Flags used by the compiler during debug builds.")
set(CMAKE_C_FLAGS_RELEASE ""
CACHE STRING "Flags used by the compiler during release builds.")
set(CMAKE_CXX_FLAGS_RELEASE ""
CACHE STRING "Flags used by the compiler during release builds.")
As it's not good to modify this file directly, it seems the only way to solve it is to specify the value explicitly in command-line for every first generation.
Upvotes: 0
Reputation: 57203
CMake will take care of release and debug flags internally, you are expected to pass -DCMAKE_BUILD_TYPE=Release
or -DCMAKE_BUILD_TYPE=Debug
on command line.
Upvotes: -1