From 12733d0d8d9145f8cff620098bfc911cd4ea6234 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 28 Sep 2023 18:51:46 -0400 Subject: CMakeParseImplicitLinkInfo: Detect link lines using link.exe and lld-link These are printed by LLVM-based compiler drivers targeting the MSVC ABI. In our use case for this, `CMAKE_LINKER` may not yet be known, so do not include it in the test data. --- Modules/CMakeParseImplicitLinkInfo.cmake | 16 ++++++++++------ .../windows_arm64-C-Clang-17.0.1-MSVC.input | 20 ++++++++++++++++++++ .../windows_arm64-CXX-Clang-17.0.1-MSVC.input | 20 ++++++++++++++++++++ ...windows_arm64-Fortran-LLVMFlang-17.0.1-MSVC.input | 20 ++++++++++++++++++++ .../windows_x86_64-C-Clang-17.0.1-MSVC.input | 20 ++++++++++++++++++++ .../windows_x86_64-CXX-Clang-17.0.1-MSVC.input | 20 ++++++++++++++++++++ ...indows_x86_64-Fortran-LLVMFlang-17.0.1-MSVC.input | 20 ++++++++++++++++++++ .../ParseImplicitLinkInfo.cmake | 2 ++ .../results/windows_arm64-C-Clang-17.0.1-MSVC.output | 2 ++ .../windows_arm64-CXX-Clang-17.0.1-MSVC.output | 2 ++ ...indows_arm64-Fortran-LLVMFlang-17.0.1-MSVC.output | 2 ++ .../windows_x86_64-C-Clang-17.0.1-MSVC.output | 2 ++ .../windows_x86_64-CXX-Clang-17.0.1-MSVC.output | 2 ++ ...ndows_x86_64-Fortran-LLVMFlang-17.0.1-MSVC.output | 2 ++ 14 files changed, 144 insertions(+), 6 deletions(-) create mode 100644 Tests/RunCMake/ParseImplicitData/windows_arm64-C-Clang-17.0.1-MSVC.input create mode 100644 Tests/RunCMake/ParseImplicitData/windows_arm64-CXX-Clang-17.0.1-MSVC.input create mode 100644 Tests/RunCMake/ParseImplicitData/windows_arm64-Fortran-LLVMFlang-17.0.1-MSVC.input create mode 100644 Tests/RunCMake/ParseImplicitData/windows_x86_64-C-Clang-17.0.1-MSVC.input create mode 100644 Tests/RunCMake/ParseImplicitData/windows_x86_64-CXX-Clang-17.0.1-MSVC.input create mode 100644 Tests/RunCMake/ParseImplicitData/windows_x86_64-Fortran-LLVMFlang-17.0.1-MSVC.input create mode 100644 Tests/RunCMake/ParseImplicitLinkInfo/results/windows_arm64-C-Clang-17.0.1-MSVC.output create mode 100644 Tests/RunCMake/ParseImplicitLinkInfo/results/windows_arm64-CXX-Clang-17.0.1-MSVC.output create mode 100644 Tests/RunCMake/ParseImplicitLinkInfo/results/windows_arm64-Fortran-LLVMFlang-17.0.1-MSVC.output create mode 100644 Tests/RunCMake/ParseImplicitLinkInfo/results/windows_x86_64-C-Clang-17.0.1-MSVC.output create mode 100644 Tests/RunCMake/ParseImplicitLinkInfo/results/windows_x86_64-CXX-Clang-17.0.1-MSVC.output create mode 100644 Tests/RunCMake/ParseImplicitLinkInfo/results/windows_x86_64-Fortran-LLVMFlang-17.0.1-MSVC.output diff --git a/Modules/CMakeParseImplicitLinkInfo.cmake b/Modules/CMakeParseImplicitLinkInfo.cmake index 1773dc4..9213cc9 100644 --- a/Modules/CMakeParseImplicitLinkInfo.cmake +++ b/Modules/CMakeParseImplicitLinkInfo.cmake @@ -26,12 +26,22 @@ function(CMAKE_PARSE_IMPLICIT_LINK_INFO text lib_var dir_var fwk_var log_var obj set(multiValueArgs ) cmake_parse_arguments(EXTRA_PARSE "${keywordArgs}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + set(is_msvc 0) + if(EXTRA_PARSE_LANGUAGE AND + ("x${CMAKE_${EXTRA_PARSE_LANGUAGE}_ID}" STREQUAL "xMSVC" OR + "x${CMAKE_${EXTRA_PARSE_LANGUAGE}_SIMULATE_ID}" STREQUAL "xMSVC")) + set(is_msvc 1) + endif() + # Parse implicit linker arguments. set(linker "CMAKE_LINKER-NOTFOUND") if(CMAKE_LINKER) get_filename_component(linker ${CMAKE_LINKER} NAME) string(REGEX REPLACE "([][+.*?()^$])" "\\\\\\1" linker "${linker}") endif() + if(is_msvc) + string(APPEND linker "|link\\.exe|lld-link") + endif() set(startfile "CMAKE_LINK_STARTFILE-NOTFOUND") if(CMAKE_LINK_STARTFILE) set(startfile "${CMAKE_LINK_STARTFILE}") @@ -75,12 +85,6 @@ function(CMAKE_PARSE_IMPLICIT_LINK_INFO text lib_var dir_var fwk_var log_var obj endif() endif() endif() - set(is_msvc 0) - if(EXTRA_PARSE_LANGUAGE AND - ("x${CMAKE_${EXTRA_PARSE_LANGUAGE}_ID}" STREQUAL "xMSVC" OR - "x${CMAKE_${EXTRA_PARSE_LANGUAGE}_SIMULATE_ID}" STREQUAL "xMSVC")) - set(is_msvc 1) - endif() set(search_static 0) if("${cmd}" MATCHES "${linker_regex}") string(APPEND log " link line: [${line}]\n") diff --git a/Tests/RunCMake/ParseImplicitData/windows_arm64-C-Clang-17.0.1-MSVC.input b/Tests/RunCMake/ParseImplicitData/windows_arm64-C-Clang-17.0.1-MSVC.input new file mode 100644 index 0000000..d28b970 --- /dev/null +++ b/Tests/RunCMake/ParseImplicitData/windows_arm64-C-Clang-17.0.1-MSVC.input @@ -0,0 +1,20 @@ +CMAKE_LANG=C +CMAKE_LINKER= +CMAKE_C_COMPILER_ABI= +CMAKE_C_COMPILER_AR= +CMAKE_C_COMPILER_ARCHITECTURE_ID=ARM64 +CMAKE_C_COMPILER_EXTERNAL_TOOLCHAIN= +CMAKE_C_COMPILER_ID=Clang +CMAKE_C_COMPILER_LAUNCHER= +CMAKE_C_COMPILER_LOADED=1 +CMAKE_C_COMPILER_RANLIB= +CMAKE_C_COMPILER_TARGET= +CMAKE_C_COMPILER_VERSION=17.0.1 +CMAKE_C_COMPILER_VERSION_INTERAL= +CMAKE_C_SIMULATE_ID=MSVC +clang version 17.0.1 +Target: aarch64-pc-windows-msvc +Thread model: posix +InstalledDir: C:\DoesNotExist\LLVM\bin + "C:\\DoesNotExist\\LLVM\\bin\\clang-cl.exe" -cc1 -triple aarch64-pc-windows-msvc19.36.32532 -emit-obj -mrelax-all -mincremental-linker-compatible -dumpdir a- -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name CMakeCCompilerABI.c -mrelocation-model pic -pic-level 2 -mframe-pointer=none -relaxed-aliasing -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu generic -target-feature +neon -target-feature +v8a -target-abi aapcs -D_MT -flto-visibility-public-std --dependent-lib=libcmt --dependent-lib=oldnames -stack-protector 2 -fdiagnostics-format msvc -v "-fcoverage-compilation-dir=C:\\DoesNotExist\\Temp" -resource-dir "C:\\DoesNotExist\\LLVM\\lib\\clang\\17" -internal-isystem "C:\\DoesNotExist\\LLVM\\lib\\clang\\17\\include" -internal-isystem "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.36.32532\\include" -internal-isystem "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.36.32532\\ATLMFC\\include" -internal-isystem "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Auxiliary\\VS\\include" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.22621.0\\ucrt" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\\\include\\10.0.22621.0\\\\um" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\\\include\\10.0.22621.0\\\\shared" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\\\include\\10.0.22621.0\\\\winrt" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\\\include\\10.0.22621.0\\\\cppwinrt" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\NETFXSDK\\4.8\\include\\um" -internal-isystem "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.36.32532\\include" -internal-isystem "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.36.32532\\ATLMFC\\include" -internal-isystem "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Auxiliary\\VS\\include" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.22621.0\\ucrt" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\\\include\\10.0.22621.0\\\\um" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\\\include\\10.0.22621.0\\\\shared" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\\\include\\10.0.22621.0\\\\winrt" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\\\include\\10.0.22621.0\\\\cppwinrt" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\NETFXSDK\\4.8\\include\\um" "-fdebug-compilation-dir=C:\\DoesNotExist\\Temp" -ferror-limit 19 -fno-use-cxa-atexit -fms-extensions -fms-compatibility -fms-compatibility-version=19.36.32532 -fdelayed-template-parsing -target-feature -fmv -faddrsig -o "C:\\DoesNotExist\\Temp\\CMakeCCompilerABI-742dcb.obj" -x c CMakeCCompilerABI.c + "C:\\DoesNotExist\\LLVM\\bin\\lld-link" -out:CMakeCCompilerABI.exe "-libpath:C:\\DoesNotExist\\LLVM\\lib\\clang\\17\\lib\\windows" -nologo "C:\\DoesNotExist\\Temp\\CMakeCCompilerABI-742dcb.obj" diff --git a/Tests/RunCMake/ParseImplicitData/windows_arm64-CXX-Clang-17.0.1-MSVC.input b/Tests/RunCMake/ParseImplicitData/windows_arm64-CXX-Clang-17.0.1-MSVC.input new file mode 100644 index 0000000..e82a4fa --- /dev/null +++ b/Tests/RunCMake/ParseImplicitData/windows_arm64-CXX-Clang-17.0.1-MSVC.input @@ -0,0 +1,20 @@ +CMAKE_LANG=CXX +CMAKE_LINKER= +CMAKE_CXX_COMPILER_ABI= +CMAKE_CXX_COMPILER_AR= +CMAKE_CXX_COMPILER_ARCHITECTURE_ID=ARM64 +CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN= +CMAKE_CXX_COMPILER_ID=Clang +CMAKE_CXX_COMPILER_LAUNCHER= +CMAKE_CXX_COMPILER_LOADED=1 +CMAKE_CXX_COMPILER_RANLIB= +CMAKE_CXX_COMPILER_TARGET= +CMAKE_CXX_COMPILER_VERSION=17.0.1 +CMAKE_CXX_COMPILER_VERSION_INTERAL= +CMAKE_CXX_SIMULATE_ID=MSVC +clang version 17.0.1 +Target: aarch64-pc-windows-msvc +Thread model: posix +InstalledDir: C:\DoesNotExist\LLVM\bin + "C:\\DoesNotExist\\LLVM\\bin\\clang-cl.exe" -cc1 -triple aarch64-pc-windows-msvc19.36.32532 -emit-obj -mrelax-all -mincremental-linker-compatible -dumpdir a- -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name CMakeCXXCompilerABI.cpp -mrelocation-model pic -pic-level 2 -mframe-pointer=none -relaxed-aliasing -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu generic -target-feature +neon -target-feature +v8a -target-abi aapcs -D_MT -flto-visibility-public-std --dependent-lib=libcmt --dependent-lib=oldnames -stack-protector 2 -fdiagnostics-format msvc -v "-fcoverage-compilation-dir=C:\\DoesNotExist\\Temp" -resource-dir "C:\\DoesNotExist\\LLVM\\lib\\clang\\17" -internal-isystem "C:\\DoesNotExist\\LLVM\\lib\\clang\\17\\include" -internal-isystem "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.36.32532\\include" -internal-isystem "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.36.32532\\ATLMFC\\include" -internal-isystem "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Auxiliary\\VS\\include" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.22621.0\\ucrt" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\\\include\\10.0.22621.0\\\\um" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\\\include\\10.0.22621.0\\\\shared" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\\\include\\10.0.22621.0\\\\winrt" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\\\include\\10.0.22621.0\\\\cppwinrt" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\NETFXSDK\\4.8\\include\\um" -internal-isystem "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.36.32532\\include" -internal-isystem "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.36.32532\\ATLMFC\\include" -internal-isystem "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Auxiliary\\VS\\include" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.22621.0\\ucrt" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\\\include\\10.0.22621.0\\\\um" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\\\include\\10.0.22621.0\\\\shared" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\\\include\\10.0.22621.0\\\\winrt" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\\\include\\10.0.22621.0\\\\cppwinrt" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\NETFXSDK\\4.8\\include\\um" -fdeprecated-macro "-fdebug-compilation-dir=C:\\DoesNotExist\\Temp" -ferror-limit 19 -fno-use-cxa-atexit -fms-extensions -fms-compatibility -fms-compatibility-version=19.36.32532 -std=c++14 -fdelayed-template-parsing -target-feature -fmv -faddrsig -o "C:\\DoesNotExist\\Temp\\CMakeCXXCompilerABI-266f4c.obj" -x c++ CMakeCXXCompilerABI.cpp + "C:\\DoesNotExist\\LLVM\\bin\\lld-link" -out:CMakeCXXCompilerABI.exe "-libpath:C:\\DoesNotExist\\LLVM\\lib\\clang\\17\\lib\\windows" -nologo "C:\\DoesNotExist\\Temp\\CMakeCXXCompilerABI-266f4c.obj" diff --git a/Tests/RunCMake/ParseImplicitData/windows_arm64-Fortran-LLVMFlang-17.0.1-MSVC.input b/Tests/RunCMake/ParseImplicitData/windows_arm64-Fortran-LLVMFlang-17.0.1-MSVC.input new file mode 100644 index 0000000..4937a41 --- /dev/null +++ b/Tests/RunCMake/ParseImplicitData/windows_arm64-Fortran-LLVMFlang-17.0.1-MSVC.input @@ -0,0 +1,20 @@ +CMAKE_LANG=Fortran +CMAKE_LINKER= +CMAKE_Fortran_COMPILER_ABI= +CMAKE_Fortran_COMPILER_AR= +CMAKE_Fortran_COMPILER_ARCHITECTURE_ID=ARM64 +CMAKE_Fortran_COMPILER_EXTERNAL_TOOLCHAIN= +CMAKE_Fortran_COMPILER_ID=LLVMFlang +CMAKE_Fortran_COMPILER_LAUNCHER= +CMAKE_Fortran_COMPILER_LOADED=1 +CMAKE_Fortran_COMPILER_RANLIB= +CMAKE_Fortran_COMPILER_TARGET= +CMAKE_Fortran_COMPILER_VERSION=17.0.1 +CMAKE_Fortran_COMPILER_VERSION_INTERAL= +CMAKE_Fortran_SIMULATE_ID=MSVC +flang-new version 17.0.1 +Target: aarch64-pc-windows-msvc +Thread model: posix +InstalledDir: C:\DoesNotExist\LLVM\bin + "C:\\DoesNotExist\\LLVM\\bin\\flang-new" -fc1 -triple aarch64-pc-windows-msvc19.36.32532 -emit-obj -mrelocation-model pic -pic-level 2 -target-cpu generic -target-feature +neon -target-feature +v8a -o "C:\\DoesNotExist\\Temp\\CMakeFortranCompilerABI-ac5f0c.o" -x f95-cpp-input CMakeFortranCompilerABI.F + "C:\\DoesNotExist\\LLVM\\bin\\lld-link" -out:a.exe "-libpath:C:\\DoesNotExist\\LLVM\\lib" Fortran_main.lib FortranRuntime.lib FortranDecimal.lib /subsystem:console "-libpath:C:\\DoesNotExist\\LLVM\\lib\\clang\\17\\lib\\windows" -nologo "C:\\DoesNotExist\\Temp\\CMakeFortranCompilerABI-ac5f0c.o" diff --git a/Tests/RunCMake/ParseImplicitData/windows_x86_64-C-Clang-17.0.1-MSVC.input b/Tests/RunCMake/ParseImplicitData/windows_x86_64-C-Clang-17.0.1-MSVC.input new file mode 100644 index 0000000..b823880 --- /dev/null +++ b/Tests/RunCMake/ParseImplicitData/windows_x86_64-C-Clang-17.0.1-MSVC.input @@ -0,0 +1,20 @@ +CMAKE_LANG=C +CMAKE_LINKER= +CMAKE_C_COMPILER_ABI= +CMAKE_C_COMPILER_AR= +CMAKE_C_COMPILER_ARCHITECTURE_ID=x64 +CMAKE_C_COMPILER_EXTERNAL_TOOLCHAIN= +CMAKE_C_COMPILER_ID=Clang +CMAKE_C_COMPILER_LAUNCHER= +CMAKE_C_COMPILER_LOADED=1 +CMAKE_C_COMPILER_RANLIB= +CMAKE_C_COMPILER_TARGET= +CMAKE_C_COMPILER_VERSION=17.0.1 +CMAKE_C_COMPILER_VERSION_INTERAL= +CMAKE_C_SIMULATE_ID=MSVC +clang version 17.0.1 +Target: x86_64-pc-windows-msvc +Thread model: posix +InstalledDir: C:\DoesNotExist\LLVM\bin + "C:\\DoesNotExist\\LLVM\\bin\\clang-cl.exe" "-cc1" "-triple" "x86_64-pc-windows-msvc19.29.30152" "-emit-obj" "-mrelax-all" "-mincremental-linker-compatible" "-dumpdir" "a-" "-disable-free" "-clear-ast-before-backend" "-main-file-name" "CMakeCCompilerABI.c" "-mrelocation-model" "pic" "-pic-level" "2" "-mframe-pointer=none" "-relaxed-aliasing" "-fmath-errno" "-ffp-contract=on" "-fno-rounding-math" "-mconstructor-aliases" "-funwind-tables=2" "-target-cpu" "x86-64" "-mllvm" "-x86-asm-syntax=intel" "-tune-cpu" "generic" "-D_MT" "-flto-visibility-public-std" "--dependent-lib=libcmt" "--dependent-lib=oldnames" "-stack-protector" "2" "-fms-volatile" "-fdiagnostics-format" "msvc" "-fcoverage-compilation-dir=C:\\DoesNotExist\\Temp" "-resource-dir" "C:\\DoesNotExist\\LLVM\\lib\\clang\\17" "-internal-isystem" "C:\\DoesNotExist\\LLVM\\lib\\clang\\17\\include" "-internal-isystem" "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Professional\\VC\\Tools\\MSVC\\14.29.30133\\include" "-internal-isystem" "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Professional\\VC\\Tools\\MSVC\\14.29.30133\\atlmfc\\include" "-internal-isystem" "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.19041.0\\ucrt" "-internal-isystem" "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.19041.0\\shared" "-internal-isystem" "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.19041.0\\um" "-internal-isystem" "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.19041.0\\winrt" "-internal-isystem" "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.19041.0\\cppwinrt" "-fdebug-compilation-dir=C:\\DoesNotExist\\Temp" "-ferror-limit" "19" "-fno-use-cxa-atexit" "-fms-extensions" "-fms-compatibility" "-fms-compatibility-version=19.29.30152" "-fdelayed-template-parsing" "-faddrsig" "-o" "C:\\DoesNotExist\\Temp\\CMakeCCompilerABI-ebc8cc.obj" "-x" "c" "CMakeCCompilerABI.c" + "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Professional\\VC\\Tools\\MSVC\\14.29.30133\\bin\\Hostx64\\x64\\link.exe" "-out:CMakeCCompilerABI.exe" "-libpath:C:\\DoesNotExist\\LLVM\\lib\\clang\\17\\lib\\windows" "-nologo" "C:\\DoesNotExist\\Temp\\CMakeCCompilerABI-ebc8cc.obj" diff --git a/Tests/RunCMake/ParseImplicitData/windows_x86_64-CXX-Clang-17.0.1-MSVC.input b/Tests/RunCMake/ParseImplicitData/windows_x86_64-CXX-Clang-17.0.1-MSVC.input new file mode 100644 index 0000000..756fd13 --- /dev/null +++ b/Tests/RunCMake/ParseImplicitData/windows_x86_64-CXX-Clang-17.0.1-MSVC.input @@ -0,0 +1,20 @@ +CMAKE_LANG=CXX +CMAKE_LINKER= +CMAKE_CXX_COMPILER_ABI= +CMAKE_CXX_COMPILER_AR= +CMAKE_CXX_COMPILER_ARCHITECTURE_ID=x64 +CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN= +CMAKE_CXX_COMPILER_ID=Clang +CMAKE_CXX_COMPILER_LAUNCHER= +CMAKE_CXX_COMPILER_LOADED=1 +CMAKE_CXX_COMPILER_RANLIB= +CMAKE_CXX_COMPILER_TARGET= +CMAKE_CXX_COMPILER_VERSION=17.0.1 +CMAKE_CXX_COMPILER_VERSION_INTERAL= +CMAKE_CXX_SIMULATE_ID=MSVC +clang version 17.0.1 +Target: x86_64-pc-windows-msvc +Thread model: posix +InstalledDir: C:\DoesNotExist\LLVM\bin + "C:\\DoesNotExist\\LLVM\\bin\\clang-cl.exe" "-cc1" "-triple" "x86_64-pc-windows-msvc19.29.30152" "-emit-obj" "-mrelax-all" "-mincremental-linker-compatible" "-dumpdir" "a-" "-disable-free" "-clear-ast-before-backend" "-main-file-name" "CMakeCXXCompilerABI.cpp" "-mrelocation-model" "pic" "-pic-level" "2" "-mframe-pointer=none" "-relaxed-aliasing" "-fmath-errno" "-ffp-contract=on" "-fno-rounding-math" "-mconstructor-aliases" "-funwind-tables=2" "-target-cpu" "x86-64" "-mllvm" "-x86-asm-syntax=intel" "-tune-cpu" "generic" "-D_MT" "-flto-visibility-public-std" "--dependent-lib=libcmt" "--dependent-lib=oldnames" "-stack-protector" "2" "-fms-volatile" "-fdiagnostics-format" "msvc" "-fcoverage-compilation-dir=C:\\DoesNotExist\\Temp" "-resource-dir" "C:\\DoesNotExist\\LLVM\\lib\\clang\\17" "-internal-isystem" "C:\\DoesNotExist\\LLVM\\lib\\clang\\17\\include" "-internal-isystem" "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Professional\\VC\\Tools\\MSVC\\14.29.30133\\include" "-internal-isystem" "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Professional\\VC\\Tools\\MSVC\\14.29.30133\\atlmfc\\include" "-internal-isystem" "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.19041.0\\ucrt" "-internal-isystem" "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.19041.0\\shared" "-internal-isystem" "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.19041.0\\um" "-internal-isystem" "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.19041.0\\winrt" "-internal-isystem" "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.19041.0\\cppwinrt" "-fdeprecated-macro" "-fdebug-compilation-dir=C:\\DoesNotExist\\Temp" "-ferror-limit" "19" "-fno-use-cxa-atexit" "-fms-extensions" "-fms-compatibility" "-fms-compatibility-version=19.29.30152" "-std=c++14" "-fdelayed-template-parsing" "-faddrsig" "-o" "C:\\DoesNotExist\\Temp\\CMakeCXXCompilerABI-9170e6.obj" "-x" "c++" "CMakeCXXCompilerABI.cpp" + "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Professional\\VC\\Tools\\MSVC\\14.29.30133\\bin\\Hostx64\\x64\\link.exe" "-out:CMakeCXXCompilerABI.exe" "-libpath:C:\\DoesNotExist\\LLVM\\lib\\clang\\17\\lib\\windows" "-nologo" "C:\\DoesNotExist\\Temp\\CMakeCXXCompilerABI-9170e6.obj" diff --git a/Tests/RunCMake/ParseImplicitData/windows_x86_64-Fortran-LLVMFlang-17.0.1-MSVC.input b/Tests/RunCMake/ParseImplicitData/windows_x86_64-Fortran-LLVMFlang-17.0.1-MSVC.input new file mode 100644 index 0000000..fb75b51 --- /dev/null +++ b/Tests/RunCMake/ParseImplicitData/windows_x86_64-Fortran-LLVMFlang-17.0.1-MSVC.input @@ -0,0 +1,20 @@ +CMAKE_LANG=Fortran +CMAKE_LINKER= +CMAKE_Fortran_COMPILER_ABI= +CMAKE_Fortran_COMPILER_AR= +CMAKE_Fortran_COMPILER_ARCHITECTURE_ID=x64 +CMAKE_Fortran_COMPILER_EXTERNAL_TOOLCHAIN= +CMAKE_Fortran_COMPILER_ID=LLVMFlang +CMAKE_Fortran_COMPILER_LAUNCHER= +CMAKE_Fortran_COMPILER_LOADED=1 +CMAKE_Fortran_COMPILER_RANLIB= +CMAKE_Fortran_COMPILER_TARGET= +CMAKE_Fortran_COMPILER_VERSION=17.0.1 +CMAKE_Fortran_COMPILER_VERSION_INTERAL= +CMAKE_Fortran_SIMULATE_ID=MSVC +flang-new version 17.0.1 +Target: x86_64-pc-windows-msvc +Thread model: posix +InstalledDir: C:\DoesNotExist\LLVM\bin + "C:\\DoesNotExist\\LLVM\\bin\\flang-new" "-fc1" "-triple" "x86_64-pc-windows-msvc19.29.30152" "-emit-obj" "-mrelocation-model" "pic" "-pic-level" "2" "-target-cpu" "x86-64" "-o" "C:\\DoesNotExist\\Temp\\CMakeFortranCompilerABI-54be37.o" "-x" "f95-cpp-input" "CMakeFortranCompilerABI.F" + "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Professional\\VC\\Tools\\MSVC\\14.29.30133\\bin\\Hostx64\\x64\\link.exe" "-out:a.exe" "-libpath:C:\\DoesNotExist\\LLVM\\lib" "Fortran_main.lib" "FortranRuntime.lib" "FortranDecimal.lib" "/subsystem:console" "-libpath:C:\\DoesNotExist\\LLVM\\lib\\clang\\17\\lib\\windows" "-nologo" "C:\\DoesNotExist\\Temp\\CMakeFortranCompilerABI-54be37.o" diff --git a/Tests/RunCMake/ParseImplicitLinkInfo/ParseImplicitLinkInfo.cmake b/Tests/RunCMake/ParseImplicitLinkInfo/ParseImplicitLinkInfo.cmake index fa7bf07..04998a2 100644 --- a/Tests/RunCMake/ParseImplicitLinkInfo/ParseImplicitLinkInfo.cmake +++ b/Tests/RunCMake/ParseImplicitLinkInfo/ParseImplicitLinkInfo.cmake @@ -42,6 +42,8 @@ set(targets netbsd_nostdinc-C-GNU-4.8.5 netbsd_nostdinc-CXX-GNU-4.8.5 openbsd-C-Clang-5.0.1 openbsd-CXX-Clang-5.0.1 sunos-C-SunPro-5.13.0 sunos-CXX-SunPro-5.13.0 sunos-Fortran-SunPro-8.8.0 + windows_x86_64-C-Clang-17.0.1-MSVC windows_x86_64-CXX-Clang-17.0.1-MSVC windows_x86_64-Fortran-LLVMFlang-17.0.1-MSVC + windows_arm64-C-Clang-17.0.1-MSVC windows_arm64-CXX-Clang-17.0.1-MSVC windows_arm64-Fortran-LLVMFlang-17.0.1-MSVC ) if(CMAKE_HOST_WIN32) diff --git a/Tests/RunCMake/ParseImplicitLinkInfo/results/windows_arm64-C-Clang-17.0.1-MSVC.output b/Tests/RunCMake/ParseImplicitLinkInfo/results/windows_arm64-C-Clang-17.0.1-MSVC.output new file mode 100644 index 0000000..df9ef98 --- /dev/null +++ b/Tests/RunCMake/ParseImplicitLinkInfo/results/windows_arm64-C-Clang-17.0.1-MSVC.output @@ -0,0 +1,2 @@ +libs= +dirs=C:/DoesNotExist/LLVM/lib/clang/17/lib/windows diff --git a/Tests/RunCMake/ParseImplicitLinkInfo/results/windows_arm64-CXX-Clang-17.0.1-MSVC.output b/Tests/RunCMake/ParseImplicitLinkInfo/results/windows_arm64-CXX-Clang-17.0.1-MSVC.output new file mode 100644 index 0000000..df9ef98 --- /dev/null +++ b/Tests/RunCMake/ParseImplicitLinkInfo/results/windows_arm64-CXX-Clang-17.0.1-MSVC.output @@ -0,0 +1,2 @@ +libs= +dirs=C:/DoesNotExist/LLVM/lib/clang/17/lib/windows diff --git a/Tests/RunCMake/ParseImplicitLinkInfo/results/windows_arm64-Fortran-LLVMFlang-17.0.1-MSVC.output b/Tests/RunCMake/ParseImplicitLinkInfo/results/windows_arm64-Fortran-LLVMFlang-17.0.1-MSVC.output new file mode 100644 index 0000000..65f3494 --- /dev/null +++ b/Tests/RunCMake/ParseImplicitLinkInfo/results/windows_arm64-Fortran-LLVMFlang-17.0.1-MSVC.output @@ -0,0 +1,2 @@ +libs=Fortran_main\.lib;FortranRuntime\.lib;FortranDecimal\.lib +dirs=C:/DoesNotExist/LLVM/lib;C:/DoesNotExist/LLVM/lib/clang/17/lib/windows diff --git a/Tests/RunCMake/ParseImplicitLinkInfo/results/windows_x86_64-C-Clang-17.0.1-MSVC.output b/Tests/RunCMake/ParseImplicitLinkInfo/results/windows_x86_64-C-Clang-17.0.1-MSVC.output new file mode 100644 index 0000000..df9ef98 --- /dev/null +++ b/Tests/RunCMake/ParseImplicitLinkInfo/results/windows_x86_64-C-Clang-17.0.1-MSVC.output @@ -0,0 +1,2 @@ +libs= +dirs=C:/DoesNotExist/LLVM/lib/clang/17/lib/windows diff --git a/Tests/RunCMake/ParseImplicitLinkInfo/results/windows_x86_64-CXX-Clang-17.0.1-MSVC.output b/Tests/RunCMake/ParseImplicitLinkInfo/results/windows_x86_64-CXX-Clang-17.0.1-MSVC.output new file mode 100644 index 0000000..df9ef98 --- /dev/null +++ b/Tests/RunCMake/ParseImplicitLinkInfo/results/windows_x86_64-CXX-Clang-17.0.1-MSVC.output @@ -0,0 +1,2 @@ +libs= +dirs=C:/DoesNotExist/LLVM/lib/clang/17/lib/windows diff --git a/Tests/RunCMake/ParseImplicitLinkInfo/results/windows_x86_64-Fortran-LLVMFlang-17.0.1-MSVC.output b/Tests/RunCMake/ParseImplicitLinkInfo/results/windows_x86_64-Fortran-LLVMFlang-17.0.1-MSVC.output new file mode 100644 index 0000000..65f3494 --- /dev/null +++ b/Tests/RunCMake/ParseImplicitLinkInfo/results/windows_x86_64-Fortran-LLVMFlang-17.0.1-MSVC.output @@ -0,0 +1,2 @@ +libs=Fortran_main\.lib;FortranRuntime\.lib;FortranDecimal\.lib +dirs=C:/DoesNotExist/LLVM/lib;C:/DoesNotExist/LLVM/lib/clang/17/lib/windows -- cgit v0.12 From 7571e653f4142806c134e2864a937109471ea82e Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 28 Sep 2023 19:18:24 -0400 Subject: CMakeDetermineCompilerABI: Add option to skip implicit link info parsing Provide a way to do the parsing earlier and not overwrite it here. --- Modules/CMakeDetermineCompilerABI.cmake | 72 ++++++++++++++++++--------------- 1 file changed, 40 insertions(+), 32 deletions(-) diff --git a/Modules/CMakeDetermineCompilerABI.cmake b/Modules/CMakeDetermineCompilerABI.cmake index 7d8fa19..efc18f9 100644 --- a/Modules/CMakeDetermineCompilerABI.cmake +++ b/Modules/CMakeDetermineCompilerABI.cmake @@ -139,38 +139,46 @@ function(CMAKE_DETERMINE_COMPILER_ABI lang src) endif() set(CMAKE_${lang}_IMPLICIT_INCLUDE_DIRECTORIES "${_CMAKE_${lang}_IMPLICIT_INCLUDE_DIRECTORIES_INIT}" PARENT_SCOPE) - # Parse implicit linker information for this language, if available. - set(implicit_dirs "") - set(implicit_objs "") - set(implicit_libs "") - set(implicit_fwks "") - if(CMAKE_${lang}_VERBOSE_FLAG) - CMAKE_PARSE_IMPLICIT_LINK_INFO("${OUTPUT}" implicit_libs implicit_dirs implicit_fwks log - "${CMAKE_${lang}_IMPLICIT_OBJECT_REGEX}" - COMPUTE_IMPLICIT_OBJECTS implicit_objs - LANGUAGE ${lang}) - message(CONFIGURE_LOG - "Parsed ${lang} implicit link information:\n${log}\n\n") - endif() - # for VS IDE Intel Fortran we have to figure out the - # implicit link path for the fortran run time using - # a try-compile - if("${lang}" MATCHES "Fortran" - AND "${CMAKE_GENERATOR}" MATCHES "Visual Studio") - message(CHECK_START "Determine Intel Fortran Compiler Implicit Link Path") - # Build a sample project which reports symbols. - try_compile(IFORT_LIB_PATH_COMPILED - PROJECT IntelFortranImplicit - SOURCE_DIR ${CMAKE_ROOT}/Modules/IntelVSImplicitPath - BINARY_DIR ${CMAKE_BINARY_DIR}/CMakeFiles/IntelVSImplicitPath - CMAKE_FLAGS - "-DCMAKE_Fortran_FLAGS:STRING=${CMAKE_Fortran_FLAGS}" - OUTPUT_VARIABLE _output) - file(WRITE - "${CMAKE_BINARY_DIR}/CMakeFiles/IntelVSImplicitPath/output.txt" - "${_output}") - include(${CMAKE_BINARY_DIR}/CMakeFiles/IntelVSImplicitPath/output.cmake OPTIONAL) - message(CHECK_PASS "done") + if(_CMAKE_${lang}_IMPLICIT_LINK_INFORMATION_DETERMINED_EARLY) + # Use implicit linker information detected during compiler id step. + set(implicit_dirs "${CMAKE_${lang}_IMPLICIT_LINK_DIRECTORIES}") + set(implicit_objs "") + set(implicit_libs "${CMAKE_${lang}_IMPLICIT_LINK_LIBRARIES}") + set(implicit_fwks "${CMAKE_${lang}_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES}") + else() + # Parse implicit linker information for this language, if available. + set(implicit_dirs "") + set(implicit_objs "") + set(implicit_libs "") + set(implicit_fwks "") + if(CMAKE_${lang}_VERBOSE_FLAG) + CMAKE_PARSE_IMPLICIT_LINK_INFO("${OUTPUT}" implicit_libs implicit_dirs implicit_fwks log + "${CMAKE_${lang}_IMPLICIT_OBJECT_REGEX}" + COMPUTE_IMPLICIT_OBJECTS implicit_objs + LANGUAGE ${lang}) + message(CONFIGURE_LOG + "Parsed ${lang} implicit link information:\n${log}\n\n") + endif() + # for VS IDE Intel Fortran we have to figure out the + # implicit link path for the fortran run time using + # a try-compile + if("${lang}" MATCHES "Fortran" + AND "${CMAKE_GENERATOR}" MATCHES "Visual Studio") + message(CHECK_START "Determine Intel Fortran Compiler Implicit Link Path") + # Build a sample project which reports symbols. + try_compile(IFORT_LIB_PATH_COMPILED + PROJECT IntelFortranImplicit + SOURCE_DIR ${CMAKE_ROOT}/Modules/IntelVSImplicitPath + BINARY_DIR ${CMAKE_BINARY_DIR}/CMakeFiles/IntelVSImplicitPath + CMAKE_FLAGS + "-DCMAKE_Fortran_FLAGS:STRING=${CMAKE_Fortran_FLAGS}" + OUTPUT_VARIABLE _output) + file(WRITE + "${CMAKE_BINARY_DIR}/CMakeFiles/IntelVSImplicitPath/output.txt" + "${_output}") + include(${CMAKE_BINARY_DIR}/CMakeFiles/IntelVSImplicitPath/output.cmake OPTIONAL) + message(CHECK_PASS "done") + endif() endif() # Implicit link libraries cannot be used explicitly for multiple -- cgit v0.12 From 9d060b8682888e4159ccbd03194c821c5d4233f0 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 28 Sep 2023 19:19:42 -0400 Subject: Fortran: Save CMAKE_LINKER variable persistently for MSVC ABI We already do this for other languages including C and CXX. --- Modules/CMakeFortranCompiler.cmake.in | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Modules/CMakeFortranCompiler.cmake.in b/Modules/CMakeFortranCompiler.cmake.in index 6a2be28..89a00ab 100644 --- a/Modules/CMakeFortranCompiler.cmake.in +++ b/Modules/CMakeFortranCompiler.cmake.in @@ -14,8 +14,9 @@ set(CMAKE_Fortran_SIMULATE_VERSION "@CMAKE_Fortran_SIMULATE_VERSION@") set(CMAKE_AR "@CMAKE_AR@") set(CMAKE_Fortran_COMPILER_AR "@CMAKE_Fortran_COMPILER_AR@") set(CMAKE_RANLIB "@CMAKE_RANLIB@") -set(CMAKE_TAPI "@CMAKE_TAPI@") +set(CMAKE_LINKER "@CMAKE_LINKER@") set(CMAKE_Fortran_COMPILER_RANLIB "@CMAKE_Fortran_COMPILER_RANLIB@") +set(CMAKE_TAPI "@CMAKE_TAPI@") set(CMAKE_COMPILER_IS_GNUG77 @CMAKE_COMPILER_IS_GNUG77@) set(CMAKE_Fortran_COMPILER_LOADED 1) set(CMAKE_Fortran_COMPILER_WORKS @CMAKE_Fortran_COMPILER_WORKS@) -- cgit v0.12 From 26fa048ffed9657602eda3eb478cf5abe97d37a4 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 28 Sep 2023 19:22:18 -0400 Subject: Tests: Enable CMP0091/CMP0141 for MSVC settings in FortranOnly test --- Tests/FortranOnly/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/FortranOnly/CMakeLists.txt b/Tests/FortranOnly/CMakeLists.txt index 02bf2b8..73312a0 100644 --- a/Tests/FortranOnly/CMakeLists.txt +++ b/Tests/FortranOnly/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.5...3.25) # Enable CMP0091 and CMP0141. project(FortranOnly Fortran) message("CTEST_FULL_OUTPUT ") -- cgit v0.12 From e9af7b968756e72553296ecdcde6f36606a0babf Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 28 Sep 2023 19:23:23 -0400 Subject: LLVMFlang: Add support for CMAKE_Fortran_COMPILER_TARGET --- Modules/Compiler/LLVMFlang-Fortran.cmake | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Modules/Compiler/LLVMFlang-Fortran.cmake b/Modules/Compiler/LLVMFlang-Fortran.cmake index 291413e..6b0c0fc 100644 --- a/Modules/Compiler/LLVMFlang-Fortran.cmake +++ b/Modules/Compiler/LLVMFlang-Fortran.cmake @@ -15,6 +15,8 @@ set(CMAKE_Fortran_COMPILE_OPTIONS_PREPROCESS_ON "-cpp") set(CMAKE_Fortran_COMPILE_OPTIONS_PREPROCESS_OFF "-nocpp") set(CMAKE_Fortran_POSTPROCESS_FLAG "-ffixed-line-length-72") +set(CMAKE_Fortran_COMPILE_OPTIONS_TARGET "--target=") + string(APPEND CMAKE_Fortran_FLAGS_DEBUG_INIT " -O0 -g") string(APPEND CMAKE_Fortran_FLAGS_RELWITHDEBINFO_INIT " -O2 -g") string(APPEND CMAKE_Fortran_FLAGS_RELEASE_INIT " -O3") -- cgit v0.12 From 26bf32cdc67271547ca0b0d38872f8f23a90d191 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 28 Sep 2023 19:36:56 -0400 Subject: LLVMFlang: Add support for targeting MSVC ABI on Windows The compiler does not yet support everything needed to integrate well with the MSVC ABI, in particular for runtime library selection and debug format selection. Document them in FIXME comments and leave this support undocumented by CMake for now. Fixes: #24840 Inspired-by: Pierrick Bouvier --- Modules/CMakeDetermineCompilerId.cmake | 26 ++++++++++ Modules/CMakeDetermineFortranCompiler.cmake | 50 +++++++++++++++++++ Modules/CMakeFindBinUtils.cmake | 2 +- Modules/Compiler/LLVMFlang-Fortran.cmake | 12 +++-- Modules/Platform/Windows-LLVMFlang-Fortran.cmake | 61 ++++++++++++++++++++++-- Tests/CMakeLists.txt | 9 +++- Tests/Fortran/CMakeLists.txt | 2 +- Tests/MSVCRuntimeLibrary/Fortran/CMakeLists.txt | 7 +++ 8 files changed, 158 insertions(+), 11 deletions(-) diff --git a/Modules/CMakeDetermineCompilerId.cmake b/Modules/CMakeDetermineCompilerId.cmake index 9d3b60f..4f1eaba 100644 --- a/Modules/CMakeDetermineCompilerId.cmake +++ b/Modules/CMakeDetermineCompilerId.cmake @@ -174,6 +174,32 @@ 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. + if(COMPILER_${lang}_PRODUCED_OUTPUT MATCHES "-triple ([0-9a-z_]*)-.*windows-msvc([0-9]+)\\.([0-9]+)") + set(CMAKE_${lang}_SIMULATE_ID "MSVC") + 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}") + 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() + endif() + if (COMPILER_QNXNTO AND (CMAKE_${lang}_COMPILER_ID STREQUAL "GNU" OR CMAKE_${lang}_COMPILER_ID STREQUAL "LCC")) execute_process( COMMAND "${CMAKE_${lang}_COMPILER}" diff --git a/Modules/CMakeDetermineFortranCompiler.cmake b/Modules/CMakeDetermineFortranCompiler.cmake index 8cbaf70..392f0f1 100644 --- a/Modules/CMakeDetermineFortranCompiler.cmake +++ b/Modules/CMakeDetermineFortranCompiler.cmake @@ -98,6 +98,9 @@ else() set(CMAKE_Fortran_COMPILER_ID_TEST_FLAGS_FIRST # Get verbose output to help distinguish compilers. "-v" + + # Try compiling to an object file only, with verbose output. + "-v -c" ) set(CMAKE_Fortran_COMPILER_ID_TEST_FLAGS # Try compiling to an object file only. @@ -108,6 +111,10 @@ else() ) endif() +if(CMAKE_Fortran_COMPILER_TARGET) + set(CMAKE_Fortran_COMPILER_ID_TEST_FLAGS_FIRST "-v -c --target=${CMAKE_Fortran_COMPILER_TARGET}") +endif() + # Build a small source file to identify the compiler. if(NOT CMAKE_Fortran_COMPILER_ID_RUN) set(CMAKE_Fortran_COMPILER_ID_RUN 1) @@ -227,6 +234,49 @@ if(NOT CMAKE_Fortran_COMPILER_ID_RUN) endif() endif() +if("${CMAKE_Fortran_COMPILER_ID};${CMAKE_Fortran_SIMULATE_ID}" STREQUAL "LLVMFlang;MSVC") + # With LLVMFlang targeting the MSVC ABI we link using lld-link. + # Detect the implicit link information from the compiler driver + # so we can explicitly pass it to the linker. + include(${CMAKE_ROOT}/Modules/CMakeParseImplicitLinkInfo.cmake) + set(_LLVMFlang_COMMAND "${CMAKE_Fortran_COMPILER}" "-###" ${CMAKE_CURRENT_LIST_DIR}/CMakeFortranCompilerABI.F) + if(CMAKE_Fortran_COMPILER_TARGET) + list(APPEND _LLVMFlang_COMMAND --target=${CMAKE_Fortran_COMPILER_TARGET}) + endif() + execute_process(COMMAND ${_LLVMFlang_COMMAND} + OUTPUT_VARIABLE _LLVMFlang_OUTPUT + ERROR_VARIABLE _LLVMFlang_OUTPUT + RESULT_VARIABLE _LLVMFlang_RESULT) + string(JOIN "\" \"" _LLVMFlang_COMMAND ${_LLVMFlang_COMMAND}) + message(CONFIGURE_LOG + "Running the Fortran compiler: \"${_LLVMFlang_COMMAND}\"\n" + "${_LLVMFlang_OUTPUT}" + ) + if(_LLVMFlang_RESULT EQUAL 0) + cmake_parse_implicit_link_info("${_LLVMFlang_OUTPUT}" + CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES + CMAKE_Fortran_IMPLICIT_LINK_DIRECTORIES + CMAKE_Fortran_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES + log + "${CMAKE_Fortran_IMPLICIT_OBJECT_REGEX}" + LANGUAGE Fortran) + message(CONFIGURE_LOG + "Parsed Fortran implicit link information:\n" + "${log}\n" + ) + set(_CMAKE_Fortran_IMPLICIT_LINK_INFORMATION_DETERMINED_EARLY 1) + if("x${CMAKE_Fortran_COMPILER_ARCHITECTURE_ID}" STREQUAL "xARM64") + # FIXME(LLVMFlang): It does not add `-defaultlib:` fields to object + # files to specify link dependencies on its runtime libraries. + # For now, we add them ourselves. + list(APPEND CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES "clang_rt.builtins-aarch64.lib") + endif() + endif() + unset(_LLVMFlang_COMMAND) + unset(_LLVMFlang_OUTPUT) + unset(_LLVMFlang_RESULT) +endif() + if (NOT _CMAKE_TOOLCHAIN_LOCATION) get_filename_component(_CMAKE_TOOLCHAIN_LOCATION "${CMAKE_Fortran_COMPILER}" PATH) endif () diff --git a/Modules/CMakeFindBinUtils.cmake b/Modules/CMakeFindBinUtils.cmake index 431d00b..e12b175 100644 --- a/Modules/CMakeFindBinUtils.cmake +++ b/Modules/CMakeFindBinUtils.cmake @@ -79,7 +79,7 @@ if(("x${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_SIMULATE_ID}" STREQUAL "xMSVC" AND set(_CMAKE_MT_NAMES "mt") # Prepend toolchain-specific names. - if("x${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_ID}" STREQUAL "xClang") + if("x${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_ID}" MATCHES "^x(Clang|LLVMFlang)$") set(_CMAKE_NM_NAMES "llvm-nm" "nm") list(PREPEND _CMAKE_AR_NAMES "llvm-lib") # llvm-mt is not ready to be used as a replacement for mt.exe diff --git a/Modules/Compiler/LLVMFlang-Fortran.cmake b/Modules/Compiler/LLVMFlang-Fortran.cmake index 6b0c0fc..d27f094 100644 --- a/Modules/Compiler/LLVMFlang-Fortran.cmake +++ b/Modules/Compiler/LLVMFlang-Fortran.cmake @@ -1,5 +1,3 @@ -set(CMAKE_Fortran_VERBOSE_FLAG "-v") - set(CMAKE_Fortran_SUBMODULE_SEP "-") set(CMAKE_Fortran_SUBMODULE_EXT ".mod") @@ -17,6 +15,10 @@ set(CMAKE_Fortran_POSTPROCESS_FLAG "-ffixed-line-length-72") set(CMAKE_Fortran_COMPILE_OPTIONS_TARGET "--target=") -string(APPEND CMAKE_Fortran_FLAGS_DEBUG_INIT " -O0 -g") -string(APPEND CMAKE_Fortran_FLAGS_RELWITHDEBINFO_INIT " -O2 -g") -string(APPEND CMAKE_Fortran_FLAGS_RELEASE_INIT " -O3") +if(NOT "x${CMAKE_Fortran_SIMULATE_ID}" STREQUAL "xMSVC") + set(CMAKE_Fortran_VERBOSE_FLAG "-v") + + string(APPEND CMAKE_Fortran_FLAGS_DEBUG_INIT " -O0 -g") + string(APPEND CMAKE_Fortran_FLAGS_RELWITHDEBINFO_INIT " -O2 -g") + string(APPEND CMAKE_Fortran_FLAGS_RELEASE_INIT " -O3") +endif() diff --git a/Modules/Platform/Windows-LLVMFlang-Fortran.cmake b/Modules/Platform/Windows-LLVMFlang-Fortran.cmake index 64dc0da..3e22a6e 100644 --- a/Modules/Platform/Windows-LLVMFlang-Fortran.cmake +++ b/Modules/Platform/Windows-LLVMFlang-Fortran.cmake @@ -1,3 +1,58 @@ -include(Platform/Windows-GNU) -__windows_compiler_gnu(Fortran) -# TODO: MSVC ABI Support +if("x${CMAKE_Fortran_SIMULATE_ID}" STREQUAL "xGNU") + include(Platform/Windows-GNU) + __windows_compiler_gnu(Fortran) +elseif("x${CMAKE_Fortran_SIMULATE_ID}" STREQUAL "xMSVC") + include(Platform/Windows-MSVC) + __windows_compiler_msvc(Fortran) + + # FIXME(LLVMFlang): It does not provides MSVC runtime library selection flags. + # It should be given a flag like classic Flang's `-Xclang --dependent-lib=`, or a + # dedicated flag to select among multiple `Fortran*.lib` runtime library variants + # that each depend on a different MSVC runtime library. For now, LLVMFlang's + # `Fortran*.lib` runtime libraries hard-code use of msvcrt (MultiThreadedDLL), + # so we link to it ourselves. + set(_LLVMFlang_LINK_RUNTIME "-defaultlib:msvcrt") + set(CMAKE_Fortran_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreaded "") + set(CMAKE_Fortran_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDLL "") + set(CMAKE_Fortran_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDebug "") + set(CMAKE_Fortran_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDebugDLL "") + + # FIXME(LLVMFlang): It does not provide all debug information format flags or predefines. + # It should be given a flag to enable Embedded debug information like MSVC -Z7. + #set(CMAKE_Fortran_COMPILE_OPTIONS_MSVC_DEBUG_INFORMATION_FORMAT_Embedded) # not supported by LLVMFlang + #set(CMAKE_Fortran_COMPILE_OPTIONS_MSVC_DEBUG_INFORMATION_FORMAT_EditAndContinue) # not supported by LLVMFlang + set(CMAKE_Fortran_COMPILE_OPTIONS_MSVC_DEBUG_INFORMATION_FORMAT_ProgramDatabase "-g") + + set(CMAKE_Fortran_COMPILE_OBJECT " -o -c ") + + if(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT_DEFAULT) + set(_g "") + else() + set(_g " -g") + endif() + string(APPEND CMAKE_Fortran_FLAGS_DEBUG_INIT "${_g}") + string(APPEND CMAKE_Fortran_FLAGS_RELEASE_INIT "") + string(APPEND CMAKE_Fortran_FLAGS_RELWITHDEBINFO_INIT "${_g}") + string(APPEND CMAKE_Fortran_FLAGS_MINSIZEREL_INIT "") + unset(_g) + + # We link with lld-link.exe instead of the compiler driver, so explicitly + # pass implicit link information previously detected from the compiler. + set(_LLVMFlang_LINK_DIRS "${CMAKE_Fortran_IMPLICIT_LINK_DIRECTORIES}") + list(TRANSFORM _LLVMFlang_LINK_DIRS PREPEND "-libpath:\"") + list(TRANSFORM _LLVMFlang_LINK_DIRS APPEND "\"") + string(JOIN " " _LLVMFlang_LINK_DIRS ${_LLVMFlang_LINK_DIRS}) + string(JOIN " " _LLVMFlang_LINK_LIBS ${CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES}) + foreach(v IN ITEMS + CMAKE_Fortran_LINK_EXECUTABLE + CMAKE_Fortran_CREATE_SHARED_LIBRARY + CMAKE_Fortran_CREATE_SHARED_MODULE + ) + string(APPEND "${v}" " ${_LLVMFlang_LINK_DIRS} ${_LLVMFlang_LINK_LIBS} ${_LLVMFlang_LINK_RUNTIME}") + endforeach() + unset(_LLVMFlang_LINK_DIRS) + unset(_LLVMFlang_LINK_LIBS) + unset(_LLVMFlang_LINK_RUNTIME) +else() + message(FATAL_ERROR "LLVMFlang target ABI unrecognized: ${CMAKE_Fortran_SIMULATE_ID}") +endif() diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index 915c974..4c61eab 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -439,6 +439,10 @@ if(BUILD_TESTING) set(CMAKE_SKIP_VSGNUFortran TRUE) endif() endif() + if(CMAKE_Fortran_COMPILER_ID STREQUAL LLVMFlang) + # No DLLEXPORT for 'Tests/VSGNUFortran/subdir/fortran/world.f'. + set(CMAKE_SKIP_VSGNUFortran TRUE) + endif() if(CMAKE_Fortran_COMPILER_ID STREQUAL IntelLLVM) message(STATUS "Skip VSGNUFortran for ifx until DLLEXPORT support is implemented") set(CMAKE_SKIP_VSGNUFortran TRUE) @@ -2150,7 +2154,10 @@ if(BUILD_TESTING) endif() set(MSVCDebugInformationFormat_BUILD_OPTIONS -DCMake_TEST_CUDA=${CMake_TEST_CUDA}) - if(CMAKE_Fortran_COMPILER) + if(CMAKE_Fortran_COMPILER + # FIXME(LLVMFlang): It does not provide debug information format flags or predefines. + AND NOT CMAKE_Fortran_COMPILER_ID STREQUAL "LLVMFlang" + ) list(APPEND MSVCDebugInformationFormat_BUILD_OPTIONS -DCMake_TEST_Fortran=1) endif() ADD_TEST_MACRO(MSVCDebugInformationFormat) diff --git a/Tests/Fortran/CMakeLists.txt b/Tests/Fortran/CMakeLists.txt index 30ab16b..41d3b4e 100644 --- a/Tests/Fortran/CMakeLists.txt +++ b/Tests/Fortran/CMakeLists.txt @@ -29,7 +29,7 @@ endif() # Pick a module .def file with the properly mangled symbol name. set(world_def "") if(WIN32 AND NOT CYGWIN) - if(CMAKE_Fortran_COMPILER_ID MATCHES "GNU|LCC") + if(CMAKE_Fortran_COMPILER_ID MATCHES "GNU|LCC|LLVMFlang") set(world_def world_gnu.def) elseif(CMAKE_Fortran_COMPILER_ID MATCHES "Intel" OR CMAKE_GENERATOR MATCHES "Visual Studio") # Intel plugin diff --git a/Tests/MSVCRuntimeLibrary/Fortran/CMakeLists.txt b/Tests/MSVCRuntimeLibrary/Fortran/CMakeLists.txt index 41bd6f5..2a8a152 100644 --- a/Tests/MSVCRuntimeLibrary/Fortran/CMakeLists.txt +++ b/Tests/MSVCRuntimeLibrary/Fortran/CMakeLists.txt @@ -21,6 +21,13 @@ foreach(t MultiThreaded SingleThreaded) endforeach() endforeach() endforeach() +if(CMAKE_Fortran_COMPILER_ID STREQUAL "LLVMFlang") + # LLVMFlang does not actually define these, so inject them + set(CMAKE_Fortran_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreaded "-D_MT") + set(CMAKE_Fortran_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDLL "-D_MT;-D_DLL") + set(CMAKE_Fortran_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDebug "-D_MT;-D_DEBUG") + set(CMAKE_Fortran_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDebugDLL "-D_MT;-D_DEBUG;-D_DLL") +endif() string(APPEND CMAKE_Fortran_FLAGS " -w") function(verify_combinations threads lang src) -- cgit v0.12