24

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?

Paweł Bylica
  • 3,441
  • 1
  • 27
  • 42
David Doria
  • 9,383
  • 15
  • 81
  • 143
  • 10
    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. – David Doria Oct 19 '12 at 02:43

2 Answers2

28

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
ingomueller.net
  • 3,388
  • 2
  • 32
  • 30
  • 2
    How can I combine this with interlaced source comments, e.g. [this](http://stackoverflow.com/a/137479/388010)? À la `g++ -g -O0 -c -fverbose-asm -Wa,-adhln test.cpp > test.lst` – Sebastian Graf Jul 17 '15 at 17:34
  • 1
    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. – Sebastian Graf Jul 17 '15 at 17:45
19

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

Fraser
  • 70,437
  • 17
  • 232
  • 212