Created
September 5, 2015 21:33
-
-
Save Manu343726/64c0a75c089ad96d22cb to your computer and use it in GitHub Desktop.
Generating assembly listings with CMake
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## Variables: | |
| # | |
| # OUTPUT_DIRECTORY: Directory where the assemblu file will be placed (For example "/home/manu/listings") | |
| # ASSEMBLY_LISTING_FILE: Assembly listing filename (For example "foo.s") | |
| # SOURCE_FILENAME: Name of the sourcefile being compiled (See bellow). For example "foo", from foo.cpp. | |
| # TARGET: Target being compiled (Mostly an executable target). For example "foo". | |
| if(MSVC) | |
| # Trust me, Microsoft docs suck. | |
| target_compile_options(${TARGET} "/Fa${OUTPUT_PATH}/${ASSEMBLY_LISTING_FILE}" /FA) | |
| else() | |
| # The trick is that makefiles generator defines a [sourcefile].s target for each sourcefile of a target to generate the listing | |
| # of that file. We hook a command after build to invoke that target and copy the result file to our ourput directory: | |
| add_custom_command(TARGET ${TARGET} | |
| POST_BUILD | |
| COMMAND make ARGS ${SOURCE_FILENAME}.s | |
| COMMAND ${CMAKE_COMMAND} -E copy | |
| "${CMAKE_BINARY_DIR}/CMakeFiles/${TARGET}.dir/${SOURCE_FILENAME}.cpp.s" | |
| "${OUTPUT_PATH}/${ASSEMBLY_LISTING_FILE}" | |
| WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) | |
| endif() |
Author
Yes, these are the input variables of the routine
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how to use it ? do I need to set these variable first?
OUTPUT_DIRECTORY: Directory where the assemblu file will be placed (For example "/home/manu/listings")
ASSEMBLY_LISTING_FILE: Assembly listing filename (For example "foo.s")
SOURCE_FILENAME: Name of the sourcefile being compiled (See bellow). For example "foo", from foo.cpp.
TARGET: Target being compiled (Mostly an executable target). For example "foo".