简体   繁体   English

如何防止Gradle / Android Studio覆盖CMake提供的C ++编译器设置?

[英]How can I prevent Gradle/Android Studio from overwriting C++ compiler settings provided by CMake?

I'm trying to integrate my existing CMake scripts into Android Studio / Gradle. 我正在尝试将现有的CMake脚本集成到Android Studio / Gradle中。 I've got it generating and building with CMake, but for whatever reason, the CPP flags I specify in my CMake scripts are not being used when run through Gradle. 我已经使用CMake生成和构建它,但无论出于何种原因,我在CMake脚本中指定的CPP标志在通过Gradle运行时都没有被使用。 I want my CMake scripts to have complete control over settings like -std=c++14 , -fexceptions , etc. All I really need Gradle to do is provide a toolchain file to specify the toolset information (compiler, path to includes, etc). 我希望我的CMake脚本可以完全控制-std=c++14-fexceptions等设置。我真正需要Gradle做的是提供一个工具链文件来指定工具集信息(编译器,包含的路径等等) )。 I guess Gradle is trying to take more control over CMake than is necessary (at least as far as I can tell). 我猜Gradle试图对CMake进行更多的控制而不是必要的(至少据我所知)。

Is there a way to make Gradle not overwrite these CMake settings? 有没有办法让Gradle不会覆盖这些CMake设置? It's going to be a pain to maintain and duplicate these settings between Gradle and CMake scripts themselves. 在Gradle和CMake脚本之间维护和复制这些设置将是一件痛苦的事。 So far I'm really not a fan of the Gradle integration of CMake, they seem to use their own hand-built version with custom patches. 到目前为止,我真的不喜欢CMake的Gradle集成,他们似乎使用他们自己手工制作的版本和自定义补丁。

Gradle doesn't overwrite any CMake c++ flags. Gradle不会覆盖任何CMake c ++标志。 What you're seeing is probably the Android SDK CMake toolchain that sets up tools, c++ flags, and per-ABI configuration. 你所看到的可能是设置工具,c ++标志和per-ABI配置的Android SDK CMake工具链。

Here is how gradle calls CMake: 以下是gradle如何调用CMake:

{root}/Sdk/cmake/3.6.3155560/bin/cmake
-H{project}/app
-B{project}/app/.externalNativeBuild/cmake/debug/arm64-v8a
-GAndroid Gradle - Ninja
-DANDROID_ABI=arm64-v8a
-DANDROID_NDK={root}/Sdk/ndk-bundle
-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={project}/app/build/intermediates/cmake/debug/obj/arm64-v8a
-DCMAKE_BUILD_TYPE=Debug
-DCMAKE_MAKE_PROGRAM={root}/Sdk/cmake/3.6.3155560/bin/ninja
-DCMAKE_TOOLCHAIN_FILE={root}/Sdk/ndk-bundle/build/cmake/android.toolchain.cmake
-DANDROID_PLATFORM=android-21

You can see what it is for your particular case by looking at one of the cmake_build_output.txt files that gradle generated. 您可以通过查看gradle生成的cmake_build_output.txt文件之一来查看特定情况的内容。

You can look at android.toolchain.cmake to see when and how the toolchain sets particular flags. 您可以查看android.toolchain.cmake以查看工具链何时以及如何设置特定标志。 (You can open bugs on that file and provide feedback by going to b.android.com. If you cc me--jomof@google.com--I will make sure it gets to the right person). (您可以打开该文件中的错误并通过访问b.android.com提供反馈。如果您抄送我--jomof@google.com--我会确保它找到合适的人)。 We're definitely planning to beef up documentation as well and you can open bugs for suggestions for documentation improvement as well. 我们当然也计划加强文档,你也可以打开bug来获取文档改进的建议。

You should be able to append your own flags like -fexceptions to what the toolchain sets and your values will override any prior values. 您应该能够将自己的标志(如-fexceptions)附加到工具链设置的内容中,并且您的值将覆盖任何先前的值。 If that isn't what you're seeing can you give some more details on how your CMakeLists.txt is set up? 如果那不是您所看到的,您可以提供有关如何设置CMakeLists.txt的更多详细信息吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM