通过Cmake打开Android Studio调试构建的编译器优化 [英] Turn on compiler optimization for Android Studio debug build via Cmake

查看:343
本文介绍了通过Cmake打开Android Studio调试构建的编译器优化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为基于NDK的应用程序使用Android Studio 3.0. 对于C ++代码,我使用 CMake作为外部构建器.

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.

但是,我想为C ++代码的一部分(物理引擎)打开编译器优化(例如-O3),不仅针对发行版,还针对调试版.

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.

我该怎么办?

我有一个静态库目标的CMakeLists,该目标使用顶层CMakeLists文件中的add_subdirectory()指令.

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

请注意,我指向应用程序的build.gradle文件中的顶级CMakeList,如下所示:

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'
    }
}

推荐答案

事实证明,您可以使用

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.

这篇关于通过Cmake打开Android Studio调试构建的编译器优化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆