CMakeDetermineASMCompiler.cmake 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. IF(NOT CMAKE_ASM${ASM_DIALECT}_COMPILER)
  15. # prefer the environment variable ASM
  16. IF($ENV{ASM${ASM_DIALECT}} MATCHES ".+")
  17. SET(CMAKE_ASM${ASM_DIALECT}_COMPILER_INIT "$ENV{ASM${ASM_DIALECT}}")
  18. ENDIF($ENV{ASM${ASM_DIALECT}} MATCHES ".+")
  19. # finally list compilers to try
  20. IF(CMAKE_ASM${ASM_DIALECT}_COMPILER_INIT)
  21. SET(CMAKE_ASM${ASM_DIALECT}_COMPILER_LIST ${CMAKE_ASM${ASM_DIALECT}_COMPILER_INIT})
  22. ELSE(CMAKE_ASM${ASM_DIALECT}_COMPILER_INIT)
  23. SET(CMAKE_ASM${ASM_DIALECT}_COMPILER_LIST ${_CMAKE_TOOLCHAIN_PREFIX}as ${_CMAKE_TOOLCHAIN_PREFIX}gas)
  24. ENDIF(CMAKE_ASM${ASM_DIALECT}_COMPILER_INIT)
  25. # Find the compiler.
  26. IF (_CMAKE_USER_CXX_COMPILER_PATH OR _CMAKE_USER_C_COMPILER_PATH)
  27. FIND_PROGRAM(CMAKE_ASM${ASM_DIALECT}_COMPILER NAMES ${CMAKE_ASM${ASM_DIALECT}_COMPILER_LIST} PATHS ${_CMAKE_USER_C_COMPILER_PATH} ${_CMAKE_USER_CXX_COMPILER_PATH} DOC "Assembler" NO_DEFAULT_PATH)
  28. ENDIF (_CMAKE_USER_CXX_COMPILER_PATH OR _CMAKE_USER_C_COMPILER_PATH)
  29. FIND_PROGRAM(CMAKE_ASM${ASM_DIALECT}_COMPILER NAMES ${CMAKE_ASM${ASM_DIALECT}_COMPILER_LIST} PATHS ${_CMAKE_TOOLCHAIN_LOCATION} DOC "Assembler")
  30. ELSE(NOT CMAKE_ASM${ASM_DIALECT}_COMPILER)
  31. # we only get here if CMAKE_ASM${ASM_DIALECT}_COMPILER was specified using -D or a pre-made CMakeCache.txt
  32. # (e.g. via ctest) or set in CMAKE_TOOLCHAIN_FILE
  33. #
  34. # if a compiler was specified by the user but without path,
  35. # now try to find it with the full path
  36. # if it is found, force it into the cache,
  37. # if not, don't overwrite the setting (which was given by the user) with "NOTFOUND"
  38. GET_FILENAME_COMPONENT(_CMAKE_USER_ASM${ASM_DIALECT}_COMPILER_PATH "${CMAKE_ASM${ASM_DIALECT}_COMPILER}" PATH)
  39. IF(NOT _CMAKE_USER_ASM${ASM_DIALECT}_COMPILER_PATH)
  40. FIND_PROGRAM(CMAKE_ASM${ASM_DIALECT}_COMPILER_WITH_PATH NAMES ${CMAKE_ASM${ASM_DIALECT}_COMPILER})
  41. MARK_AS_ADVANCED(CMAKE_ASM${ASM_DIALECT}_COMPILER_WITH_PATH)
  42. IF(CMAKE_ASM${ASM_DIALECT}_COMPILER_WITH_PATH)
  43. SET(CMAKE_ASM${ASM_DIALECT}_COMPILER ${CMAKE_ASM${ASM_DIALECT}_COMPILER_WITH_PATH} CACHE FILEPATH "Assembler" FORCE)
  44. ENDIF(CMAKE_ASM${ASM_DIALECT}_COMPILER_WITH_PATH)
  45. ENDIF(NOT _CMAKE_USER_ASM${ASM_DIALECT}_COMPILER_PATH)
  46. ENDIF(NOT CMAKE_ASM${ASM_DIALECT}_COMPILER)
  47. MARK_AS_ADVANCED(CMAKE_ASM${ASM_DIALECT}_COMPILER)
  48. IF (NOT _CMAKE_TOOLCHAIN_LOCATION)
  49. GET_FILENAME_COMPONENT(_CMAKE_TOOLCHAIN_LOCATION "${CMAKE_ASM${ASM_DIALECT}_COMPILER}" PATH)
  50. ENDIF (NOT _CMAKE_TOOLCHAIN_LOCATION)
  51. IF(NOT CMAKE_ASM${ASM_DIALECT}_COMPILER_ID)
  52. # Table of per-vendor compiler id flags with expected output.
  53. LIST(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS GNU )
  54. SET(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_GNU "--version")
  55. SET(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_GNU "GNU assembler")
  56. INCLUDE(CMakeDetermineCompilerId)
  57. CMAKE_DETERMINE_COMPILER_ID_VENDOR(ASM${ASM_DIALECT})
  58. IF(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID)
  59. MESSAGE(STATUS "The ASM${ASM_DIALECT} compiler identification is ${CMAKE_ASM${ASM_DIALECT}_COMPILER_ID}")
  60. ELSE(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID)
  61. MESSAGE(STATUS "The ASM${ASM_DIALECT} compiler identification is unknown")
  62. ENDIF(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID)
  63. ENDIF()
  64. # If we have a gas/as cross compiler, they have usually some prefix, like
  65. # e.g. powerpc-linux-gas, arm-elf-gas or i586-mingw32msvc-gas .
  66. # The other tools of the toolchain usually have the same prefix
  67. # NAME_WE cannot be used since then this test will fail for names lile
  68. # "arm-unknown-nto-qnx6.3.0-gas.exe", where BASENAME would be
  69. # "arm-unknown-nto-qnx6" instead of the correct "arm-unknown-nto-qnx6.3.0-"
  70. IF (NOT _CMAKE_TOOLCHAIN_PREFIX)
  71. GET_FILENAME_COMPONENT(COMPILER_BASENAME "${CMAKE_ASM${ASM_DIALECT}_COMPILER}" NAME)
  72. IF (COMPILER_BASENAME MATCHES "^(.+-)g?as(\\.exe)?$")
  73. STRING(REGEX REPLACE "^(.+-)g?as(\\.exe)?$" "\\1" _CMAKE_TOOLCHAIN_PREFIX "${COMPILER_BASENAME}")
  74. ENDIF (COMPILER_BASENAME MATCHES "^(.+-)g?as(\\.exe)?$")
  75. ENDIF (NOT _CMAKE_TOOLCHAIN_PREFIX)
  76. INCLUDE(CMakeFindBinUtils)
  77. SET(CMAKE_ASM${ASM_DIALECT}_COMPILER_ENV_VAR "ASM${ASM_DIALECT}")
  78. IF(CMAKE_ASM${ASM_DIALECT}_COMPILER)
  79. MESSAGE(STATUS "Found assembler: ${CMAKE_ASM${ASM_DIALECT}_COMPILER}")
  80. ELSE(CMAKE_ASM${ASM_DIALECT}_COMPILER)
  81. MESSAGE(STATUS "Didn't find assembler")
  82. ENDIF(CMAKE_ASM${ASM_DIALECT}_COMPILER)
  83. SET(_CMAKE_ASM_COMPILER "${CMAKE_ASM${ASM_DIALECT}_COMPILER}")
  84. SET(_CMAKE_ASM_COMPILER_ARG1 "${CMAKE_ASM${ASM_DIALECT}_COMPILER_ARG1}")
  85. SET(_CMAKE_ASM_COMPILER_ENV_VAR "${CMAKE_ASM${ASM_DIALECT}_COMPILER_ENV_VAR}")
  86. # configure variables set in this file for fast reload later on
  87. CONFIGURE_FILE(${CMAKE_ROOT}/Modules/CMakeASMCompiler.cmake.in
  88. ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeASM${ASM_DIALECT}Compiler.cmake IMMEDIATE @ONLY)
  89. SET(_CMAKE_ASM_COMPILER)
  90. SET(_CMAKE_ASM_COMPILER_ARG1)
  91. SET(_CMAKE_ASM_COMPILER_ENV_VAR)