From cd28915260432cdbcdfb1f715477c262d41867d1 Mon Sep 17 00:00:00 2001 From: Brad King Date: Mon, 27 Nov 2023 16:02:07 -0500 Subject: LLVMFlang: Update MSVC ABI and architecture detection for LLVMFlang 18.0 LLVMFlang 18.0 adds MSVC ABI and architecture macros. Resolve the corresponding FIXME left by commit 26bf32cdc6 (LLVMFlang: Add support for targeting MSVC ABI on Windows, 2023-09-28, v3.28.0-rc1~10^2). Issue: #24840 --- Modules/CMakeDetermineCompilerId.cmake | 37 ++++++++++++++++++---------------- Modules/CMakeFortranCompilerId.F.in | 2 +- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/Modules/CMakeDetermineCompilerId.cmake b/Modules/CMakeDetermineCompilerId.cmake index ffba1cb..b380aa5 100644 --- a/Modules/CMakeDetermineCompilerId.cmake +++ b/Modules/CMakeDetermineCompilerId.cmake @@ -174,27 +174,30 @@ function(CMAKE_DETERMINE_COMPILER_ID lang flagvar src) endif() endif() - # FIXME(LLVMFlang): It does not provide predefines identifying the MSVC ABI or architecture. - # It should be taught to define _MSC_VER and its _M_* architecture flags. if("x${lang}" STREQUAL "xFortran" AND "x${CMAKE_${lang}_COMPILER_ID}" STREQUAL "xLLVMFlang") - # Parse the target triple to detect information we should later be able - # to get during preprocessing above, once LLVMFlang provides it. + # Parse the target triple to detect information not always available from the preprocessor. if(COMPILER_${lang}_PRODUCED_OUTPUT MATCHES "-triple ([0-9a-z_]*)-.*windows-msvc([0-9]+)\\.([0-9]+)") - set(CMAKE_${lang}_SIMULATE_ID "MSVC") + # CMakeFortranCompilerId.F.in does not extract the _MSC_VER minor version. + # We can do better using the version parsed here. set(CMAKE_${lang}_SIMULATE_VERSION "${CMAKE_MATCH_2}.${CMAKE_MATCH_3}") - set(arch ${CMAKE_MATCH_1}) - if(arch STREQUAL "x86_64") - set(CMAKE_${lang}_COMPILER_ARCHITECTURE_ID "x64") - elseif(arch STREQUAL "aarch64") - set(CMAKE_${lang}_COMPILER_ARCHITECTURE_ID "ARM64") - elseif(arch STREQUAL "arm64ec") - set(CMAKE_${lang}_COMPILER_ARCHITECTURE_ID "ARM64EC") - elseif(arch MATCHES "^i[3-9]86$") - set(CMAKE_${lang}_COMPILER_ARCHITECTURE_ID "X86") - else() - message(FATAL_ERROR "LLVMFlang target architecture unrecognized: ${arch}") + + if (CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 18.0) + # LLVMFlang < 18.0 does not provide predefines identifying the MSVC ABI or architecture. + set(CMAKE_${lang}_SIMULATE_ID "MSVC") + set(arch ${CMAKE_MATCH_1}) + if(arch STREQUAL "x86_64") + set(CMAKE_${lang}_COMPILER_ARCHITECTURE_ID "x64") + elseif(arch STREQUAL "aarch64") + set(CMAKE_${lang}_COMPILER_ARCHITECTURE_ID "ARM64") + elseif(arch STREQUAL "arm64ec") + set(CMAKE_${lang}_COMPILER_ARCHITECTURE_ID "ARM64EC") + elseif(arch MATCHES "^i[3-9]86$") + set(CMAKE_${lang}_COMPILER_ARCHITECTURE_ID "X86") + else() + message(FATAL_ERROR "LLVMFlang target architecture unrecognized: ${arch}") + endif() + set(MSVC_${lang}_ARCHITECTURE_ID "${CMAKE_${lang}_COMPILER_ARCHITECTURE_ID}") endif() - set(MSVC_${lang}_ARCHITECTURE_ID "${CMAKE_${lang}_COMPILER_ARCHITECTURE_ID}") elseif(COMPILER_${lang}_PRODUCED_OUTPUT MATCHES "-triple ([0-9a-z_]*)-.*windows-gnu") set(CMAKE_${lang}_SIMULATE_ID "GNU") endif() diff --git a/Modules/CMakeFortranCompilerId.F.in b/Modules/CMakeFortranCompilerId.F.in index f5c2ab5..a040073 100644 --- a/Modules/CMakeFortranCompilerId.F.in +++ b/Modules/CMakeFortranCompilerId.F.in @@ -240,7 +240,7 @@ #else PRINT *, 'INFO:platform[]' #endif -#if defined(_WIN32) && (defined(__INTEL_COMPILER) || defined(__ICC)) +#if defined(_MSC_VER) # if defined(_M_IA64) PRINT *, 'INFO:arch[IA64]' # elif defined(_M_X64) || defined(_M_AMD64) -- cgit v0.12