Kristupas A.
Kristupas A.

Reputation: 344

Android Studio External Native Build Precompiled Headers

I'm porting a project from NDK build to Android Studio.

Currently the project has a precompiled header attached (with NDK build), which speeds up compilation time a lot.

I'm looking for a way to add precompiled header (.pch) to my external native build within Android Studio project. I'm using CMake.

Upvotes: 9

Views: 1237

Answers (1)

downstroy
downstroy

Reputation: 1118

I am in the same situation and I have found several user-made script to do that.

I would recommend this one:

https://github.com/larsch/cmake-precompiled-header

In order to make it work for the latest ndk-tools which uses clang, copy paste the content of this pull request:

https://gist.github.com/leeor/316168500765cf51ae97

into the PrecompiledHeader.cmake file (replace everything in this file, except if you want to keep GCC/ MSVC compatibility, then just you will have to merge the two files which shouldn't be hard).

It should work, except some special CMAKE_CXX_FLAGS that triggers an error in the export_all_flags function, and that I don't know how to fix yet. I'll keep you updated with my progress.

Upvotes: 3

Related Questions