2 #=============================================================================
3 # Copyright 2007-2009 Kitware, Inc.
5 # Distributed under the OSI-approved BSD License (the "License");
6 # see accompanying file Copyright.txt for details.
8 # This software is distributed WITHOUT ANY WARRANTY; without even the
9 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 # See the License for more information.
11 #=============================================================================
12 # (To distribute this file outside of CMake, substitute the full
13 # License text for the above reference.)
15 # determine the compiler to use for ASM programs
17 include(${CMAKE_ROOT}/Modules/CMakeDetermineCompiler.cmake)
19 if(NOT CMAKE_ASM${ASM_DIALECT}_COMPILER)
20 # prefer the environment variable ASM
21 if($ENV{ASM${ASM_DIALECT}} MATCHES ".+")
22 set(CMAKE_ASM${ASM_DIALECT}_COMPILER_INIT "$ENV{ASM${ASM_DIALECT}}")
25 # finally list compilers to try
26 if("ASM${ASM_DIALECT}" STREQUAL "ASM") # the generic assembler support
27 if(NOT CMAKE_ASM_COMPILER_INIT)
29 set(CMAKE_ASM_COMPILER "${CMAKE_C_COMPILER}" CACHE FILEPATH "The ASM compiler")
30 set(CMAKE_ASM_COMPILER_ID "${CMAKE_C_COMPILER_ID}")
31 elseif(CMAKE_CXX_COMPILER)
32 set(CMAKE_ASM_COMPILER "${CMAKE_CXX_COMPILER}" CACHE FILEPATH "The ASM compiler")
33 set(CMAKE_ASM_COMPILER_ID "${CMAKE_CXX_COMPILER_ID}")
35 # List all default C and CXX compilers
36 set(CMAKE_ASM${ASM_DIALECT}_COMPILER_LIST
37 ${_CMAKE_TOOLCHAIN_PREFIX}cc ${_CMAKE_TOOLCHAIN_PREFIX}gcc cl bcc xlc
38 CC ${_CMAKE_TOOLCHAIN_PREFIX}c++ ${_CMAKE_TOOLCHAIN_PREFIX}g++ aCC cl bcc xlC)
41 else() # some specific assembler "dialect"
42 if(NOT CMAKE_ASM${ASM_DIALECT}_COMPILER_INIT)
43 message(FATAL_ERROR "CMAKE_ASM${ASM_DIALECT}_COMPILER_INIT must be preset !")
48 _cmake_find_compiler(ASM${ASM_DIALECT})
52 # we only get here if CMAKE_ASM${ASM_DIALECT}_COMPILER was specified using -D or a pre-made CMakeCache.txt
53 # (e.g. via ctest) or set in CMAKE_TOOLCHAIN_FILE
55 # if a compiler was specified by the user but without path,
56 # now try to find it with the full path
57 # if it is found, force it into the cache,
58 # if not, don't overwrite the setting (which was given by the user) with "NOTFOUND"
59 get_filename_component(_CMAKE_USER_ASM${ASM_DIALECT}_COMPILER_PATH "${CMAKE_ASM${ASM_DIALECT}_COMPILER}" PATH)
60 if(NOT _CMAKE_USER_ASM${ASM_DIALECT}_COMPILER_PATH)
61 find_program(CMAKE_ASM${ASM_DIALECT}_COMPILER_WITH_PATH NAMES ${CMAKE_ASM${ASM_DIALECT}_COMPILER})
62 mark_as_advanced(CMAKE_ASM${ASM_DIALECT}_COMPILER_WITH_PATH)
63 if(CMAKE_ASM${ASM_DIALECT}_COMPILER_WITH_PATH)
64 set(CMAKE_ASM${ASM_DIALECT}_COMPILER ${CMAKE_ASM${ASM_DIALECT}_COMPILER_WITH_PATH} CACHE FILEPATH "Assembler" FORCE)
68 mark_as_advanced(CMAKE_ASM${ASM_DIALECT}_COMPILER)
70 if (NOT _CMAKE_TOOLCHAIN_LOCATION)
71 get_filename_component(_CMAKE_TOOLCHAIN_LOCATION "${CMAKE_ASM${ASM_DIALECT}_COMPILER}" PATH)
75 if(NOT CMAKE_ASM${ASM_DIALECT}_COMPILER_ID)
77 # Table of per-vendor compiler id flags with expected output.
78 list(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS GNU )
79 set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_GNU "--version")
80 set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_GNU "(GNU assembler)|(GCC)|(Free Software Foundation)")
82 list(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS HP )
83 set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_HP "-V")
84 set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_HP "HP C")
86 list(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS Intel )
87 set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_Intel "--version")
88 set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_Intel "(ICC)")
90 list(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS SunPro )
91 set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_SunPro "-V")
92 set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_SunPro "Sun C")
94 list(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS XL )
95 set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_XL "-qversion")
96 set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_XL "XL C")
98 list(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS MSVC )
99 set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_MSVC "/?")
100 set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_MSVC "Microsoft")
102 list(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS TI_DSP )
103 set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_TI_DSP "-h")
104 set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_TI_DSP "Texas Instruments")
106 include(CMakeDetermineCompilerId)
107 CMAKE_DETERMINE_COMPILER_ID_VENDOR(ASM${ASM_DIALECT})
111 if(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID)
112 message(STATUS "The ASM${ASM_DIALECT} compiler identification is ${CMAKE_ASM${ASM_DIALECT}_COMPILER_ID}")
114 message(STATUS "The ASM${ASM_DIALECT} compiler identification is unknown")
119 # If we have a gas/as cross compiler, they have usually some prefix, like
120 # e.g. powerpc-linux-gas, arm-elf-gas or i586-mingw32msvc-gas , optionally
121 # with a 3-component version number at the end
122 # The other tools of the toolchain usually have the same prefix
123 # NAME_WE cannot be used since then this test will fail for names lile
124 # "arm-unknown-nto-qnx6.3.0-gas.exe", where BASENAME would be
125 # "arm-unknown-nto-qnx6" instead of the correct "arm-unknown-nto-qnx6.3.0-"
126 if (NOT _CMAKE_TOOLCHAIN_PREFIX)
127 get_filename_component(COMPILER_BASENAME "${CMAKE_ASM${ASM_DIALECT}_COMPILER}" NAME)
128 if (COMPILER_BASENAME MATCHES "^(.+-)g?as(-[0-9]+\\.[0-9]+\\.[0-9]+)?(\\.exe)?$")
129 set(_CMAKE_TOOLCHAIN_PREFIX ${CMAKE_MATCH_1})
133 # Now try the C compiler regexp:
134 if (NOT _CMAKE_TOOLCHAIN_PREFIX)
135 if (COMPILER_BASENAME MATCHES "^(.+-)g?cc(-[0-9]+\\.[0-9]+\\.[0-9]+)?(\\.exe)?$")
136 set(_CMAKE_TOOLCHAIN_PREFIX ${CMAKE_MATCH_1})
140 # Finally try the CXX compiler regexp:
141 if (NOT _CMAKE_TOOLCHAIN_PREFIX)
142 if (COMPILER_BASENAME MATCHES "^(.+-)[gc]\\+\\+(-[0-9]+\\.[0-9]+\\.[0-9]+)?(\\.exe)?$")
143 set(_CMAKE_TOOLCHAIN_PREFIX ${CMAKE_MATCH_1})
148 include(CMakeFindBinUtils)
150 set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ENV_VAR "ASM${ASM_DIALECT}")
152 if(CMAKE_ASM${ASM_DIALECT}_COMPILER)
153 message(STATUS "Found assembler: ${CMAKE_ASM${ASM_DIALECT}_COMPILER}")
155 message(STATUS "Didn't find assembler")
159 set(_CMAKE_ASM_COMPILER "${CMAKE_ASM${ASM_DIALECT}_COMPILER}")
160 set(_CMAKE_ASM_COMPILER_ID "${CMAKE_ASM${ASM_DIALECT}_COMPILER_ID}")
161 set(_CMAKE_ASM_COMPILER_ARG1 "${CMAKE_ASM${ASM_DIALECT}_COMPILER_ARG1}")
162 set(_CMAKE_ASM_COMPILER_ENV_VAR "${CMAKE_ASM${ASM_DIALECT}_COMPILER_ENV_VAR}")
164 # configure variables set in this file for fast reload later on
165 configure_file(${CMAKE_ROOT}/Modules/CMakeASMCompiler.cmake.in
166 ${CMAKE_PLATFORM_INFO_DIR}/CMakeASM${ASM_DIALECT}Compiler.cmake IMMEDIATE @ONLY)
168 set(_CMAKE_ASM_COMPILER)
169 set(_CMAKE_ASM_COMPILER_ARG1)
170 set(_CMAKE_ASM_COMPILER_ENV_VAR)