[llvm] Fix Findzstd.cmake for compiler-rt with MSVC (PR #98645)

Yaxun Liu via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 12 07:59:07 PDT 2024


https://github.com/yxsamliu created https://github.com/llvm/llvm-project/pull/98645

When building compiler-rt with MSVC, CMAKE_INSTALL_LIBDIR and CMAKE_INSTALL_BINDIR.

This causes error in Findzstd.cmake like the following:

CMake Error at C:/llvm/cmake/modules/Findzstd.cmake:39 (string):
  string sub-command REGEX, mode REPLACE: regex matched an empty string.

Do not do the REGEX when CMAKE_INSTALL_LIBDIR and CMAKE_INSTALL_BINDIR are empty.

Similar issues were reported by others at

https://github.com/llvm/llvm-project/commit/e7fc7540daa9333f0be4f380fc9c619236d17f57

>From 2ca5ae6d48310db74deeaa3c9938f59f515bb085 Mon Sep 17 00:00:00 2001
From: "Yaxun (Sam) Liu" <yaxun.liu at amd.com>
Date: Fri, 12 Jul 2024 10:43:35 -0400
Subject: [PATCH] Fix Findzstd.cmake for compiler-rt with MSVC

When building compiler-rt with MSVC, CMAKE_INSTALL_LIBDIR and CMAKE_INSTALL_BINDIR.

This causes error in Findzstd.cmake like the following:

CMake Error at C:/llvm/cmake/modules/Findzstd.cmake:39 (string):
  string sub-command REGEX, mode REPLACE: regex matched an empty string.

Do not do the REGEX when CMAKE_INSTALL_LIBDIR and CMAKE_INSTALL_BINDIR are empty.

Similar issues were reported by others at

https://github.com/llvm/llvm-project/commit/e7fc7540daa9333f0be4f380fc9c619236d17f57
---
 llvm/cmake/modules/Findzstd.cmake | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/llvm/cmake/modules/Findzstd.cmake b/llvm/cmake/modules/Findzstd.cmake
index 178d99565f044..4bc0b793e51c9 100644
--- a/llvm/cmake/modules/Findzstd.cmake
+++ b/llvm/cmake/modules/Findzstd.cmake
@@ -36,7 +36,9 @@ if(zstd_FOUND)
     if(MSVC)
       # IMPORTED_LOCATION is the path to the DLL and IMPORTED_IMPLIB is the "library".
       get_filename_component(zstd_DIRNAME "${zstd_LIBRARY}" DIRECTORY)
-      string(REGEX REPLACE "${CMAKE_INSTALL_LIBDIR}$" "${CMAKE_INSTALL_BINDIR}" zstd_DIRNAME "${zstd_DIRNAME}")
+      if(NOT "${CMAKE_INSTALL_LIBDIR}" STREQUAL "" AND NOT "${CMAKE_INSTALL_BINDIR}" STREQUAL "")
+        string(REGEX REPLACE "${CMAKE_INSTALL_LIBDIR}$" "${CMAKE_INSTALL_BINDIR}" zstd_DIRNAME "${zstd_DIRNAME}")
+      endif()
       get_filename_component(zstd_BASENAME "${zstd_LIBRARY}" NAME)
       string(REGEX REPLACE "\\${CMAKE_LINK_LIBRARY_SUFFIX}$" "${CMAKE_SHARED_LIBRARY_SUFFIX}" zstd_BASENAME "${zstd_BASENAME}")
       set_target_properties(zstd::libzstd_shared PROPERTIES



More information about the llvm-commits mailing list