40 lines · plain
1# Helper function to find out whether the assembler supports a particular2# command-line flag. You'd like to use the standard check_compiler_flag(), but3# that only supports a fixed list of languages, and ASM isn't one of them. So4# we do it ourselves, by trying to assemble an empty source file.5 6function(check_assembler_flag outvar flag)7 if(NOT DEFINED "${outvar}")8 if(NOT CMAKE_REQUIRED_QUIET)9 message(CHECK_START "Checking for assembler flag ${flag}")10 endif()11 12 # Stop try_compile from attempting to link the result of the assembly, so13 # that we don't depend on having a working linker, and also don't have to14 # figure out what special symbol like _start needs to be defined in the15 # test input.16 #17 # This change is made within the dynamic scope of this function, so18 # CMAKE_TRY_COMPILE_TARGET_TYPE will be restored to its previous value on19 # return.20 set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)21 22 # Try to assemble an empty file with a .S name, using the provided flag.23 set(asm_source_file24 ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CheckAssemblerFlag.S)25 write_file(${asm_source_file} "")26 try_compile(${outvar}27 ${CMAKE_BINARY_DIR}28 SOURCES ${asm_source_file}29 COMPILE_DEFINITIONS ${flag})30 31 if(NOT CMAKE_REQUIRED_QUIET)32 if(${outvar})33 message(CHECK_PASS "Accepted")34 else()35 message(CHECK_FAIL "Not accepted")36 endif()37 endif()38 endif()39endfunction()40