1

I have the following line in my CMakeLists.txt file:

set_target_properties(native-lib PROPERTIES COMPILE_FLAGS "-save-temps")

This tells the compiler to preserve the assembly in a *.s file.

I need to know how to make this include the assembly listing though.

i.e. Have the C source beside the assembly in the *.s file.

I believe this is normally done with the -l flag but it doesn't seem to work.

Any ideas?

Alex Cohn
  • 56,089
  • 9
  • 113
  • 307
JP_
  • 1,636
  • 15
  • 26

1 Answers1

1

-save-temps is not about this at all. You need -S flag to generate assembly listings. Unfortunately, you cannot eat the cake and have it create assembly and object files in same run. With cmake, you can add this file either via the script:

set_target_properties(native-lib PROPERTIES COMPILE_FLAGS "-S")

or through build.gradle:

android {
  defaultConfig {
    externalNativeBuild { 
      cmake {
        cFlags "-S"

In either case, your build will fail, but you can collect the assembly listings from .externalNativeBuild/cmake/debug/armeabi/CMakeFiles/native-lib.dir/src/main/cpp. You may choose to manually rename these files from *.o to *.s.

Alex Cohn
  • 56,089
  • 9
  • 113
  • 307
  • Thanks for the reply. I tried this and the build is successful. There is nothing in the mentioned folder afterwards and after removing -save-temps there is no .s file anymore. I also tried it with both -S and -save-temps but no luck. – JP_ Aug 07 '17 at 15:59
  • Maybe you have cpp files, then you need `cppFlags`. – Alex Cohn Aug 07 '17 at 16:12
  • 1
    If you add `arguments '-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON'` you will see the actual compile commands in your gradle console. – Alex Cohn Aug 07 '17 at 16:13
  • Okay thanks I got the .o file to show up in the folder you mentioned by using cppFlags "-S" in the build.gradle file and ignoring the cmake file. Unfortunately this is not the assembly listing. It's assembly yes but there is no mixed C with it, – JP_ Aug 07 '17 at 17:45
  • 1
    This [seems](https://stackoverflow.com/q/24603910/192373) to be not supported by clang. You can switch to GCC, but it is another compiler, and it is being discouraged in NDK. – Alex Cohn Aug 07 '17 at 19:57
  • It's almost worth it for this... I tried the suggested workaround on the page you linked but it doesn't work either. This is really disappointing. Thanks for the help mate. – JP_ Aug 08 '17 at 03:54