CMakeDetermineASMCompiler.cmake 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. # determine the compiler to use for ASM programs
  4. include(${CMAKE_ROOT}/Modules/CMakeDetermineCompiler.cmake)
  5. if(NOT CMAKE_ASM${ASM_DIALECT}_COMPILER)
  6. # prefer the environment variable ASM
  7. if(NOT $ENV{ASM${ASM_DIALECT}} STREQUAL "")
  8. get_filename_component(CMAKE_ASM${ASM_DIALECT}_COMPILER_INIT $ENV{ASM${ASM_DIALECT}} PROGRAM PROGRAM_ARGS CMAKE_ASM${ASM_DIALECT}_FLAGS_ENV_INIT)
  9. if(CMAKE_ASM${ASM_DIALECT}_FLAGS_ENV_INIT)
  10. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ARG1 "${CMAKE_ASM${ASM_DIALECT}_FLAGS_ENV_INIT}" CACHE STRING "First argument to ASM${ASM_DIALECT} compiler")
  11. endif()
  12. if(NOT EXISTS ${CMAKE_ASM${ASM_DIALECT}_COMPILER_INIT})
  13. message(FATAL_ERROR "Could not find compiler set in environment variable ASM${ASM_DIALECT}:\n$ENV{ASM${ASM_DIALECT}}.")
  14. endif()
  15. endif()
  16. # finally list compilers to try
  17. if("ASM${ASM_DIALECT}" STREQUAL "ASM") # the generic assembler support
  18. if(NOT CMAKE_ASM_COMPILER_INIT)
  19. if(CMAKE_C_COMPILER)
  20. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_LIST ${CMAKE_C_COMPILER})
  21. elseif(CMAKE_CXX_COMPILER)
  22. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_LIST ${CMAKE_CXX_COMPILER})
  23. else()
  24. # List all default C and CXX compilers
  25. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_LIST
  26. ${_CMAKE_TOOLCHAIN_PREFIX}cc ${_CMAKE_TOOLCHAIN_PREFIX}gcc cl bcc xlc
  27. CC ${_CMAKE_TOOLCHAIN_PREFIX}c++ ${_CMAKE_TOOLCHAIN_PREFIX}g++ aCC cl bcc xlC)
  28. endif()
  29. endif()
  30. else() # some specific assembler "dialect"
  31. if(NOT CMAKE_ASM${ASM_DIALECT}_COMPILER_INIT AND NOT CMAKE_ASM${ASM_DIALECT}_COMPILER_LIST)
  32. message(FATAL_ERROR "CMAKE_ASM${ASM_DIALECT}_COMPILER_INIT or CMAKE_ASM${ASM_DIALECT}_COMPILER_LIST must be preset !")
  33. endif()
  34. endif()
  35. # Find the compiler.
  36. _cmake_find_compiler(ASM${ASM_DIALECT})
  37. else()
  38. _cmake_find_compiler_path(ASM${ASM_DIALECT})
  39. endif()
  40. mark_as_advanced(CMAKE_ASM${ASM_DIALECT}_COMPILER)
  41. if (NOT _CMAKE_TOOLCHAIN_LOCATION)
  42. get_filename_component(_CMAKE_TOOLCHAIN_LOCATION "${CMAKE_ASM${ASM_DIALECT}_COMPILER}" PATH)
  43. endif ()
  44. if(NOT CMAKE_ASM${ASM_DIALECT}_COMPILER_ID)
  45. # Table of per-vendor compiler id flags with expected output.
  46. list(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS GNU )
  47. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_GNU "--version")
  48. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_GNU "(GNU assembler)|(GCC)|(Free Software Foundation)")
  49. list(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS Clang )
  50. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_Clang "--version")
  51. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_Clang "(clang version)")
  52. list(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS AppleClang )
  53. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_AppleClang "--version")
  54. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_AppleClang "(Apple LLVM version)")
  55. list(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS ARMClang )
  56. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_ARMClang "--version")
  57. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_ARMClang "armclang")
  58. list(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS HP )
  59. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_HP "-V")
  60. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_HP "HP C")
  61. list(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS Intel )
  62. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_Intel "--version")
  63. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_Intel "(ICC)")
  64. list(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS SunPro )
  65. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_SunPro "-V")
  66. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_SunPro "Sun C")
  67. list(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS XL )
  68. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_XL "-qversion")
  69. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_XL "XL C")
  70. list(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS MSVC )
  71. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_MSVC "-?")
  72. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_MSVC "Microsoft")
  73. list(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS TI )
  74. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_TI "-h")
  75. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_TI "Texas Instruments")
  76. list(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS IAR)
  77. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_IAR )
  78. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_IAR "IAR Assembler")
  79. list(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS ARMCC)
  80. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_ARMCC )
  81. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_ARMCC "(ARM Compiler)|(ARM Assembler)")
  82. list(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS NASM)
  83. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_NASM "-v")
  84. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_NASM "(NASM version)")
  85. list(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS YASM)
  86. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_YASM "--version")
  87. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_YASM "(yasm)")
  88. list(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS ADSP)
  89. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_ADSP "-version")
  90. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_ADSP "Analog Devices")
  91. list(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS QCC)
  92. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_QCC "-V")
  93. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_QCC "gcc_nto")
  94. include(CMakeDetermineCompilerId)
  95. set(userflags)
  96. CMAKE_DETERMINE_COMPILER_ID_VENDOR(ASM${ASM_DIALECT} "${userflags}")
  97. if("x${CMAKE_ASM${ASM_DIALECT}_COMPILER_ID}" STREQUAL "xIAR")
  98. # primary necessary to detect architecture, so the right archiver and linker can be picked
  99. # eg. "IAR Assembler V8.10.1.12857/W32 for ARM" or "IAR Assembler V4.11.1.4666 for Renesas RX"
  100. # Cut out identification first, newline handling is a pain
  101. string(REGEX MATCH "IAR Assembler[^\r\n]*" _compileid "${CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_OUTPUT}")
  102. if("${_compileid}" MATCHES "V([0-9]+\\.[0-9]+\\.[0-9]+)")
  103. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_VERSION ${CMAKE_MATCH_1})
  104. endif()
  105. string(REGEX MATCHALL "([A-Za-z0-9-]+)" _all_compileid_matches "${_compileid}")
  106. if(_all_compileid_matches)
  107. list(GET _all_compileid_matches "-1" CMAKE_ASM${ASM_DIALECT}_COMPILER_ARCHITECTURE_ID)
  108. endif()
  109. endif()
  110. unset(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_OUTPUT)
  111. unset(_all_compileid_matches)
  112. unset(_compileid)
  113. endif()
  114. if(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID)
  115. if(CMAKE_ASM${ASM_DIALECT}_COMPILER_VERSION)
  116. set(_version " ${CMAKE_ASM${ASM_DIALECT}_COMPILER_VERSION}")
  117. else()
  118. set(_version "")
  119. endif()
  120. if(CMAKE_ASM${ASM_DIALECT}_COMPILER_ARCHITECTURE_ID AND "x${CMAKE_ASM${ASM_DIALECT}_COMPILER_ID}" STREQUAL "xIAR")
  121. set(_archid " ${CMAKE_ASM${ASM_DIALECT}_COMPILER_ARCHITECTURE_ID}")
  122. else()
  123. set(_archid "")
  124. endif()
  125. message(STATUS "The ASM${ASM_DIALECT} compiler identification is ${CMAKE_ASM${ASM_DIALECT}_COMPILER_ID}${_archid}${_version}")
  126. unset(_archid)
  127. unset(_version)
  128. else()
  129. message(STATUS "The ASM${ASM_DIALECT} compiler identification is unknown")
  130. endif()
  131. # If we have a gas/as cross compiler, they have usually some prefix, like
  132. # e.g. powerpc-linux-gas, arm-elf-gas or i586-mingw32msvc-gas , optionally
  133. # with a 3-component version number at the end
  134. # The other tools of the toolchain usually have the same prefix
  135. # NAME_WE cannot be used since then this test will fail for names like
  136. # "arm-unknown-nto-qnx6.3.0-gas.exe", where BASENAME would be
  137. # "arm-unknown-nto-qnx6" instead of the correct "arm-unknown-nto-qnx6.3.0-"
  138. if (NOT _CMAKE_TOOLCHAIN_PREFIX)
  139. get_filename_component(COMPILER_BASENAME "${CMAKE_ASM${ASM_DIALECT}_COMPILER}" NAME)
  140. if (COMPILER_BASENAME MATCHES "^(.+-)g?as(-[0-9]+\\.[0-9]+\\.[0-9]+)?(\\.exe)?$")
  141. set(_CMAKE_TOOLCHAIN_PREFIX ${CMAKE_MATCH_1})
  142. endif ()
  143. endif ()
  144. # Now try the C compiler regexp:
  145. if (NOT _CMAKE_TOOLCHAIN_PREFIX)
  146. if (COMPILER_BASENAME MATCHES "^(.+-)g?cc(-[0-9]+\\.[0-9]+\\.[0-9]+)?(\\.exe)?$")
  147. set(_CMAKE_TOOLCHAIN_PREFIX ${CMAKE_MATCH_1})
  148. endif ()
  149. endif ()
  150. # Finally try the CXX compiler regexp:
  151. if (NOT _CMAKE_TOOLCHAIN_PREFIX)
  152. if (COMPILER_BASENAME MATCHES "^(.+-)[gc]\\+\\+(-[0-9]+\\.[0-9]+\\.[0-9]+)?(\\.exe)?$")
  153. set(_CMAKE_TOOLCHAIN_PREFIX ${CMAKE_MATCH_1})
  154. endif ()
  155. endif ()
  156. set(_CMAKE_PROCESSING_LANGUAGE "ASM")
  157. include(CMakeFindBinUtils)
  158. include(Compiler/${CMAKE_ASM${ASM_DIALECT}_COMPILER_ID}-FindBinUtils OPTIONAL)
  159. unset(_CMAKE_PROCESSING_LANGUAGE)
  160. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ENV_VAR "ASM${ASM_DIALECT}")
  161. if(CMAKE_ASM${ASM_DIALECT}_COMPILER)
  162. message(STATUS "Found assembler: ${CMAKE_ASM${ASM_DIALECT}_COMPILER}")
  163. else()
  164. message(STATUS "Didn't find assembler")
  165. endif()
  166. foreach(_var
  167. COMPILER
  168. COMPILER_ID
  169. COMPILER_ARG1
  170. COMPILER_ENV_VAR
  171. COMPILER_AR
  172. COMPILER_RANLIB
  173. COMPILER_VERSION
  174. )
  175. set(_CMAKE_ASM_${_var} "${CMAKE_ASM${ASM_DIALECT}_${_var}}")
  176. endforeach()
  177. if(CMAKE_ASM${ASM_DIALECT}_COMPILER_ARCHITECTURE_ID)
  178. set(_SET_CMAKE_ASM_COMPILER_ARCHITECTURE_ID
  179. "set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ARCHITECTURE_ID ${CMAKE_ASM${ASM_DIALECT}_COMPILER_ARCHITECTURE_ID})")
  180. else()
  181. set(_SET_CMAKE_ASM_COMPILER_ARCHITECTURE_ID "")
  182. endif()
  183. # configure variables set in this file for fast reload later on
  184. configure_file(${CMAKE_ROOT}/Modules/CMakeASMCompiler.cmake.in
  185. ${CMAKE_PLATFORM_INFO_DIR}/CMakeASM${ASM_DIALECT}Compiler.cmake @ONLY)
  186. foreach(_var
  187. COMPILER
  188. COMPILER_ID
  189. COMPILER_ARG1
  190. COMPILER_ENV_VAR
  191. COMPILER_AR
  192. COMPILER_RANLIB
  193. COMPILER_VERSION
  194. )
  195. unset(_CMAKE_ASM_${_var})
  196. endforeach()