CMakeDetermineCompilerId.cmake 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. # Function to compile a source file to identify the compiler. This is
  4. # used internally by CMake and should not be included by user code.
  5. # If successful, sets CMAKE_<lang>_COMPILER_ID and CMAKE_<lang>_PLATFORM_ID
  6. function(CMAKE_DETERMINE_COMPILER_ID lang flagvar src)
  7. # Make sure the compiler arguments are clean.
  8. string(STRIP "${CMAKE_${lang}_COMPILER_ARG1}" CMAKE_${lang}_COMPILER_ID_ARG1)
  9. string(REGEX REPLACE " +" ";" CMAKE_${lang}_COMPILER_ID_ARG1 "${CMAKE_${lang}_COMPILER_ID_ARG1}")
  10. # Make sure user-specified compiler flags are used.
  11. if(CMAKE_${lang}_FLAGS)
  12. set(CMAKE_${lang}_COMPILER_ID_FLAGS ${CMAKE_${lang}_FLAGS})
  13. else()
  14. set(CMAKE_${lang}_COMPILER_ID_FLAGS $ENV{${flagvar}})
  15. endif()
  16. string(REPLACE " " ";" CMAKE_${lang}_COMPILER_ID_FLAGS_LIST "${CMAKE_${lang}_COMPILER_ID_FLAGS}")
  17. # Compute the directory in which to run the test.
  18. set(CMAKE_${lang}_COMPILER_ID_DIR ${CMAKE_PLATFORM_INFO_DIR}/CompilerId${lang})
  19. # Try building with no extra flags and then try each set
  20. # of helper flags. Stop when the compiler is identified.
  21. foreach(userflags "${CMAKE_${lang}_COMPILER_ID_FLAGS_LIST}" "")
  22. foreach(testflags ${CMAKE_${lang}_COMPILER_ID_TEST_FLAGS_FIRST}
  23. ""
  24. ${CMAKE_${lang}_COMPILER_ID_TEST_FLAGS})
  25. separate_arguments(testflags UNIX_COMMAND "${testflags}")
  26. CMAKE_DETERMINE_COMPILER_ID_BUILD("${lang}" "${testflags}" "${userflags}" "${src}")
  27. CMAKE_DETERMINE_COMPILER_ID_MATCH_VENDOR("${lang}" "${COMPILER_${lang}_PRODUCED_OUTPUT}")
  28. if(CMAKE_${lang}_COMPILER_ID)
  29. break()
  30. endif()
  31. foreach(file ${COMPILER_${lang}_PRODUCED_FILES})
  32. CMAKE_DETERMINE_COMPILER_ID_CHECK("${lang}" "${CMAKE_${lang}_COMPILER_ID_DIR}/${file}" "${src}")
  33. endforeach()
  34. if(CMAKE_${lang}_COMPILER_ID)
  35. break()
  36. endif()
  37. endforeach()
  38. if(CMAKE_${lang}_COMPILER_ID)
  39. break()
  40. endif()
  41. endforeach()
  42. # Check if compiler id detection gave us the compiler tool.
  43. if(CMAKE_${lang}_COMPILER_ID_TOOL)
  44. set(CMAKE_${lang}_COMPILER "${CMAKE_${lang}_COMPILER_ID_TOOL}")
  45. set(CMAKE_${lang}_COMPILER "${CMAKE_${lang}_COMPILER_ID_TOOL}" PARENT_SCOPE)
  46. elseif(NOT CMAKE_${lang}_COMPILER)
  47. set(CMAKE_${lang}_COMPILER "CMAKE_${lang}_COMPILER-NOTFOUND" PARENT_SCOPE)
  48. endif()
  49. # If the compiler is still unknown, try to query its vendor.
  50. if(CMAKE_${lang}_COMPILER AND NOT CMAKE_${lang}_COMPILER_ID)
  51. foreach(userflags "${CMAKE_${lang}_COMPILER_ID_FLAGS_LIST}" "")
  52. CMAKE_DETERMINE_COMPILER_ID_VENDOR(${lang} "${userflags}")
  53. endforeach()
  54. endif()
  55. # If the compiler is still unknown, fallback to GHS
  56. if(NOT CMAKE_${lang}_COMPILER_ID AND "${CMAKE_GENERATOR}" MATCHES "Green Hills MULTI")
  57. set(CMAKE_${lang}_COMPILER_ID GHS)
  58. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
  59. "The ${lang} compiler identification is falling back to GHS.\n\n")
  60. endif()
  61. # CUDA < 7.5 is missing version macros
  62. if(lang STREQUAL "CUDA"
  63. AND CMAKE_${lang}_COMPILER_ID STREQUAL "NVIDIA"
  64. AND NOT CMAKE_${lang}_COMPILER_VERSION)
  65. execute_process(
  66. COMMAND "${CMAKE_${lang}_COMPILER}"
  67. --version
  68. OUTPUT_VARIABLE output ERROR_VARIABLE output
  69. RESULT_VARIABLE result
  70. TIMEOUT 10
  71. )
  72. if(output MATCHES [=[ V([0-9]+)\.([0-9]+)\.([0-9]+)]=])
  73. set(CMAKE_${lang}_COMPILER_VERSION "${CMAKE_MATCH_1}.${CMAKE_MATCH_2}.${CMAKE_MATCH_3}")
  74. endif()
  75. endif()
  76. # For Swift we need to explicitly query the version.
  77. if(lang STREQUAL "Swift"
  78. AND CMAKE_${lang}_COMPILER
  79. AND NOT CMAKE_${lang}_COMPILER_VERSION)
  80. execute_process(
  81. COMMAND "${CMAKE_${lang}_COMPILER}"
  82. -version
  83. OUTPUT_VARIABLE output ERROR_VARIABLE output
  84. RESULT_VARIABLE result
  85. TIMEOUT 10
  86. )
  87. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
  88. "Running the ${lang} compiler: \"${CMAKE_${lang}_COMPILER}\" -version\n"
  89. "${output}\n"
  90. )
  91. if(output MATCHES [[Swift version ([0-9]+\.[0-9]+(\.[0-9]+)?)]])
  92. set(CMAKE_${lang}_COMPILER_VERSION "${CMAKE_MATCH_1}")
  93. if(NOT CMAKE_${lang}_COMPILER_ID)
  94. set(CMAKE_Swift_COMPILER_ID "Apple")
  95. endif()
  96. endif()
  97. endif()
  98. if (COMPILER_QNXNTO AND CMAKE_${lang}_COMPILER_ID STREQUAL "GNU")
  99. execute_process(
  100. COMMAND "${CMAKE_${lang}_COMPILER}"
  101. -V
  102. OUTPUT_VARIABLE output ERROR_VARIABLE output
  103. RESULT_VARIABLE result
  104. TIMEOUT 10
  105. )
  106. if (output MATCHES "targets available")
  107. set(CMAKE_${lang}_COMPILER_ID QCC)
  108. # http://community.qnx.com/sf/discussion/do/listPosts/projects.community/discussion.qnx_momentics_community_support.topc3555?_pagenum=2
  109. # The qcc driver does not itself have a version.
  110. endif()
  111. endif()
  112. # if the format is unknown after all files have been checked, put "Unknown" in the cache
  113. if(NOT CMAKE_EXECUTABLE_FORMAT)
  114. set(CMAKE_EXECUTABLE_FORMAT "Unknown" CACHE INTERNAL "Executable file format")
  115. endif()
  116. if(CMAKE_GENERATOR STREQUAL "Ninja" AND MSVC_${lang}_ARCHITECTURE_ID)
  117. foreach(userflags "${CMAKE_${lang}_COMPILER_ID_FLAGS_LIST}" "")
  118. CMAKE_DETERMINE_MSVC_SHOWINCLUDES_PREFIX(${lang} "${userflags}")
  119. endforeach()
  120. else()
  121. set(CMAKE_${lang}_CL_SHOWINCLUDES_PREFIX "")
  122. endif()
  123. set(_variant "")
  124. if("x${CMAKE_${lang}_COMPILER_ID}" STREQUAL "xClang")
  125. if("x${CMAKE_${lang}_SIMULATE_ID}" STREQUAL "xMSVC")
  126. if(CMAKE_GENERATOR MATCHES "Visual Studio")
  127. set(CMAKE_${lang}_COMPILER_FRONTEND_VARIANT "MSVC")
  128. else()
  129. # Test whether an MSVC-like command-line option works.
  130. execute_process(COMMAND "${CMAKE_${lang}_COMPILER}" -?
  131. RESULT_VARIABLE _clang_result
  132. OUTPUT_VARIABLE _clang_stdout
  133. ERROR_VARIABLE _clang_stderr)
  134. if(_clang_result EQUAL 0)
  135. set(CMAKE_${lang}_COMPILER_FRONTEND_VARIANT "MSVC")
  136. else()
  137. set(CMAKE_${lang}_COMPILER_FRONTEND_VARIANT "GNU")
  138. endif()
  139. endif()
  140. set(_variant " with ${CMAKE_${lang}_COMPILER_FRONTEND_VARIANT}-like command-line")
  141. else()
  142. set(CMAKE_${lang}_COMPILER_FRONTEND_VARIANT "GNU")
  143. endif()
  144. else()
  145. set(CMAKE_${lang}_COMPILER_FRONTEND_VARIANT "")
  146. endif()
  147. # Display the final identification result.
  148. if(CMAKE_${lang}_COMPILER_ID)
  149. if(CMAKE_${lang}_COMPILER_VERSION)
  150. set(_version " ${CMAKE_${lang}_COMPILER_VERSION}")
  151. else()
  152. set(_version "")
  153. endif()
  154. if(CMAKE_${lang}_COMPILER_ARCHITECTURE_ID AND "x${CMAKE_${lang}_COMPILER_ID}" STREQUAL "xIAR")
  155. set(_archid " ${CMAKE_${lang}_COMPILER_ARCHITECTURE_ID}")
  156. else()
  157. set(_archid "")
  158. endif()
  159. message(STATUS "The ${lang} compiler identification is "
  160. "${CMAKE_${lang}_COMPILER_ID}${_archid}${_version}${_variant}")
  161. unset(_archid)
  162. unset(_version)
  163. unset(_variant)
  164. else()
  165. message(STATUS "The ${lang} compiler identification is unknown")
  166. endif()
  167. set(CMAKE_${lang}_COMPILER_ID "${CMAKE_${lang}_COMPILER_ID}" PARENT_SCOPE)
  168. set(CMAKE_${lang}_PLATFORM_ID "${CMAKE_${lang}_PLATFORM_ID}" PARENT_SCOPE)
  169. set(CMAKE_${lang}_COMPILER_ARCHITECTURE_ID "${CMAKE_${lang}_COMPILER_ARCHITECTURE_ID}" PARENT_SCOPE)
  170. set(MSVC_${lang}_ARCHITECTURE_ID "${MSVC_${lang}_ARCHITECTURE_ID}"
  171. PARENT_SCOPE)
  172. set(CMAKE_${lang}_XCODE_ARCHS "${CMAKE_${lang}_XCODE_ARCHS}" PARENT_SCOPE)
  173. set(CMAKE_${lang}_CL_SHOWINCLUDES_PREFIX "${CMAKE_${lang}_CL_SHOWINCLUDES_PREFIX}" PARENT_SCOPE)
  174. set(CMAKE_${lang}_COMPILER_FRONTEND_VARIANT "${CMAKE_${lang}_COMPILER_FRONTEND_VARIANT}" PARENT_SCOPE)
  175. set(CMAKE_${lang}_COMPILER_VERSION "${CMAKE_${lang}_COMPILER_VERSION}" PARENT_SCOPE)
  176. set(CMAKE_${lang}_COMPILER_VERSION_INTERNAL "${CMAKE_${lang}_COMPILER_VERSION_INTERNAL}" PARENT_SCOPE)
  177. set(CMAKE_${lang}_COMPILER_WRAPPER "${CMAKE_${lang}_COMPILER_WRAPPER}" PARENT_SCOPE)
  178. set(CMAKE_${lang}_SIMULATE_ID "${CMAKE_${lang}_SIMULATE_ID}" PARENT_SCOPE)
  179. set(CMAKE_${lang}_SIMULATE_VERSION "${CMAKE_${lang}_SIMULATE_VERSION}" PARENT_SCOPE)
  180. set(CMAKE_${lang}_STANDARD_COMPUTED_DEFAULT "${CMAKE_${lang}_STANDARD_COMPUTED_DEFAULT}" PARENT_SCOPE)
  181. set(CMAKE_${lang}_COMPILER_PRODUCED_OUTPUT "${COMPILER_${lang}_PRODUCED_OUTPUT}" PARENT_SCOPE)
  182. set(CMAKE_${lang}_COMPILER_PRODUCED_FILES "${COMPILER_${lang}_PRODUCED_FILES}" PARENT_SCOPE)
  183. endfunction()
  184. include(CMakeCompilerIdDetection)
  185. #-----------------------------------------------------------------------------
  186. # Function to write the compiler id source file.
  187. function(CMAKE_DETERMINE_COMPILER_ID_WRITE lang src)
  188. find_file(src_in ${src}.in PATHS ${CMAKE_ROOT}/Modules ${CMAKE_MODULE_PATH} NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
  189. file(READ ${src_in} ID_CONTENT_IN)
  190. compiler_id_detection(CMAKE_${lang}_COMPILER_ID_CONTENT ${lang}
  191. ID_STRING
  192. VERSION_STRINGS
  193. PLATFORM_DEFAULT_COMPILER
  194. )
  195. unset(src_in CACHE)
  196. string(CONFIGURE "${ID_CONTENT_IN}" ID_CONTENT_OUT @ONLY)
  197. file(WRITE ${CMAKE_${lang}_COMPILER_ID_DIR}/${src} "${ID_CONTENT_OUT}")
  198. endfunction()
  199. #-----------------------------------------------------------------------------
  200. # Function to build the compiler id source file and look for output
  201. # files.
  202. function(CMAKE_DETERMINE_COMPILER_ID_BUILD lang testflags userflags src)
  203. # Create a clean working directory.
  204. file(REMOVE_RECURSE ${CMAKE_${lang}_COMPILER_ID_DIR})
  205. file(MAKE_DIRECTORY ${CMAKE_${lang}_COMPILER_ID_DIR})
  206. file(MAKE_DIRECTORY ${CMAKE_${lang}_COMPILER_ID_DIR}/tmp)
  207. CMAKE_DETERMINE_COMPILER_ID_WRITE("${lang}" "${src}")
  208. # Construct a description of this test case.
  209. set(COMPILER_DESCRIPTION
  210. "Compiler: ${CMAKE_${lang}_COMPILER} ${CMAKE_${lang}_COMPILER_ID_ARG1}
  211. Build flags: ${userflags}
  212. Id flags: ${testflags} ${CMAKE_${lang}_COMPILER_ID_FLAGS_ALWAYS}
  213. ")
  214. # Compile the compiler identification source.
  215. if("${CMAKE_GENERATOR}" MATCHES "Visual Studio ([0-9]+)")
  216. set(vs_version ${CMAKE_MATCH_1})
  217. set(id_platform ${CMAKE_VS_PLATFORM_NAME})
  218. set(id_lang "${lang}")
  219. set(id_PostBuildEvent_Command "")
  220. if(CMAKE_VS_PLATFORM_TOOLSET MATCHES "^[Ll][Ll][Vv][Mm](_v[0-9]+(_xp)?)?$")
  221. set(id_cl_var "ClangClExecutable")
  222. elseif(CMAKE_VS_PLATFORM_TOOLSET MATCHES "v[0-9]+_clang_.*")
  223. set(id_cl clang.exe)
  224. else()
  225. set(id_cl cl.exe)
  226. endif()
  227. if(CMAKE_VS_PLATFORM_NAME STREQUAL "Tegra-Android")
  228. set(v NsightTegra)
  229. set(ext vcxproj)
  230. if(lang STREQUAL CXX)
  231. set(id_gcc g++)
  232. set(id_clang clang++)
  233. else()
  234. set(id_gcc gcc)
  235. set(id_clang clang)
  236. endif()
  237. elseif(lang STREQUAL Fortran)
  238. set(v Intel)
  239. set(ext vfproj)
  240. set(id_cl ifort.exe)
  241. elseif(lang STREQUAL CSharp)
  242. set(v 10)
  243. set(ext csproj)
  244. set(id_cl csc.exe)
  245. elseif(NOT "${vs_version}" VERSION_LESS 10)
  246. set(v 10)
  247. set(ext vcxproj)
  248. else()
  249. set(id_version ${vs_version}.00)
  250. set(v 7)
  251. set(ext vcproj)
  252. endif()
  253. if(CMAKE_VS_PLATFORM_TOOLSET)
  254. if(CMAKE_VS_PLATFORM_NAME STREQUAL "Tegra-Android")
  255. set(id_toolset "<NdkToolchainVersion>${CMAKE_VS_PLATFORM_TOOLSET}</NdkToolchainVersion>")
  256. else()
  257. set(id_toolset "<PlatformToolset>${CMAKE_VS_PLATFORM_TOOLSET}</PlatformToolset>")
  258. if(CMAKE_VS_PLATFORM_TOOLSET MATCHES "Intel")
  259. set(id_cl icl.exe)
  260. endif()
  261. if(CMAKE_VS_PLATFORM_TOOLSET_VERSION)
  262. set(id_sep "\\")
  263. if(CMAKE_VS_PLATFORM_TOOLSET_VERSION VERSION_GREATER_EQUAL "14.20")
  264. if(EXISTS "${CMAKE_GENERATOR_INSTANCE}/VC/Auxiliary/Build.${CMAKE_VS_PLATFORM_TOOLSET_VERSION}/Microsoft.VCToolsVersion.${CMAKE_VS_PLATFORM_TOOLSET_VERSION}.props")
  265. set(id_sep ".")
  266. endif()
  267. endif()
  268. set(id_toolset_version_props "<Import Project=\"${CMAKE_GENERATOR_INSTANCE}\\VC\\Auxiliary\\Build${id_sep}${CMAKE_VS_PLATFORM_TOOLSET_VERSION}\\Microsoft.VCToolsVersion.${CMAKE_VS_PLATFORM_TOOLSET_VERSION}.props\" />")
  269. unset(id_sep)
  270. endif()
  271. endif()
  272. else()
  273. set(id_toolset "")
  274. set(id_toolset_version_props "")
  275. endif()
  276. if(CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE)
  277. set(id_PreferredToolArchitecture "<PreferredToolArchitecture>${CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE}</PreferredToolArchitecture>")
  278. else()
  279. set(id_PreferredToolArchitecture "")
  280. endif()
  281. if(CMAKE_SYSTEM_NAME STREQUAL "WindowsPhone")
  282. set(id_system "<ApplicationType>Windows Phone</ApplicationType>")
  283. elseif(CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
  284. set(id_system "<ApplicationType>Windows Store</ApplicationType>")
  285. else()
  286. set(id_system "")
  287. endif()
  288. if(id_system AND CMAKE_SYSTEM_VERSION MATCHES "^([0-9]+\\.[0-9]+)")
  289. set(id_system_version "<ApplicationTypeRevision>${CMAKE_MATCH_1}</ApplicationTypeRevision>")
  290. else()
  291. set(id_system_version "")
  292. endif()
  293. if(CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION)
  294. set(id_WindowsTargetPlatformVersion "<WindowsTargetPlatformVersion>${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}</WindowsTargetPlatformVersion>")
  295. endif()
  296. if(id_platform STREQUAL ARM64)
  297. set(id_WindowsSDKDesktopARMSupport "<WindowsSDKDesktopARM64Support>true</WindowsSDKDesktopARM64Support>")
  298. elseif(id_platform STREQUAL ARM)
  299. set(id_WindowsSDKDesktopARMSupport "<WindowsSDKDesktopARMSupport>true</WindowsSDKDesktopARMSupport>")
  300. else()
  301. set(id_WindowsSDKDesktopARMSupport "")
  302. endif()
  303. if(CMAKE_VS_WINCE_VERSION)
  304. set(id_entrypoint "mainACRTStartup")
  305. if("${vs_version}" VERSION_LESS 9)
  306. set(id_subsystem 9)
  307. else()
  308. set(id_subsystem 8)
  309. endif()
  310. else()
  311. set(id_subsystem 1)
  312. endif()
  313. set(id_dir ${CMAKE_${lang}_COMPILER_ID_DIR})
  314. set(id_src "${src}")
  315. set(id_compile "ClCompile")
  316. if(id_cl_var)
  317. set(id_PostBuildEvent_Command "echo CMAKE_${lang}_COMPILER=$(${id_cl_var})")
  318. else()
  319. set(id_PostBuildEvent_Command "for %%i in (${id_cl}) do %40echo CMAKE_${lang}_COMPILER=%%~$PATH:i")
  320. endif()
  321. set(id_Import_props "")
  322. set(id_Import_targets "")
  323. set(id_ItemDefinitionGroup_entry "")
  324. set(id_Link_AdditionalDependencies "")
  325. if(lang STREQUAL CUDA)
  326. if(NOT CMAKE_VS_PLATFORM_TOOLSET_CUDA)
  327. message(FATAL_ERROR "No CUDA toolset found.")
  328. endif()
  329. set(cuda_tools "CUDA ${CMAKE_VS_PLATFORM_TOOLSET_CUDA}")
  330. set(id_compile "CudaCompile")
  331. set(id_PostBuildEvent_Command [[echo CMAKE_CUDA_COMPILER=$(CudaToolkitBinDir)\nvcc.exe]])
  332. if(CMAKE_VS_PLATFORM_TOOLSET_CUDA_CUSTOM_DIR)
  333. set(id_CudaToolkitCustomDir "<CudaToolkitCustomDir>${CMAKE_VS_PLATFORM_TOOLSET_CUDA_CUSTOM_DIR}nvcc</CudaToolkitCustomDir>")
  334. string(CONCAT id_Import_props "<Import Project=\"${CMAKE_VS_PLATFORM_TOOLSET_CUDA_CUSTOM_DIR}\\CUDAVisualStudioIntegration\\extras\\visual_studio_integration\\MSBuildExtensions\\${cuda_tools}.props\" />")
  335. string(CONCAT id_Import_targets "<Import Project=\"${CMAKE_VS_PLATFORM_TOOLSET_CUDA_CUSTOM_DIR}\\CUDAVisualStudioIntegration\\extras\\visual_studio_integration\\MSBuildExtensions\\${cuda_tools}.targets\" />")
  336. else()
  337. string(CONCAT id_Import_props [[<Import Project="$(VCTargetsPath)\BuildCustomizations\]] "${cuda_tools}" [[.props" />]])
  338. string(CONCAT id_Import_targets [[<Import Project="$(VCTargetsPath)\BuildCustomizations\]] "${cuda_tools}" [[.targets" />]])
  339. endif()
  340. if(CMAKE_VS_PLATFORM_NAME STREQUAL x64)
  341. set(id_ItemDefinitionGroup_entry "<CudaCompile><TargetMachinePlatform>64</TargetMachinePlatform></CudaCompile>")
  342. endif()
  343. set(id_Link_AdditionalDependencies "<AdditionalDependencies>cudart.lib</AdditionalDependencies>")
  344. endif()
  345. configure_file(${CMAKE_ROOT}/Modules/CompilerId/VS-${v}.${ext}.in
  346. ${id_dir}/CompilerId${lang}.${ext} @ONLY)
  347. if(CMAKE_VS_MSBUILD_COMMAND AND NOT lang STREQUAL "Fortran")
  348. set(command "${CMAKE_VS_MSBUILD_COMMAND}" "CompilerId${lang}.${ext}"
  349. "/p:Configuration=Debug" "/p:Platform=${id_platform}" "/p:VisualStudioVersion=${vs_version}.0"
  350. )
  351. elseif(CMAKE_VS_DEVENV_COMMAND)
  352. set(command "${CMAKE_VS_DEVENV_COMMAND}" "CompilerId${lang}.${ext}" "/build" "Debug")
  353. else()
  354. set(command "")
  355. endif()
  356. if(command)
  357. execute_process(
  358. COMMAND ${command}
  359. WORKING_DIRECTORY ${CMAKE_${lang}_COMPILER_ID_DIR}
  360. OUTPUT_VARIABLE CMAKE_${lang}_COMPILER_ID_OUTPUT
  361. ERROR_VARIABLE CMAKE_${lang}_COMPILER_ID_OUTPUT
  362. RESULT_VARIABLE CMAKE_${lang}_COMPILER_ID_RESULT
  363. )
  364. else()
  365. set(CMAKE_${lang}_COMPILER_ID_RESULT 1)
  366. set(CMAKE_${lang}_COMPILER_ID_OUTPUT "VS environment not known to support ${lang}")
  367. endif()
  368. # Match the compiler location line printed out.
  369. if("${CMAKE_${lang}_COMPILER_ID_OUTPUT}" MATCHES "CMAKE_${lang}_COMPILER=([^%\r\n]+)[\r\n]")
  370. # Strip VS diagnostic output from the end of the line.
  371. string(REGEX REPLACE " \\(TaskId:[0-9]*\\)$" "" _comp "${CMAKE_MATCH_1}")
  372. if(EXISTS "${_comp}")
  373. file(TO_CMAKE_PATH "${_comp}" _comp)
  374. set(CMAKE_${lang}_COMPILER_ID_TOOL "${_comp}" PARENT_SCOPE)
  375. endif()
  376. endif()
  377. elseif("${CMAKE_GENERATOR}" MATCHES "Xcode")
  378. set(id_lang "${lang}")
  379. set(id_type ${CMAKE_${lang}_COMPILER_XCODE_TYPE})
  380. set(id_dir ${CMAKE_${lang}_COMPILER_ID_DIR})
  381. set(id_src "${src}")
  382. if(CMAKE_XCODE_PLATFORM_TOOLSET)
  383. set(id_toolset "GCC_VERSION = ${CMAKE_XCODE_PLATFORM_TOOLSET};")
  384. else()
  385. set(id_toolset "")
  386. endif()
  387. if("${lang}" STREQUAL "Swift")
  388. if(CMAKE_Swift_LANGUAGE_VERSION)
  389. set(id_lang_version "SWIFT_VERSION = ${CMAKE_Swift_LANGUAGE_VERSION};")
  390. elseif(XCODE_VERSION VERSION_GREATER_EQUAL 10.2)
  391. set(id_lang_version "SWIFT_VERSION = 4.0;")
  392. elseif(XCODE_VERSION VERSION_GREATER_EQUAL 8.3)
  393. set(id_lang_version "SWIFT_VERSION = 3.0;")
  394. else()
  395. set(id_lang_version "SWIFT_VERSION = 2.3;")
  396. endif()
  397. else()
  398. set(id_lang_version "")
  399. endif()
  400. if(CMAKE_OSX_DEPLOYMENT_TARGET)
  401. set(id_deployment_target
  402. "MACOSX_DEPLOYMENT_TARGET = \"${CMAKE_OSX_DEPLOYMENT_TARGET}\";")
  403. else()
  404. set(id_deployment_target "")
  405. endif()
  406. set(id_product_type "com.apple.product-type.tool")
  407. if(CMAKE_OSX_SYSROOT)
  408. set(id_sdkroot "SDKROOT = \"${CMAKE_OSX_SYSROOT}\";")
  409. if(CMAKE_OSX_SYSROOT MATCHES "(^|/)[Ii][Pp][Hh][Oo][Nn][Ee]" OR
  410. CMAKE_OSX_SYSROOT MATCHES "(^|/)[Aa][Pp][Pp][Ll][Ee][Tt][Vv]")
  411. set(id_product_type "com.apple.product-type.bundle.unit-test")
  412. elseif(CMAKE_OSX_SYSROOT MATCHES "(^|/)[Ww][Aa][Tt][Cc][Hh]")
  413. set(id_product_type "com.apple.product-type.framework")
  414. endif()
  415. else()
  416. set(id_sdkroot "")
  417. endif()
  418. set(id_clang_cxx_library "")
  419. set(stdlib_regex "(^| )(-stdlib=)([^ ]+)( |$)")
  420. string(REGEX MATCHALL "${stdlib_regex}" all_stdlib_matches "${CMAKE_CXX_FLAGS}")
  421. if(all_stdlib_matches)
  422. list(GET all_stdlib_matches "-1" last_stdlib_match)
  423. if(last_stdlib_match MATCHES "${stdlib_regex}")
  424. set(id_clang_cxx_library "CLANG_CXX_LIBRARY = \"${CMAKE_MATCH_3}\";")
  425. endif()
  426. endif()
  427. configure_file(${CMAKE_ROOT}/Modules/CompilerId/Xcode-3.pbxproj.in
  428. ${id_dir}/CompilerId${lang}.xcodeproj/project.pbxproj @ONLY)
  429. unset(_ENV_MACOSX_DEPLOYMENT_TARGET)
  430. if(DEFINED ENV{MACOSX_DEPLOYMENT_TARGET})
  431. set(_ENV_MACOSX_DEPLOYMENT_TARGET "$ENV{MACOSX_DEPLOYMENT_TARGET}")
  432. set(ENV{MACOSX_DEPLOYMENT_TARGET} "")
  433. endif()
  434. execute_process(COMMAND xcodebuild
  435. WORKING_DIRECTORY ${CMAKE_${lang}_COMPILER_ID_DIR}
  436. OUTPUT_VARIABLE CMAKE_${lang}_COMPILER_ID_OUTPUT
  437. ERROR_VARIABLE CMAKE_${lang}_COMPILER_ID_OUTPUT
  438. RESULT_VARIABLE CMAKE_${lang}_COMPILER_ID_RESULT
  439. )
  440. if(DEFINED _ENV_MACOSX_DEPLOYMENT_TARGET)
  441. set(ENV{MACOSX_DEPLOYMENT_TARGET} "${_ENV_MACOSX_DEPLOYMENT_TARGET}")
  442. endif()
  443. if(DEFINED CMAKE_${lang}_COMPILER_ID_TOOL_MATCH_REGEX)
  444. if("${CMAKE_${lang}_COMPILER_ID_OUTPUT}" MATCHES "${CMAKE_${lang}_COMPILER_ID_TOOL_MATCH_REGEX}")
  445. set(_comp "${CMAKE_MATCH_${CMAKE_${lang}_COMPILER_ID_TOOL_MATCH_INDEX}}")
  446. if(EXISTS "${_comp}")
  447. set(CMAKE_${lang}_COMPILER_ID_TOOL "${_comp}" PARENT_SCOPE)
  448. endif()
  449. endif()
  450. endif()
  451. if("${CMAKE_${lang}_COMPILER_ID_OUTPUT}" MATCHES "ARCHS=([^%\r\n]+)[\r\n]")
  452. set(CMAKE_${lang}_XCODE_ARCHS "${CMAKE_MATCH_1}")
  453. separate_arguments(CMAKE_${lang}_XCODE_ARCHS)
  454. set(CMAKE_${lang}_XCODE_ARCHS "${CMAKE_${lang}_XCODE_ARCHS}" PARENT_SCOPE)
  455. endif()
  456. elseif("${CMAKE_GENERATOR}" MATCHES "Green Hills MULTI")
  457. set(id_dir ${CMAKE_${lang}_COMPILER_ID_DIR})
  458. set(id_src "${src}")
  459. if (GHS_PRIMARY_TARGET)
  460. set(ghs_primary_target "${GHS_PRIMARY_TARGET}")
  461. else()
  462. set(ghs_primary_target "${CMAKE_GENERATOR_PLATFORM}_${GHS_TARGET_PLATFORM}.tgt")
  463. endif()
  464. if ("${GHS_TARGET_PLATFORM}" MATCHES "integrity")
  465. set(bsp_name "macro GHS_BSP=${GHS_BSP_NAME}")
  466. set(os_dir "macro GHS_OS=${GHS_OS_DIR}")
  467. endif()
  468. set(command "${CMAKE_MAKE_PROGRAM}" "-commands" "-top" "GHS_default.gpj")
  469. configure_file(${CMAKE_ROOT}/Modules/CompilerId/GHS_default.gpj.in
  470. ${id_dir}/GHS_default.gpj @ONLY)
  471. configure_file(${CMAKE_ROOT}/Modules/CompilerId/GHS_lib.gpj.in
  472. ${id_dir}/GHS_lib.gpj @ONLY)
  473. execute_process(COMMAND ${command}
  474. WORKING_DIRECTORY ${id_dir}
  475. OUTPUT_VARIABLE CMAKE_${lang}_COMPILER_ID_OUTPUT
  476. ERROR_VARIABLE CMAKE_${lang}_COMPILER_ID_OUTPUT
  477. RESULT_VARIABLE CMAKE_${lang}_COMPILER_ID_RESULT
  478. )
  479. # Match the compiler location line printed out.
  480. set(ghs_toolpath "${CMAKE_MAKE_PROGRAM}")
  481. if(CMAKE_HOST_UNIX)
  482. string(REPLACE "/gbuild" "/" ghs_toolpath ${ghs_toolpath})
  483. else()
  484. string(REPLACE "/gbuild.exe" "/" ghs_toolpath ${ghs_toolpath})
  485. string(REPLACE / "\\\\" ghs_toolpath ${ghs_toolpath})
  486. endif()
  487. if("${CMAKE_${lang}_COMPILER_ID_OUTPUT}" MATCHES "(${ghs_toolpath}[^ ]*)")
  488. if(CMAKE_HOST_UNIX)
  489. set(_comp "${CMAKE_MATCH_1}")
  490. else()
  491. set(_comp "${CMAKE_MATCH_1}.exe")
  492. endif()
  493. if(EXISTS "${_comp}")
  494. file(TO_CMAKE_PATH "${_comp}" _comp)
  495. set(CMAKE_${lang}_COMPILER_ID_TOOL "${_comp}" PARENT_SCOPE)
  496. endif()
  497. endif()
  498. else()
  499. execute_process(
  500. COMMAND "${CMAKE_${lang}_COMPILER}"
  501. ${CMAKE_${lang}_COMPILER_ID_ARG1}
  502. ${userflags}
  503. ${testflags}
  504. ${CMAKE_${lang}_COMPILER_ID_FLAGS_ALWAYS}
  505. "${src}"
  506. WORKING_DIRECTORY ${CMAKE_${lang}_COMPILER_ID_DIR}
  507. OUTPUT_VARIABLE CMAKE_${lang}_COMPILER_ID_OUTPUT
  508. ERROR_VARIABLE CMAKE_${lang}_COMPILER_ID_OUTPUT
  509. RESULT_VARIABLE CMAKE_${lang}_COMPILER_ID_RESULT
  510. )
  511. endif()
  512. # Check the result of compilation.
  513. if(CMAKE_${lang}_COMPILER_ID_RESULT
  514. # Intel Fortran warns and ignores preprocessor lines without /fpp
  515. OR CMAKE_${lang}_COMPILER_ID_OUTPUT MATCHES "Bad # preprocessor line"
  516. )
  517. # Compilation failed.
  518. set(MSG
  519. "Compiling the ${lang} compiler identification source file \"${src}\" failed.
  520. ${COMPILER_DESCRIPTION}
  521. The output was:
  522. ${CMAKE_${lang}_COMPILER_ID_RESULT}
  523. ${CMAKE_${lang}_COMPILER_ID_OUTPUT}
  524. ")
  525. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log "${MSG}")
  526. #if(NOT CMAKE_${lang}_COMPILER_ID_ALLOW_FAIL)
  527. # message(FATAL_ERROR "${MSG}")
  528. #endif()
  529. # No output files should be inspected.
  530. set(COMPILER_${lang}_PRODUCED_FILES)
  531. set(COMPILER_${lang}_PRODUCED_OUTPUT)
  532. else()
  533. # Compilation succeeded.
  534. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
  535. "Compiling the ${lang} compiler identification source file \"${src}\" succeeded.
  536. ${COMPILER_DESCRIPTION}
  537. The output was:
  538. ${CMAKE_${lang}_COMPILER_ID_RESULT}
  539. ${CMAKE_${lang}_COMPILER_ID_OUTPUT}
  540. ")
  541. # Find the executable produced by the compiler, try all files in the
  542. # binary dir.
  543. string(REGEX REPLACE "([][])" "[\\1]" _glob_id_dir "${CMAKE_${lang}_COMPILER_ID_DIR}")
  544. file(GLOB files
  545. RELATIVE ${CMAKE_${lang}_COMPILER_ID_DIR}
  546. # normal case
  547. ${_glob_id_dir}/*
  548. # com.apple.package-type.bundle.unit-test
  549. ${_glob_id_dir}/*.xctest/*
  550. # com.apple.product-type.framework
  551. ${_glob_id_dir}/*.framework/*
  552. )
  553. list(REMOVE_ITEM files "${src}")
  554. set(COMPILER_${lang}_PRODUCED_FILES "")
  555. foreach(file ${files})
  556. if(NOT IS_DIRECTORY ${CMAKE_${lang}_COMPILER_ID_DIR}/${file})
  557. list(APPEND COMPILER_${lang}_PRODUCED_FILES ${file})
  558. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
  559. "Compilation of the ${lang} compiler identification source \""
  560. "${src}\" produced \"${file}\"\n\n")
  561. endif()
  562. endforeach()
  563. if(NOT COMPILER_${lang}_PRODUCED_FILES)
  564. # No executable was found.
  565. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
  566. "Compilation of the ${lang} compiler identification source \""
  567. "${src}\" did not produce an executable in \""
  568. "${CMAKE_${lang}_COMPILER_ID_DIR}\".\n\n")
  569. endif()
  570. set(COMPILER_${lang}_PRODUCED_OUTPUT "${CMAKE_${lang}_COMPILER_ID_OUTPUT}")
  571. endif()
  572. # Return the files produced by the compilation.
  573. set(COMPILER_${lang}_PRODUCED_FILES "${COMPILER_${lang}_PRODUCED_FILES}" PARENT_SCOPE)
  574. set(COMPILER_${lang}_PRODUCED_OUTPUT "${COMPILER_${lang}_PRODUCED_OUTPUT}" PARENT_SCOPE)
  575. endfunction()
  576. #-----------------------------------------------------------------------------
  577. # Function to extract the compiler id from compiler output.
  578. function(CMAKE_DETERMINE_COMPILER_ID_MATCH_VENDOR lang output)
  579. foreach(vendor ${CMAKE_${lang}_COMPILER_ID_MATCH_VENDORS})
  580. if(output MATCHES "${CMAKE_${lang}_COMPILER_ID_MATCH_VENDOR_REGEX_${vendor}}")
  581. set(CMAKE_${lang}_COMPILER_ID "${vendor}")
  582. endif()
  583. endforeach()
  584. set(CMAKE_${lang}_COMPILER_ID "${CMAKE_${lang}_COMPILER_ID}" PARENT_SCOPE)
  585. endfunction()
  586. #-----------------------------------------------------------------------------
  587. # Function to extract the compiler id from an executable.
  588. function(CMAKE_DETERMINE_COMPILER_ID_CHECK lang file)
  589. # Look for a compiler id if not yet known.
  590. if(NOT CMAKE_${lang}_COMPILER_ID)
  591. # Read the compiler identification string from the executable file.
  592. set(COMPILER_ID)
  593. set(COMPILER_VERSION)
  594. set(COMPILER_VERSION_MAJOR 0)
  595. set(COMPILER_VERSION_MINOR 0)
  596. set(COMPILER_VERSION_PATCH 0)
  597. set(COMPILER_VERSION_TWEAK 0)
  598. set(COMPILER_VERSION_INTERNAL "")
  599. set(HAVE_COMPILER_VERSION_MAJOR 0)
  600. set(HAVE_COMPILER_VERSION_MINOR 0)
  601. set(HAVE_COMPILER_VERSION_PATCH 0)
  602. set(HAVE_COMPILER_VERSION_TWEAK 0)
  603. set(COMPILER_WRAPPER)
  604. set(DIGIT_VALUE_1 1)
  605. set(DIGIT_VALUE_2 10)
  606. set(DIGIT_VALUE_3 100)
  607. set(DIGIT_VALUE_4 1000)
  608. set(DIGIT_VALUE_5 10000)
  609. set(DIGIT_VALUE_6 100000)
  610. set(DIGIT_VALUE_7 1000000)
  611. set(DIGIT_VALUE_8 10000000)
  612. set(PLATFORM_ID)
  613. set(ARCHITECTURE_ID)
  614. set(SIMULATE_ID)
  615. set(SIMULATE_VERSION)
  616. foreach(encoding "" "ENCODING;UTF-16LE" "ENCODING;UTF-16BE")
  617. file(STRINGS "${file}" CMAKE_${lang}_COMPILER_ID_STRINGS
  618. LIMIT_COUNT 38 ${encoding}
  619. REGEX ".?I.?N.?F.?O.?:.?[A-Za-z0-9_]+\\[[^]]*\\]")
  620. if(NOT CMAKE_${lang}_COMPILER_ID_STRINGS STREQUAL "")
  621. break()
  622. endif()
  623. endforeach()
  624. set(COMPILER_ID_TWICE)
  625. # With the IAR Compiler, some strings are found twice, first time as incomplete
  626. # list like "?<Constant "INFO:compiler[IAR]">". Remove the incomplete copies.
  627. list(FILTER CMAKE_${lang}_COMPILER_ID_STRINGS EXCLUDE REGEX "\\?<Constant \\\"")
  628. # In C# binaries, some strings are found more than once.
  629. list(REMOVE_DUPLICATES CMAKE_${lang}_COMPILER_ID_STRINGS)
  630. foreach(info ${CMAKE_${lang}_COMPILER_ID_STRINGS})
  631. # The IAR-AVR compiler uses a binary format that places a '6'
  632. # character (0x34) before each character in the string. Strip
  633. # out these characters without removing any legitamate characters.
  634. if("${info}" MATCHES "(.)I.N.F.O.:.")
  635. string(REGEX REPLACE "${CMAKE_MATCH_1}(.)" "\\1" info "${info}")
  636. endif()
  637. if("${info}" MATCHES "INFO:compiler\\[([^]\"]*)\\]")
  638. if(COMPILER_ID)
  639. set(COMPILER_ID_TWICE 1)
  640. endif()
  641. set(COMPILER_ID "${CMAKE_MATCH_1}")
  642. endif()
  643. if("${info}" MATCHES "INFO:platform\\[([^]\"]*)\\]")
  644. set(PLATFORM_ID "${CMAKE_MATCH_1}")
  645. endif()
  646. if("${info}" MATCHES "INFO:arch\\[([^]\"]*)\\]")
  647. set(ARCHITECTURE_ID "${CMAKE_MATCH_1}")
  648. endif()
  649. if("${info}" MATCHES "INFO:compiler_version\\[([^]\"]*)\\]")
  650. string(REGEX REPLACE "^0+([0-9]+)" "\\1" COMPILER_VERSION "${CMAKE_MATCH_1}")
  651. string(REGEX REPLACE "\\.0+([0-9])" ".\\1" COMPILER_VERSION "${COMPILER_VERSION}")
  652. endif()
  653. if("${info}" MATCHES "INFO:compiler_version_internal\\[([^]\"]*)\\]")
  654. string(REGEX REPLACE "^0+([0-9])" "\\1" COMPILER_VERSION_INTERNAL "${CMAKE_MATCH_1}")
  655. string(REGEX REPLACE "\\.0+([0-9])" ".\\1" COMPILER_VERSION_INTERNAL "${COMPILER_VERSION_INTERNAL}")
  656. endif()
  657. foreach(comp MAJOR MINOR PATCH TWEAK)
  658. foreach(digit 1 2 3 4 5 6 7 8 9)
  659. if("${info}" MATCHES "INFO:compiler_version_${comp}_digit_${digit}\\[([0-9])\\]")
  660. set(value ${CMAKE_MATCH_1})
  661. math(EXPR COMPILER_VERSION_${comp} "${COMPILER_VERSION_${comp}} + ${value} * ${DIGIT_VALUE_${digit}}")
  662. set(HAVE_COMPILER_VERSION_${comp} 1)
  663. endif()
  664. endforeach()
  665. endforeach()
  666. if("${info}" MATCHES "INFO:compiler_wrapper\\[([^]\"]*)\\]")
  667. set(COMPILER_WRAPPER "${CMAKE_MATCH_1}")
  668. endif()
  669. if("${info}" MATCHES "INFO:simulate\\[([^]\"]*)\\]")
  670. set(SIMULATE_ID "${CMAKE_MATCH_1}")
  671. endif()
  672. if("${info}" MATCHES "INFO:simulate_version\\[([^]\"]*)\\]")
  673. string(REGEX REPLACE "^0+([0-9])" "\\1" SIMULATE_VERSION "${CMAKE_MATCH_1}")
  674. string(REGEX REPLACE "\\.0+([0-9])" ".\\1" SIMULATE_VERSION "${SIMULATE_VERSION}")
  675. endif()
  676. if("${info}" MATCHES "INFO:qnxnto\\[\\]")
  677. set(COMPILER_QNXNTO 1)
  678. endif()
  679. if("${info}" MATCHES "INFO:dialect_default\\[([^]\"]*)\\]")
  680. set(CMAKE_${lang}_STANDARD_COMPUTED_DEFAULT "${CMAKE_MATCH_1}")
  681. endif()
  682. endforeach()
  683. # Construct compiler version from components if needed.
  684. if(NOT DEFINED COMPILER_VERSION AND HAVE_COMPILER_VERSION_MAJOR)
  685. set(COMPILER_VERSION "${COMPILER_VERSION_MAJOR}")
  686. if(HAVE_COMPILER_VERSION_MINOR)
  687. string(APPEND COMPILER_VERSION ".${COMPILER_VERSION_MINOR}")
  688. if(HAVE_COMPILER_VERSION_PATCH)
  689. string(APPEND COMPILER_VERSION ".${COMPILER_VERSION_PATCH}")
  690. if(HAVE_COMPILER_VERSION_TWEAK)
  691. string(APPEND COMPILER_VERSION ".${COMPILER_VERSION_TWEAK}")
  692. endif()
  693. endif()
  694. endif()
  695. endif()
  696. # Detect the exact architecture from the PE header.
  697. if(WIN32)
  698. # The offset to the PE signature is stored at 0x3c.
  699. file(READ ${file} peoffsethex LIMIT 1 OFFSET 60 HEX)
  700. if(NOT peoffsethex STREQUAL "")
  701. string(SUBSTRING "${peoffsethex}" 0 1 peoffsethex1)
  702. string(SUBSTRING "${peoffsethex}" 1 1 peoffsethex2)
  703. set(peoffsetexpression "${peoffsethex1} * 16 + ${peoffsethex2}")
  704. string(REPLACE "a" "10" peoffsetexpression "${peoffsetexpression}")
  705. string(REPLACE "b" "11" peoffsetexpression "${peoffsetexpression}")
  706. string(REPLACE "c" "12" peoffsetexpression "${peoffsetexpression}")
  707. string(REPLACE "d" "13" peoffsetexpression "${peoffsetexpression}")
  708. string(REPLACE "e" "14" peoffsetexpression "${peoffsetexpression}")
  709. string(REPLACE "f" "15" peoffsetexpression "${peoffsetexpression}")
  710. math(EXPR peoffset "${peoffsetexpression}")
  711. file(READ ${file} peheader LIMIT 6 OFFSET ${peoffset} HEX)
  712. if(peheader STREQUAL "50450000a201")
  713. set(ARCHITECTURE_ID "SH3")
  714. elseif(peheader STREQUAL "50450000a301")
  715. set(ARCHITECTURE_ID "SH3DSP")
  716. elseif(peheader STREQUAL "50450000a601")
  717. set(ARCHITECTURE_ID "SH4")
  718. elseif(peheader STREQUAL "50450000a801")
  719. set(ARCHITECTURE_ID "SH5")
  720. endif()
  721. endif()
  722. endif()
  723. # Check if a valid compiler and platform were found.
  724. if(COMPILER_ID AND NOT COMPILER_ID_TWICE)
  725. set(CMAKE_${lang}_COMPILER_ID "${COMPILER_ID}")
  726. set(CMAKE_${lang}_PLATFORM_ID "${PLATFORM_ID}")
  727. set(CMAKE_${lang}_COMPILER_ARCHITECTURE_ID "${ARCHITECTURE_ID}")
  728. set(MSVC_${lang}_ARCHITECTURE_ID "${ARCHITECTURE_ID}")
  729. set(CMAKE_${lang}_COMPILER_VERSION "${COMPILER_VERSION}")
  730. set(CMAKE_${lang}_COMPILER_VERSION_INTERNAL "${COMPILER_VERSION_INTERNAL}")
  731. set(CMAKE_${lang}_SIMULATE_ID "${SIMULATE_ID}")
  732. set(CMAKE_${lang}_SIMULATE_VERSION "${SIMULATE_VERSION}")
  733. endif()
  734. # Check the compiler identification string.
  735. if(CMAKE_${lang}_COMPILER_ID)
  736. # The compiler identification was found.
  737. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
  738. "The ${lang} compiler identification is ${CMAKE_${lang}_COMPILER_ID}, found in \""
  739. "${file}\"\n\n")
  740. else()
  741. # The compiler identification could not be found.
  742. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
  743. "The ${lang} compiler identification could not be found in \""
  744. "${file}\"\n\n")
  745. endif()
  746. endif()
  747. # try to figure out the executable format: ELF, COFF, Mach-O
  748. if(NOT CMAKE_EXECUTABLE_FORMAT)
  749. file(READ ${file} CMAKE_EXECUTABLE_MAGIC LIMIT 4 HEX)
  750. # ELF files start with 0x7f"ELF"
  751. if("${CMAKE_EXECUTABLE_MAGIC}" STREQUAL "7f454c46")
  752. set(CMAKE_EXECUTABLE_FORMAT "ELF" CACHE INTERNAL "Executable file format")
  753. endif()
  754. # # COFF (.exe) files start with "MZ"
  755. # if("${CMAKE_EXECUTABLE_MAGIC}" MATCHES "4d5a....")
  756. # set(CMAKE_EXECUTABLE_FORMAT "COFF" CACHE STRING "Executable file format")
  757. # endif()
  758. #
  759. # Mach-O files start with MH_MAGIC or MH_CIGAM
  760. if("${CMAKE_EXECUTABLE_MAGIC}" MATCHES "feedface|cefaedfe|feedfacf|cffaedfe")
  761. set(CMAKE_EXECUTABLE_FORMAT "MACHO" CACHE STRING "Executable file format")
  762. endif()
  763. endif()
  764. if(NOT DEFINED CMAKE_EXECUTABLE_FORMAT)
  765. set(CMAKE_EXECUTABLE_FORMAT)
  766. endif()
  767. # Return the information extracted.
  768. set(CMAKE_${lang}_COMPILER_ID "${CMAKE_${lang}_COMPILER_ID}" PARENT_SCOPE)
  769. set(CMAKE_${lang}_PLATFORM_ID "${CMAKE_${lang}_PLATFORM_ID}" PARENT_SCOPE)
  770. set(CMAKE_${lang}_COMPILER_ARCHITECTURE_ID "${CMAKE_${lang}_COMPILER_ARCHITECTURE_ID}" PARENT_SCOPE)
  771. set(MSVC_${lang}_ARCHITECTURE_ID "${MSVC_${lang}_ARCHITECTURE_ID}"
  772. PARENT_SCOPE)
  773. set(CMAKE_${lang}_COMPILER_VERSION "${CMAKE_${lang}_COMPILER_VERSION}" PARENT_SCOPE)
  774. set(CMAKE_${lang}_COMPILER_VERSION_INTERNAL "${CMAKE_${lang}_COMPILER_VERSION_INTERNAL}" PARENT_SCOPE)
  775. set(CMAKE_${lang}_COMPILER_WRAPPER "${COMPILER_WRAPPER}" PARENT_SCOPE)
  776. set(CMAKE_${lang}_SIMULATE_ID "${CMAKE_${lang}_SIMULATE_ID}" PARENT_SCOPE)
  777. set(CMAKE_${lang}_SIMULATE_VERSION "${CMAKE_${lang}_SIMULATE_VERSION}" PARENT_SCOPE)
  778. set(CMAKE_EXECUTABLE_FORMAT "${CMAKE_EXECUTABLE_FORMAT}" PARENT_SCOPE)
  779. set(COMPILER_QNXNTO "${COMPILER_QNXNTO}" PARENT_SCOPE)
  780. set(CMAKE_${lang}_STANDARD_COMPUTED_DEFAULT "${CMAKE_${lang}_STANDARD_COMPUTED_DEFAULT}" PARENT_SCOPE)
  781. endfunction()
  782. #-----------------------------------------------------------------------------
  783. # Function to query the compiler vendor.
  784. # This uses a table with entries of the form
  785. # list(APPEND CMAKE_${lang}_COMPILER_ID_VENDORS ${vendor})
  786. # set(CMAKE_${lang}_COMPILER_ID_VENDOR_FLAGS_${vendor} -some-vendor-flag)
  787. # set(CMAKE_${lang}_COMPILER_ID_VENDOR_REGEX_${vendor} "Some Vendor Output")
  788. # We try running the compiler with the flag for each vendor and
  789. # matching its regular expression in the output.
  790. function(CMAKE_DETERMINE_COMPILER_ID_VENDOR lang userflags)
  791. if(NOT CMAKE_${lang}_COMPILER_ID_DIR)
  792. # We get here when this function is called not from within CMAKE_DETERMINE_COMPILER_ID()
  793. # This is done e.g. for detecting the compiler ID for assemblers.
  794. # Compute the directory in which to run the test and Create a clean working directory.
  795. set(CMAKE_${lang}_COMPILER_ID_DIR ${CMAKE_PLATFORM_INFO_DIR}/CompilerId${lang})
  796. file(REMOVE_RECURSE ${CMAKE_${lang}_COMPILER_ID_DIR})
  797. file(MAKE_DIRECTORY ${CMAKE_${lang}_COMPILER_ID_DIR})
  798. endif()
  799. foreach(vendor ${CMAKE_${lang}_COMPILER_ID_VENDORS})
  800. set(flags ${CMAKE_${lang}_COMPILER_ID_VENDOR_FLAGS_${vendor}})
  801. set(regex ${CMAKE_${lang}_COMPILER_ID_VENDOR_REGEX_${vendor}})
  802. execute_process(
  803. COMMAND "${CMAKE_${lang}_COMPILER}"
  804. ${CMAKE_${lang}_COMPILER_ID_ARG1}
  805. ${userflags}
  806. ${flags}
  807. WORKING_DIRECTORY ${CMAKE_${lang}_COMPILER_ID_DIR}
  808. OUTPUT_VARIABLE output ERROR_VARIABLE output
  809. RESULT_VARIABLE result
  810. TIMEOUT 10
  811. )
  812. if("${output}" MATCHES "${regex}")
  813. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
  814. "Checking whether the ${lang} compiler is ${vendor} using \"${flags}\" "
  815. "matched \"${regex}\":\n${output}")
  816. set(CMAKE_${lang}_COMPILER_ID "${vendor}" PARENT_SCOPE)
  817. set(CMAKE_${lang}_COMPILER_ID_OUTPUT "${output}" PARENT_SCOPE)
  818. break()
  819. else()
  820. if("${result}" MATCHES "timeout")
  821. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
  822. "Checking whether the ${lang} compiler is ${vendor} using \"${flags}\" "
  823. "terminated after 10 s due to timeout.")
  824. else()
  825. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
  826. "Checking whether the ${lang} compiler is ${vendor} using \"${flags}\" "
  827. "did not match \"${regex}\":\n${output}")
  828. endif()
  829. endif()
  830. endforeach()
  831. endfunction()
  832. function(CMAKE_DETERMINE_MSVC_SHOWINCLUDES_PREFIX lang userflags)
  833. # Run this MSVC-compatible compiler to detect what the /showIncludes
  834. # option displays. We can use a C source even with the C++ compiler
  835. # because MSVC-compatible compilers handle both and show the same output.
  836. set(showdir ${CMAKE_BINARY_DIR}/CMakeFiles/ShowIncludes)
  837. file(WRITE ${showdir}/foo.h "\n")
  838. file(WRITE ${showdir}/main.c "#include \"foo.h\" \nint main(){}\n")
  839. execute_process(
  840. COMMAND "${CMAKE_${lang}_COMPILER}"
  841. ${CMAKE_${lang}_COMPILER_ID_ARG1}
  842. ${userflags}
  843. /nologo /showIncludes /c main.c
  844. WORKING_DIRECTORY ${showdir}
  845. OUTPUT_VARIABLE out
  846. ERROR_VARIABLE err
  847. RESULT_VARIABLE res
  848. ENCODING AUTO # cl prints in current code page
  849. )
  850. if(res EQUAL 0 AND "${out}" MATCHES "(^|\n)([^:\n]*:[^:\n]*:[ \t]*)")
  851. set(CMAKE_${lang}_CL_SHOWINCLUDES_PREFIX "${CMAKE_MATCH_2}" PARENT_SCOPE)
  852. else()
  853. set(CMAKE_${lang}_CL_SHOWINCLUDES_PREFIX "" PARENT_SCOPE)
  854. endif()
  855. endfunction()