CMakeDetermineASMCompiler.cmake 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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($ENV{ASM${ASM_DIALECT}} MATCHES ".+")
  18. SET(CMAKE_ASM${ASM_DIALECT}_COMPILER_INIT "$ENV{ASM${ASM_DIALECT}}")
  19. ENDIF($ENV{ASM${ASM_DIALECT}} MATCHES ".+")
  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 ${_CMAKE_TOOLCHAIN_PREFIX}gcc ${_CMAKE_TOOLCHAIN_PREFIX}cc cl bcc xlc
  32. ${_CMAKE_TOOLCHAIN_PREFIX}c++ ${_CMAKE_TOOLCHAIN_PREFIX}g++ CC aCC cl bcc xlC)
  33. ENDIF()
  34. ENDIF()
  35. ELSE() # some specific assembler "dialect"
  36. IF(NOT CMAKE_ASM${ASM_DIALECT}_COMPILER_INIT)
  37. MESSAGE(FATAL_ERROR "CMAKE_ASM${ASM_DIALECT}_COMPILER_INIT must be preset !")
  38. ENDIF()
  39. ENDIF()
  40. # Find the compiler.
  41. _cmake_find_compiler(ASM${ASM_DIALECT})
  42. ELSE(NOT CMAKE_ASM${ASM_DIALECT}_COMPILER)
  43. # we only get here if CMAKE_ASM${ASM_DIALECT}_COMPILER was specified using -D or a pre-made CMakeCache.txt
  44. # (e.g. via ctest) or set in CMAKE_TOOLCHAIN_FILE
  45. #
  46. # if a compiler was specified by the user but without path,
  47. # now try to find it with the full path
  48. # if it is found, force it into the cache,
  49. # if not, don't overwrite the setting (which was given by the user) with "NOTFOUND"
  50. GET_FILENAME_COMPONENT(_CMAKE_USER_ASM${ASM_DIALECT}_COMPILER_PATH "${CMAKE_ASM${ASM_DIALECT}_COMPILER}" PATH)
  51. IF(NOT _CMAKE_USER_ASM${ASM_DIALECT}_COMPILER_PATH)
  52. FIND_PROGRAM(CMAKE_ASM${ASM_DIALECT}_COMPILER_WITH_PATH NAMES ${CMAKE_ASM${ASM_DIALECT}_COMPILER})
  53. MARK_AS_ADVANCED(CMAKE_ASM${ASM_DIALECT}_COMPILER_WITH_PATH)
  54. IF(CMAKE_ASM${ASM_DIALECT}_COMPILER_WITH_PATH)
  55. SET(CMAKE_ASM${ASM_DIALECT}_COMPILER ${CMAKE_ASM${ASM_DIALECT}_COMPILER_WITH_PATH} CACHE FILEPATH "Assembler" FORCE)
  56. ENDIF(CMAKE_ASM${ASM_DIALECT}_COMPILER_WITH_PATH)
  57. ENDIF(NOT _CMAKE_USER_ASM${ASM_DIALECT}_COMPILER_PATH)
  58. ENDIF(NOT CMAKE_ASM${ASM_DIALECT}_COMPILER)
  59. MARK_AS_ADVANCED(CMAKE_ASM${ASM_DIALECT}_COMPILER)
  60. IF (NOT _CMAKE_TOOLCHAIN_LOCATION)
  61. GET_FILENAME_COMPONENT(_CMAKE_TOOLCHAIN_LOCATION "${CMAKE_ASM${ASM_DIALECT}_COMPILER}" PATH)
  62. ENDIF (NOT _CMAKE_TOOLCHAIN_LOCATION)
  63. IF(NOT CMAKE_ASM${ASM_DIALECT}_COMPILER_ID)
  64. # Table of per-vendor compiler id flags with expected output.
  65. LIST(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS GNU )
  66. SET(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_GNU "--version")
  67. SET(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_GNU "(GNU assembler)|(GCC)|(Free Software Foundation)")
  68. LIST(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS HP )
  69. SET(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_HP "-V")
  70. SET(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_HP "HP C")
  71. LIST(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS Intel )
  72. SET(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_Intel "--version")
  73. SET(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_Intel "(ICC)")
  74. LIST(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS SunPro )
  75. SET(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_SunPro "-V")
  76. SET(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_SunPro "Sun C")
  77. LIST(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS XL )
  78. SET(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_XL "-qversion")
  79. SET(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_XL "XL C")
  80. LIST(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS MSVC )
  81. SET(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_MSVC "/?")
  82. SET(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_MSVC "Microsoft")
  83. LIST(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS TI_DSP )
  84. SET(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_TI_DSP "-h")
  85. SET(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_TI_DSP "Texas Instruments")
  86. INCLUDE(CMakeDetermineCompilerId)
  87. CMAKE_DETERMINE_COMPILER_ID_VENDOR(ASM${ASM_DIALECT})
  88. ENDIF()
  89. IF(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID)
  90. MESSAGE(STATUS "The ASM${ASM_DIALECT} compiler identification is ${CMAKE_ASM${ASM_DIALECT}_COMPILER_ID}")
  91. ELSE(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID)
  92. MESSAGE(STATUS "The ASM${ASM_DIALECT} compiler identification is unknown")
  93. ENDIF(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID)
  94. # If we have a gas/as cross compiler, they have usually some prefix, like
  95. # e.g. powerpc-linux-gas, arm-elf-gas or i586-mingw32msvc-gas , optionally
  96. # with a 3-component version number at the end
  97. # The other tools of the toolchain usually have the same prefix
  98. # NAME_WE cannot be used since then this test will fail for names lile
  99. # "arm-unknown-nto-qnx6.3.0-gas.exe", where BASENAME would be
  100. # "arm-unknown-nto-qnx6" instead of the correct "arm-unknown-nto-qnx6.3.0-"
  101. IF (NOT _CMAKE_TOOLCHAIN_PREFIX)
  102. GET_FILENAME_COMPONENT(COMPILER_BASENAME "${CMAKE_ASM${ASM_DIALECT}_COMPILER}" NAME)
  103. IF (COMPILER_BASENAME MATCHES "^(.+-)g?as(-[0-9]+\\.[0-9]+\\.[0-9]+)?(\\.exe)?$")
  104. SET(_CMAKE_TOOLCHAIN_PREFIX ${CMAKE_MATCH_1})
  105. ENDIF (COMPILER_BASENAME MATCHES "^(.+-)g?as(-[0-9]+\\.[0-9]+\\.[0-9]+)?(\\.exe)?$")
  106. ENDIF (NOT _CMAKE_TOOLCHAIN_PREFIX)
  107. # Now try the C compiler regexp:
  108. IF (NOT _CMAKE_TOOLCHAIN_PREFIX)
  109. IF (COMPILER_BASENAME MATCHES "^(.+-)g?cc(-[0-9]+\\.[0-9]+\\.[0-9]+)?(\\.exe)?$")
  110. SET(_CMAKE_TOOLCHAIN_PREFIX ${CMAKE_MATCH_1})
  111. ENDIF (COMPILER_BASENAME MATCHES "^(.+-)g?cc(-[0-9]+\\.[0-9]+\\.[0-9]+)?(\\.exe)?$")
  112. ENDIF (NOT _CMAKE_TOOLCHAIN_PREFIX)
  113. # Finally try the CXX compiler regexp:
  114. IF (NOT _CMAKE_TOOLCHAIN_PREFIX)
  115. IF (COMPILER_BASENAME MATCHES "^(.+-)[gc]\\+\\+(-[0-9]+\\.[0-9]+\\.[0-9]+)?(\\.exe)?$")
  116. SET(_CMAKE_TOOLCHAIN_PREFIX ${CMAKE_MATCH_1})
  117. ENDIF (COMPILER_BASENAME MATCHES "^(.+-)[gc]\\+\\+(-[0-9]+\\.[0-9]+\\.[0-9]+)?(\\.exe)?$")
  118. ENDIF (NOT _CMAKE_TOOLCHAIN_PREFIX)
  119. INCLUDE(CMakeFindBinUtils)
  120. SET(CMAKE_ASM${ASM_DIALECT}_COMPILER_ENV_VAR "ASM${ASM_DIALECT}")
  121. IF(CMAKE_ASM${ASM_DIALECT}_COMPILER)
  122. MESSAGE(STATUS "Found assembler: ${CMAKE_ASM${ASM_DIALECT}_COMPILER}")
  123. ELSE(CMAKE_ASM${ASM_DIALECT}_COMPILER)
  124. MESSAGE(STATUS "Didn't find assembler")
  125. ENDIF(CMAKE_ASM${ASM_DIALECT}_COMPILER)
  126. SET(_CMAKE_ASM_COMPILER "${CMAKE_ASM${ASM_DIALECT}_COMPILER}")
  127. SET(_CMAKE_ASM_COMPILER_ID "${CMAKE_ASM${ASM_DIALECT}_COMPILER_ID}")
  128. SET(_CMAKE_ASM_COMPILER_ARG1 "${CMAKE_ASM${ASM_DIALECT}_COMPILER_ARG1}")
  129. SET(_CMAKE_ASM_COMPILER_ENV_VAR "${CMAKE_ASM${ASM_DIALECT}_COMPILER_ENV_VAR}")
  130. # configure variables set in this file for fast reload later on
  131. CONFIGURE_FILE(${CMAKE_ROOT}/Modules/CMakeASMCompiler.cmake.in
  132. ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeASM${ASM_DIALECT}Compiler.cmake IMMEDIATE @ONLY)
  133. SET(_CMAKE_ASM_COMPILER)
  134. SET(_CMAKE_ASM_COMPILER_ARG1)
  135. SET(_CMAKE_ASM_COMPILER_ENV_VAR)