CMakeDetermineASMCompiler.cmake 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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_COMPILER "${CMAKE_C_COMPILER}" CACHE FILEPATH "The ASM compiler")
  21. set(CMAKE_ASM_COMPILER_ID "${CMAKE_C_COMPILER_ID}")
  22. elseif(CMAKE_CXX_COMPILER)
  23. set(CMAKE_ASM_COMPILER "${CMAKE_CXX_COMPILER}" CACHE FILEPATH "The ASM compiler")
  24. set(CMAKE_ASM_COMPILER_ID "${CMAKE_CXX_COMPILER_ID}")
  25. else()
  26. # List all default C and CXX compilers
  27. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_LIST
  28. ${_CMAKE_TOOLCHAIN_PREFIX}cc ${_CMAKE_TOOLCHAIN_PREFIX}gcc cl bcc xlc
  29. CC ${_CMAKE_TOOLCHAIN_PREFIX}c++ ${_CMAKE_TOOLCHAIN_PREFIX}g++ aCC cl bcc xlC)
  30. endif()
  31. endif()
  32. else() # some specific assembler "dialect"
  33. if(NOT CMAKE_ASM${ASM_DIALECT}_COMPILER_INIT AND NOT CMAKE_ASM${ASM_DIALECT}_COMPILER_LIST)
  34. message(FATAL_ERROR "CMAKE_ASM${ASM_DIALECT}_COMPILER_INIT or CMAKE_ASM${ASM_DIALECT}_COMPILER_LIST must be preset !")
  35. endif()
  36. endif()
  37. # Find the compiler.
  38. _cmake_find_compiler(ASM${ASM_DIALECT})
  39. else()
  40. _cmake_find_compiler_path(ASM${ASM_DIALECT})
  41. endif()
  42. mark_as_advanced(CMAKE_ASM${ASM_DIALECT}_COMPILER)
  43. if (NOT _CMAKE_TOOLCHAIN_LOCATION)
  44. get_filename_component(_CMAKE_TOOLCHAIN_LOCATION "${CMAKE_ASM${ASM_DIALECT}_COMPILER}" PATH)
  45. endif ()
  46. if(NOT CMAKE_ASM${ASM_DIALECT}_COMPILER_ID)
  47. # Table of per-vendor compiler id flags with expected output.
  48. list(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS GNU )
  49. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_GNU "--version")
  50. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_GNU "(GNU assembler)|(GCC)|(Free Software Foundation)")
  51. list(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS HP )
  52. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_HP "-V")
  53. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_HP "HP C")
  54. list(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS Intel )
  55. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_Intel "--version")
  56. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_Intel "(ICC)")
  57. list(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS SunPro )
  58. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_SunPro "-V")
  59. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_SunPro "Sun C")
  60. list(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS XL )
  61. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_XL "-qversion")
  62. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_XL "XL C")
  63. list(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS MSVC )
  64. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_MSVC "/?")
  65. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_MSVC "Microsoft")
  66. list(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS TI )
  67. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_TI "-h")
  68. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_TI "Texas Instruments")
  69. list(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS IAR)
  70. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_IAR )
  71. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_IAR "IAR Assembler")
  72. list(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS ARMCC)
  73. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_ARMCC )
  74. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_ARMCC "(ARM Compiler)|(ARM Assembler)")
  75. list(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS NASM)
  76. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_NASM "-v")
  77. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_NASM "(NASM version)")
  78. list(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS YASM)
  79. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_YASM "--version")
  80. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_YASM "(yasm)")
  81. include(CMakeDetermineCompilerId)
  82. set(userflags)
  83. CMAKE_DETERMINE_COMPILER_ID_VENDOR(ASM${ASM_DIALECT} "${userflags}")
  84. endif()
  85. if(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID)
  86. message(STATUS "The ASM${ASM_DIALECT} compiler identification is ${CMAKE_ASM${ASM_DIALECT}_COMPILER_ID}")
  87. else()
  88. message(STATUS "The ASM${ASM_DIALECT} compiler identification is unknown")
  89. endif()
  90. # If we have a gas/as cross compiler, they have usually some prefix, like
  91. # e.g. powerpc-linux-gas, arm-elf-gas or i586-mingw32msvc-gas , optionally
  92. # with a 3-component version number at the end
  93. # The other tools of the toolchain usually have the same prefix
  94. # NAME_WE cannot be used since then this test will fail for names like
  95. # "arm-unknown-nto-qnx6.3.0-gas.exe", where BASENAME would be
  96. # "arm-unknown-nto-qnx6" instead of the correct "arm-unknown-nto-qnx6.3.0-"
  97. if (NOT _CMAKE_TOOLCHAIN_PREFIX)
  98. get_filename_component(COMPILER_BASENAME "${CMAKE_ASM${ASM_DIALECT}_COMPILER}" NAME)
  99. if (COMPILER_BASENAME MATCHES "^(.+-)g?as(-[0-9]+\\.[0-9]+\\.[0-9]+)?(\\.exe)?$")
  100. set(_CMAKE_TOOLCHAIN_PREFIX ${CMAKE_MATCH_1})
  101. endif ()
  102. endif ()
  103. # Now try the C compiler regexp:
  104. if (NOT _CMAKE_TOOLCHAIN_PREFIX)
  105. if (COMPILER_BASENAME MATCHES "^(.+-)g?cc(-[0-9]+\\.[0-9]+\\.[0-9]+)?(\\.exe)?$")
  106. set(_CMAKE_TOOLCHAIN_PREFIX ${CMAKE_MATCH_1})
  107. endif ()
  108. endif ()
  109. # Finally try the CXX compiler regexp:
  110. if (NOT _CMAKE_TOOLCHAIN_PREFIX)
  111. if (COMPILER_BASENAME MATCHES "^(.+-)[gc]\\+\\+(-[0-9]+\\.[0-9]+\\.[0-9]+)?(\\.exe)?$")
  112. set(_CMAKE_TOOLCHAIN_PREFIX ${CMAKE_MATCH_1})
  113. endif ()
  114. endif ()
  115. include(CMakeFindBinUtils)
  116. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ENV_VAR "ASM${ASM_DIALECT}")
  117. if(CMAKE_ASM${ASM_DIALECT}_COMPILER)
  118. message(STATUS "Found assembler: ${CMAKE_ASM${ASM_DIALECT}_COMPILER}")
  119. else()
  120. message(STATUS "Didn't find assembler")
  121. endif()
  122. set(_CMAKE_ASM_COMPILER "${CMAKE_ASM${ASM_DIALECT}_COMPILER}")
  123. set(_CMAKE_ASM_COMPILER_ID "${CMAKE_ASM${ASM_DIALECT}_COMPILER_ID}")
  124. set(_CMAKE_ASM_COMPILER_ARG1 "${CMAKE_ASM${ASM_DIALECT}_COMPILER_ARG1}")
  125. set(_CMAKE_ASM_COMPILER_ENV_VAR "${CMAKE_ASM${ASM_DIALECT}_COMPILER_ENV_VAR}")
  126. set(_CMAKE_ASM_COMPILER_AR "${CMAKE_ASM${ASM_DIALECT}_COMPILER_AR}")
  127. set(_CMAKE_ASM_COMPILER_RANLIB "${CMAKE_ASM${ASM_DIALECT}_COMPILER_RANLIB}")
  128. # configure variables set in this file for fast reload later on
  129. configure_file(${CMAKE_ROOT}/Modules/CMakeASMCompiler.cmake.in
  130. ${CMAKE_PLATFORM_INFO_DIR}/CMakeASM${ASM_DIALECT}Compiler.cmake @ONLY)
  131. set(_CMAKE_ASM_COMPILER)
  132. set(_CMAKE_ASM_COMPILER_ARG1)
  133. set(_CMAKE_ASM_COMPILER_ENV_VAR)
  134. set(_CMAKE_ASM_COMPILER_AR)
  135. set(_CMAKE_ASM_COMPILER_RANLIB)