3

I am using Android Studio 3.0 for my NDK based app. For the C++ code, I use CMake as the external builder.

This works well, I can create debug and release binaries.

However, I would like to turn on compiler optimizations (say -O3) for a part of the C++ code (the physics engine), not just for the release build, but also for the debug build.

So create the bulk of the debug build as is, without optimizing, yet, I want one of the static library targets to be built with the compiler optimization enabled.

How can I go about this?

I have a CMakeLists for a static library target that gets included using add_subdirectory() directive in the top level CMakeLists file.

Note that I point to the top level CMakeLists in my app's build.gradle file like this:

externalNativeBuild {
    cmake {
        path '../../Android/jni/CMakeLists.txt'
    }
}
Bram
  • 7,440
  • 3
  • 52
  • 94

1 Answers1

9

It turns out that you can use the target_compile_options() macro in your CMakeLists.txt with a config specification like this:

target_compile_options(opende PRIVATE
"$<$<CONFIG:RELEASE>:-O3>"
"$<$<CONFIG:DEBUG>:-O3>"
)

This macro adds to the existing compile options.

Bram
  • 7,440
  • 3
  • 52
  • 94