Search code examples
androidc++android-studiocmakeandroid-gradle-plugin

Android Studio, CMake. How to print debug message in compile time?


I'm using Android Studio 2.3 beta 3. I put message(AUTHOR_WARNING "Hello CMake, hello Android") In my CMakeLists.txt

But I saw this message only few times when rebuilding project in Android Studio. In most cases there's no "Hello CMake, hello Android" string in Gradle Console after build finishes. I've tried resync gradle and clean/rebuild project, still no expected output.

I have some problems with my build (I think it's incorrect paths) so my goal - to print CMake variables in compile time to better understand what is actually going on.


Solution

  • CMake messages are only at generation time (when CMake is used to generate your project / Makefile).

    One way to get CMake to generate is to go to retrieve the build folder and the CMakeCache.txt file in it, and then:

    1. Retrieve the path to your cmake executable, by reading the CMakeCache.txt file and checking the value of the CMAKE_COMMAND variable
    2. Open a command prompt in CMakeCache.txt directory
    3. Run: <path_to_cmake_found_at_point_1> .

    Note: The build folder should have a CMakeCache.txt file. The above will not work unless it does.