Generate assembly for a target

11,353

Solution 1

If you're trying to actually build MyTarget and leave the generated assembly, you can replace -S with -save-temps and then do make MyTarget

Solution 2

CMake has targets built in for both assembler and preprocessor output. For a file called src.cpp, CMake generates the target src.s for assembler output and src.i for the preprocessor output. It generates the assembler/preprocessor outputs for each target seperately in case the compile flags are different. Using the make generator for your CMake project, you can get the assembler and preprocessor outputs like this:

make src.s   # assembler output
make src.i   # preprocessor output
Share:
11,353

Related videos on Youtube

David Doria
Author by

David Doria

I live at the intersection of computer vision research and software engineering. With my background in image processing, computer vision, machine learning, and LiDAR data analysis, I am in a position to develop algorithmic solutions to these difficult problems. But these algorithms are not particularly beneficial as only ideas or prototypes - efficient and carefully executed implementations are the key to their real world application. I am passionate about the reusability of the software I develop - I have found that continually building tools for my team rather than simply solving the particular problem at hand is the key to accelerating future work and success.

Updated on September 16, 2022

Comments

  • David Doria
    David Doria over 1 year

    I am trying to pass -S to GCC for one of my executables. I tried this:

    set_target_properties(MyTarget PROPERTIES COMPILE_FLAGS "-S") 
    

    but I get "file format not recognized; treating as linker script"

    (It builds fine without that line)

    Is there something wrong with passing -S like this? Or is there another way to have CMake output the assembly .s files?

    • David Doria
      David Doria over 11 years
      I learned that if you type 'make help' on a CMake project, you will see a list of targets. "MyTarget.s" is one of them, so simply doing "make MyTarget.s" produces the assembly I was looking for.
  • Sebastian Graf
    Sebastian Graf almost 9 years
    How can I combine this with interlaced source comments, e.g. this? À la g++ -g -O0 -c -fverbose-asm -Wa,-adhln test.cpp > test.lst
  • Sebastian Graf
    Sebastian Graf almost 9 years
    For now, I manually alter the right makefile and adding -fverbose-asm after it has been generated. Then I can use the as -alhnd bit.