From 7598ea5389e04862c567b43d7c08fbbc66512f37 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 7 Dec 2023 10:13:01 -0500 Subject: Tests: Add case covering find_library behavior when targeting MSVC ABI --- Tests/RunCMake/CMakeLists.txt | 2 +- Tests/RunCMake/find_library/RunCMakeTest.cmake | 4 ++++ Tests/RunCMake/find_library/Windows-MSVC-stdout.txt | 1 + Tests/RunCMake/find_library/Windows-MSVC.cmake | 4 ++++ Tests/RunCMake/find_library/Windows-MSVC/static.lib | 0 5 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 Tests/RunCMake/find_library/Windows-MSVC-stdout.txt create mode 100644 Tests/RunCMake/find_library/Windows-MSVC.cmake create mode 100644 Tests/RunCMake/find_library/Windows-MSVC/static.lib diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index 9f0e928..e8f2ba3 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -529,7 +529,7 @@ endforeach() add_RunCMake_test(file-DOWNLOAD) add_RunCMake_test(file-RPATH -DCMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME}) add_RunCMake_test(find_file -DMINGW=${MINGW}) -add_RunCMake_test(find_library -DMINGW=${MINGW} -DCYGWIN=${CYGWIN} -DMSYS=${MSYS}) +add_RunCMake_test(find_library -DMINGW=${MINGW} -DCYGWIN=${CYGWIN} -DMSYS=${MSYS} -DMSVC=${MSVC}) add_RunCMake_test(find_package -DMINGW=${MINGW} -DMSYS=${MSYS}) add_RunCMake_test(find_path -DMINGW=${MINGW}) add_RunCMake_test(find_program -DCMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME}) diff --git a/Tests/RunCMake/find_library/RunCMakeTest.cmake b/Tests/RunCMake/find_library/RunCMakeTest.cmake index 0bed252..f9c8528 100644 --- a/Tests/RunCMake/find_library/RunCMakeTest.cmake +++ b/Tests/RunCMake/find_library/RunCMakeTest.cmake @@ -24,6 +24,10 @@ if(CMAKE_HOST_WIN32 AND MINGW) run_cmake(MSYSTEM_PREFIX) endif() +if(CMAKE_HOST_WIN32 AND MSVC) + run_cmake(Windows-MSVC) +endif() + run_cmake_script(FromScriptMode "-DTEMP_DIR=${RunCMake_BINARY_DIR}/FromScriptMode-temp") run_cmake_with_options(FromPATHEnvDebugVar --debug-find-var=CREATED_LIBRARY) diff --git a/Tests/RunCMake/find_library/Windows-MSVC-stdout.txt b/Tests/RunCMake/find_library/Windows-MSVC-stdout.txt new file mode 100644 index 0000000..af5c30b --- /dev/null +++ b/Tests/RunCMake/find_library/Windows-MSVC-stdout.txt @@ -0,0 +1 @@ +-- STATIC_LIBRARY='[^']*/Tests/RunCMake/find_library/Windows-MSVC/static.lib' diff --git a/Tests/RunCMake/find_library/Windows-MSVC.cmake b/Tests/RunCMake/find_library/Windows-MSVC.cmake new file mode 100644 index 0000000..212f2c4 --- /dev/null +++ b/Tests/RunCMake/find_library/Windows-MSVC.cmake @@ -0,0 +1,4 @@ +enable_language(C) + +find_library(STATIC_LIBRARY NAMES static NO_DEFAULT_PATH PATHS ${CMAKE_CURRENT_SOURCE_DIR}/Windows-MSVC) +message(STATUS "STATIC_LIBRARY='${STATIC_LIBRARY}'") diff --git a/Tests/RunCMake/find_library/Windows-MSVC/static.lib b/Tests/RunCMake/find_library/Windows-MSVC/static.lib new file mode 100644 index 0000000..e69de29 -- cgit v0.12 From f20c5c6f20aa7eab9e43919fffbf5b00281d1461 Mon Sep 17 00:00:00 2001 From: Daniel Ching Date: Wed, 6 Dec 2023 22:47:47 -0600 Subject: MSVC: Teach find_library to consider Rust's '${name}.dll.lib' convention This convention is used by Rust toolchains (rustc/cargo/cargo-c) for the MSVC ABI. Fixes: #25478 --- Help/release/dev/find-rustc-importlibs.rst | 6 ++++++ Help/variable/CMAKE_FIND_LIBRARY_SUFFIXES.rst | 10 +++++----- Modules/Platform/Windows.cmake | 5 ++++- Tests/RunCMake/find_library/Windows-MSVC-stdout.txt | 1 + Tests/RunCMake/find_library/Windows-MSVC.cmake | 3 +++ Tests/RunCMake/find_library/Windows-MSVC/rustc_import.dll.lib | 0 Tests/RunCMake/find_library/Windows-MSVC/rustc_import.lib | 0 7 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 Help/release/dev/find-rustc-importlibs.rst create mode 100644 Tests/RunCMake/find_library/Windows-MSVC/rustc_import.dll.lib create mode 100644 Tests/RunCMake/find_library/Windows-MSVC/rustc_import.lib diff --git a/Help/release/dev/find-rustc-importlibs.rst b/Help/release/dev/find-rustc-importlibs.rst new file mode 100644 index 0000000..646afff --- /dev/null +++ b/Help/release/dev/find-rustc-importlibs.rst @@ -0,0 +1,6 @@ +find-rustc-importlibs +--------------------- + +* On Windows, when targeting the MSVC ABI, the :command:`find_library` command + now considers ``.dll.lib`` file names before ``.lib``. This is the default + suffix for DLL import libraries created by Rust toolchains for the MSVC ABI. diff --git a/Help/variable/CMAKE_FIND_LIBRARY_SUFFIXES.rst b/Help/variable/CMAKE_FIND_LIBRARY_SUFFIXES.rst index c2c2609..d78dd15 100644 --- a/Help/variable/CMAKE_FIND_LIBRARY_SUFFIXES.rst +++ b/Help/variable/CMAKE_FIND_LIBRARY_SUFFIXES.rst @@ -5,8 +5,8 @@ Suffixes to append when looking for libraries. This specifies what suffixes to add to library names when the :command:`find_library` command looks for libraries. On Windows systems this -is typically ``.lib`` and, depending on the compiler, ``.dll.a``, ``.a`` -(e.g. GCC and Clang), so when it tries to find the ``foo`` library, it will -look for ``[]foo.lib`` and/or ``[]foo[.dll].a``, depending on -the compiler used and the ```` specified in the -:variable:`CMAKE_FIND_LIBRARY_PREFIXES`. +is typically ``.lib`` and, depending on the compiler, ``.dll.lib``, ``.dll.a``, +``.a`` (e.g. rustc, GCC, or Clang), so when it tries to find the ``foo`` +library, it will look for ``[]foo[.dll].lib`` and/or +``[]foo[.dll].a``, depending on the compiler used and the ```` +specified in the :variable:`CMAKE_FIND_LIBRARY_PREFIXES`. diff --git a/Modules/Platform/Windows.cmake b/Modules/Platform/Windows.cmake index 1bf39cf..bc93caa 100644 --- a/Modules/Platform/Windows.cmake +++ b/Modules/Platform/Windows.cmake @@ -14,7 +14,10 @@ set(CMAKE_DL_LIBS "") set(CMAKE_EXTRA_LINK_EXTENSIONS ".targets") set(CMAKE_FIND_LIBRARY_PREFIXES "") -set(CMAKE_FIND_LIBRARY_SUFFIXES ".lib") +set(CMAKE_FIND_LIBRARY_SUFFIXES + ".dll.lib" # import library from Rust toolchain for MSVC ABI + ".lib" # static or import library from MSVC tooling + ) # for borland make long command lines are redirected to a file # with the following syntax, see Windows-bcc32.cmake for use diff --git a/Tests/RunCMake/find_library/Windows-MSVC-stdout.txt b/Tests/RunCMake/find_library/Windows-MSVC-stdout.txt index af5c30b..598ede5 100644 --- a/Tests/RunCMake/find_library/Windows-MSVC-stdout.txt +++ b/Tests/RunCMake/find_library/Windows-MSVC-stdout.txt @@ -1 +1,2 @@ -- STATIC_LIBRARY='[^']*/Tests/RunCMake/find_library/Windows-MSVC/static.lib' +-- RUSTC_IMPORT_LIBRARY='[^']*/Tests/RunCMake/find_library/Windows-MSVC/rustc_import.dll.lib' diff --git a/Tests/RunCMake/find_library/Windows-MSVC.cmake b/Tests/RunCMake/find_library/Windows-MSVC.cmake index 212f2c4..485952d 100644 --- a/Tests/RunCMake/find_library/Windows-MSVC.cmake +++ b/Tests/RunCMake/find_library/Windows-MSVC.cmake @@ -2,3 +2,6 @@ enable_language(C) find_library(STATIC_LIBRARY NAMES static NO_DEFAULT_PATH PATHS ${CMAKE_CURRENT_SOURCE_DIR}/Windows-MSVC) message(STATUS "STATIC_LIBRARY='${STATIC_LIBRARY}'") + +find_library(RUSTC_IMPORT_LIBRARY NAMES rustc_import NO_DEFAULT_PATH PATHS ${CMAKE_CURRENT_SOURCE_DIR}/Windows-MSVC) +message(STATUS "RUSTC_IMPORT_LIBRARY='${RUSTC_IMPORT_LIBRARY}'") diff --git a/Tests/RunCMake/find_library/Windows-MSVC/rustc_import.dll.lib b/Tests/RunCMake/find_library/Windows-MSVC/rustc_import.dll.lib new file mode 100644 index 0000000..e69de29 diff --git a/Tests/RunCMake/find_library/Windows-MSVC/rustc_import.lib b/Tests/RunCMake/find_library/Windows-MSVC/rustc_import.lib new file mode 100644 index 0000000..e69de29 -- cgit v0.12