CMakeDetermineASMCompiler.cmake 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. #=============================================================================
  2. # Copyright 2007-2009 Kitware, Inc.
  3. #
  4. # Distributed under the OSI-approved BSD License (the "License");
  5. # see accompanying file Copyright.txt for details.
  6. #
  7. # This software is distributed WITHOUT ANY WARRANTY; without even the
  8. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9. # See the License for more information.
  10. #=============================================================================
  11. # (To distribute this file outside of CMake, substitute the full
  12. # License text for the above reference.)
  13. # determine the compiler to use for ASM programs
  14. include(${CMAKE_ROOT}/Modules/CMakeDetermineCompiler.cmake)
  15. if(NOT CMAKE_ASM${ASM_DIALECT}_COMPILER)
  16. # prefer the environment variable ASM
  17. if(NOT $ENV{ASM${ASM_DIALECT}} STREQUAL "")
  18. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_INIT "$ENV{ASM${ASM_DIALECT}}")
  19. endif()
  20. # finally list compilers to try
  21. if("ASM${ASM_DIALECT}" STREQUAL "ASM") # the generic assembler support
  22. if(NOT CMAKE_ASM_COMPILER_INIT)
  23. if(CMAKE_C_COMPILER)
  24. set(CMAKE_ASM_COMPILER "${CMAKE_C_COMPILER}" CACHE FILEPATH "The ASM compiler")
  25. set(CMAKE_ASM_COMPILER_ID "${CMAKE_C_COMPILER_ID}")
  26. elseif(CMAKE_CXX_COMPILER)
  27. set(CMAKE_ASM_COMPILER "${CMAKE_CXX_COMPILER}" CACHE FILEPATH "The ASM compiler")
  28. set(CMAKE_ASM_COMPILER_ID "${CMAKE_CXX_COMPILER_ID}")
  29. else()
  30. # List all default C and CXX compilers
  31. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_LIST
  32. ${_CMAKE_TOOLCHAIN_PREFIX}cc ${_CMAKE_TOOLCHAIN_PREFIX}gcc cl bcc xlc
  33. CC ${_CMAKE_TOOLCHAIN_PREFIX}c++ ${_CMAKE_TOOLCHAIN_PREFIX}g++ aCC cl bcc xlC)
  34. endif()
  35. endif()
  36. else() # some specific assembler "dialect"
  37. if(NOT CMAKE_ASM${ASM_DIALECT}_COMPILER_INIT AND NOT CMAKE_ASM${ASM_DIALECT}_COMPILER_LIST)
  38. message(FATAL_ERROR "CMAKE_ASM${ASM_DIALECT}_COMPILER_INIT or CMAKE_ASM${ASM_DIALECT}_COMPILER_LIST must be preset !")
  39. endif()
  40. endif()
  41. # Find the compiler.
  42. _cmake_find_compiler(ASM${ASM_DIALECT})
  43. else()
  44. _cmake_find_compiler_path(ASM${ASM_DIALECT})
  45. endif()
  46. mark_as_advanced(CMAKE_ASM${ASM_DIALECT}_COMPILER)
  47. if (NOT _CMAKE_TOOLCHAIN_LOCATION)
  48. get_filename_component(_CMAKE_TOOLCHAIN_LOCATION "${CMAKE_ASM${ASM_DIALECT}_COMPILER}" PATH)
  49. endif ()
  50. if(NOT CMAKE_ASM${ASM_DIALECT}_COMPILER_ID)
  51. # Table of per-vendor compiler id flags with expected output.
  52. list(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS GNU )
  53. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_GNU "--version")
  54. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_GNU "(GNU assembler)|(GCC)|(Free Software Foundation)")
  55. list(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS HP )
  56. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_HP "-V")
  57. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_HP "HP C")
  58. list(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS Intel )
  59. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_Intel "--version")
  60. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_Intel "(ICC)")
  61. list(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS SunPro )
  62. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_SunPro "-V")
  63. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_SunPro "Sun C")
  64. list(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS XL )
  65. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_XL "-qversion")
  66. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_XL "XL C")
  67. list(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS MSVC )
  68. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_MSVC "/?")
  69. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_MSVC "Microsoft")
  70. list(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS TI )
  71. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_TI "-h")
  72. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_TI "Texas Instruments")
  73. list(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS GNU IAR)
  74. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_IAR )
  75. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_IAR "IAR Assembler")
  76. list(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS ARMCC)
  77. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_ARMCC )
  78. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_ARMCC "(ARM Compiler)|(ARM Assembler)")
  79. include(CMakeDetermineCompilerId)
  80. CMAKE_DETERMINE_COMPILER_ID_VENDOR(ASM${ASM_DIALECT})
  81. endif()
  82. if(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID)
  83. message(STATUS "The ASM${ASM_DIALECT} compiler identification is ${CMAKE_ASM${ASM_DIALECT}_COMPILER_ID}")
  84. else()
  85. message(STATUS "The ASM${ASM_DIALECT} compiler identification is unknown")
  86. endif()
  87. # If we have a gas/as cross compiler, they have usually some prefix, like
  88. # e.g. powerpc-linux-gas, arm-elf-gas or i586-mingw32msvc-gas , optionally
  89. # with a 3-component version number at the end
  90. # The other tools of the toolchain usually have the same prefix
  91. # NAME_WE cannot be used since then this test will fail for names like
  92. # "arm-unknown-nto-qnx6.3.0-gas.exe", where BASENAME would be
  93. # "arm-unknown-nto-qnx6" instead of the correct "arm-unknown-nto-qnx6.3.0-"
  94. if (NOT _CMAKE_TOOLCHAIN_PREFIX)
  95. get_filename_component(COMPILER_BASENAME "${CMAKE_ASM${ASM_DIALECT}_COMPILER}" NAME)
  96. if (COMPILER_BASENAME MATCHES "^(.+-)g?as(-[0-9]+\\.[0-9]+\\.[0-9]+)?(\\.exe)?$")
  97. set(_CMAKE_TOOLCHAIN_PREFIX ${CMAKE_MATCH_1})
  98. endif ()
  99. endif ()
  100. # Now try the C compiler regexp:
  101. if (NOT _CMAKE_TOOLCHAIN_PREFIX)
  102. if (COMPILER_BASENAME MATCHES "^(.+-)g?cc(-[0-9]+\\.[0-9]+\\.[0-9]+)?(\\.exe)?$")
  103. set(_CMAKE_TOOLCHAIN_PREFIX ${CMAKE_MATCH_1})
  104. endif ()
  105. endif ()
  106. # Finally try the CXX compiler regexp:
  107. if (NOT _CMAKE_TOOLCHAIN_PREFIX)
  108. if (COMPILER_BASENAME MATCHES "^(.+-)[gc]\\+\\+(-[0-9]+\\.[0-9]+\\.[0-9]+)?(\\.exe)?$")
  109. set(_CMAKE_TOOLCHAIN_PREFIX ${CMAKE_MATCH_1})
  110. endif ()
  111. endif ()
  112. include(CMakeFindBinUtils)
  113. set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ENV_VAR "ASM${ASM_DIALECT}")
  114. if(CMAKE_ASM${ASM_DIALECT}_COMPILER)
  115. message(STATUS "Found assembler: ${CMAKE_ASM${ASM_DIALECT}_COMPILER}")
  116. else()
  117. message(STATUS "Didn't find assembler")
  118. endif()
  119. set(_CMAKE_ASM_COMPILER "${CMAKE_ASM${ASM_DIALECT}_COMPILER}")
  120. set(_CMAKE_ASM_COMPILER_ID "${CMAKE_ASM${ASM_DIALECT}_COMPILER_ID}")
  121. set(_CMAKE_ASM_COMPILER_ARG1 "${CMAKE_ASM${ASM_DIALECT}_COMPILER_ARG1}")
  122. set(_CMAKE_ASM_COMPILER_ENV_VAR "${CMAKE_ASM${ASM_DIALECT}_COMPILER_ENV_VAR}")
  123. # configure variables set in this file for fast reload later on
  124. configure_file(${CMAKE_ROOT}/Modules/CMakeASMCompiler.cmake.in
  125. ${CMAKE_PLATFORM_INFO_DIR}/CMakeASM${ASM_DIALECT}Compiler.cmake @ONLY)
  126. set(_CMAKE_ASM_COMPILER)
  127. set(_CMAKE_ASM_COMPILER_ARG1)
  128. set(_CMAKE_ASM_COMPILER_ENV_VAR)