MSVC: Teach find_library to consider the 'libfoo.a' naming convention

When targeting the GNU ABI, we consider `.a` libraries first but also
accept `.lib`.  For symmetry, when targeting the MSVC ABI, we now
consider `.lib` first but also accept `.a`.

This adds support for meson-generated static libraries, which are named
with the pattern `lib${foo}.a`:

* https://mesonbuild.com/FAQ.html#why-does-building-my-project-with-msvc-output-static-libraries-called-libfooa

Note that this was previously attempted by

* commit be848a71b0 (MSVC: Teach find_library to consider the 'libfoo.a'
                     naming convention, 2022-09-19, v3.25.0-rc1~111^2)

but was reverted by

* commit 955d6245c1 (MSVC: Revert "Teach find_library to consider the
                     'libfoo.a' naming convention", 2022-11-28, v3.25.1~6^2)

due to problems finding GNU ABI libraries in PATH-derived prefixes.
Since then,

* commit 0a81110b84 (find_(library|file|path): Drop PATH-derived search
                     prefixes, 2023-09-14, v3.28.0-rc1~91^2)

removed the problematic search paths, so we can restore this change.

Fixes: #23975
This commit is contained in:
Brad King
2024-01-19 16:57:46 -05:00
parent 62ca95518e
commit c6efbd78d8
5 changed files with 16 additions and 1 deletions

View File

@@ -0,0 +1,7 @@
find_library-msvc-libfoo.a
--------------------------
* On Windows, when targeting the MSVC ABI, the :command:`find_library` command
now accepts ``.a`` file names after first considering ``.lib``. This is
symmetric with existing behavior when targeting the GNU ABI, in which the
command accepts ``.lib`` file names after first considering ``.a``.

View File

@@ -13,10 +13,14 @@ set(CMAKE_LINK_LIBRARY_SUFFIX ".lib")
set(CMAKE_DL_LIBS "") set(CMAKE_DL_LIBS "")
set(CMAKE_EXTRA_LINK_EXTENSIONS ".targets") set(CMAKE_EXTRA_LINK_EXTENSIONS ".targets")
set(CMAKE_FIND_LIBRARY_PREFIXES "") set(CMAKE_FIND_LIBRARY_PREFIXES
"" # static or import library from MSVC tooling
"lib" # static library from Meson with MSVC tooling
)
set(CMAKE_FIND_LIBRARY_SUFFIXES set(CMAKE_FIND_LIBRARY_SUFFIXES
".dll.lib" # import library from Rust toolchain for MSVC ABI ".dll.lib" # import library from Rust toolchain for MSVC ABI
".lib" # static or import library from MSVC tooling ".lib" # static or import library from MSVC tooling
".a" # static library from Meson with MSVC tooling
) )
# for borland make long command lines are redirected to a file # for borland make long command lines are redirected to a file

View File

@@ -1,2 +1,3 @@
-- STATIC_LIBRARY='[^']*/Tests/RunCMake/find_library/Windows-MSVC/static.lib' -- STATIC_LIBRARY='[^']*/Tests/RunCMake/find_library/Windows-MSVC/static.lib'
-- MESON_STATIC_LIBRARY='[^']*/Tests/RunCMake/find_library/Windows-MSVC/libmeson_static.a'
-- RUSTC_IMPORT_LIBRARY='[^']*/Tests/RunCMake/find_library/Windows-MSVC/rustc_import.dll.lib' -- RUSTC_IMPORT_LIBRARY='[^']*/Tests/RunCMake/find_library/Windows-MSVC/rustc_import.dll.lib'

View File

@@ -3,5 +3,8 @@ enable_language(C)
find_library(STATIC_LIBRARY NAMES static NO_DEFAULT_PATH PATHS ${CMAKE_CURRENT_SOURCE_DIR}/Windows-MSVC) find_library(STATIC_LIBRARY NAMES static NO_DEFAULT_PATH PATHS ${CMAKE_CURRENT_SOURCE_DIR}/Windows-MSVC)
message(STATUS "STATIC_LIBRARY='${STATIC_LIBRARY}'") message(STATUS "STATIC_LIBRARY='${STATIC_LIBRARY}'")
find_library(MESON_STATIC_LIBRARY NAMES meson_static NO_DEFAULT_PATH PATHS ${CMAKE_CURRENT_SOURCE_DIR}/Windows-MSVC)
message(STATUS "MESON_STATIC_LIBRARY='${MESON_STATIC_LIBRARY}'")
find_library(RUSTC_IMPORT_LIBRARY NAMES rustc_import NO_DEFAULT_PATH PATHS ${CMAKE_CURRENT_SOURCE_DIR}/Windows-MSVC) 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}'") message(STATUS "RUSTC_IMPORT_LIBRARY='${RUSTC_IMPORT_LIBRARY}'")