Home > Software engineering >  How to generate preprocess and assmeble code by cmake?
How to generate preprocess and assmeble code by cmake?

Time:12-20

I am trying to get intermediate .i .s file by CMake when compiling .cpp file, but cmake default only output .o file. Is there any command to manipulate cmake to keep these intermediate file, thanks a lot!

CodePudding user response:

If you are using gcc, try adding this line.

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -save-temps=obj")

CodePudding user response:

Which flag to use depends on the compiler you are using. Also, you should strongly prefer to inject such compiler-and-scenario-specific flags into the build externally, rather than set()-ing them inside the build.

For g or clang , the following invocation would be appropriate:

$ cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug \
    -DCMAKE_CXX_FLAGS="-save-temps=obj"

For MSVC it would be:

> cmake -S . -B build "-DCMAKE_CXX_FLAGS=/FA"
  • Related