Search code examples
assemblycmakefortrangnugfortran

How do I see the assembler files in CMake?


I am using CMake to compile fortran code with the GFortran compiler. I want to see the assembler files but I haven't done this before. Should I see .s files after running make?

I've enabled assembly in my CmakeLists with enable_language(ASM-ATT) and I've used the following flags set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -save-temps -g -O0 to save the assembler files once they are built


Solution

  • The -save-temps option works as it should. You can find assembly files with the .s extension (and not .S) by find . -name *.s or other search tools, but, most likely, they will be located in <build-dir>/CMakeFiles/<target-name>.dir.

    Also, there's no need to enable the assembly language by calling enable_language(ASM-ATT). You should do so if you already have some assembly files in your source tree, which will be compiled alongside the Fortran files.

    The better approach to populate compile options is not to use CMake variables like CMAKE_Fortran_FLAGS, because it's applied to all the targets, but to call target-specific commands:

    add_executable(main)
    target_sources(main PRIVATE <your sources>)
    target_compile_options(main PRIVATE -save-temps <other options>)
    

    Other options like -g are set when you specify a build type via CMAKE_BUILD_TYPE:

    cmake -DCMAKE_BUILD_TYPE=Debug ..