Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Findzstd.cmake: string sub-command REGEX, mode REPLACE: regex "$" matched an empty string. #83802

Closed
vgvassilev opened this issue Mar 4, 2024 · 0 comments · Fixed by #83807
Closed
Labels
cmake Build system in general and CMake in particular

Comments

@vgvassilev
Copy link
Contributor

When using find_package(llvm) on windows we get:

CMake Error at D:/bld/cppinterop_1709495262007/_h_env/Library/lib/cmake/llvm/Findzstd.cmake:39 (string):
2024-03-03T19:54:48.3232894Z   string sub-command REGEX, mode REPLACE: regex "$" matched an empty string.
2024-03-03T19:54:48.3233394Z Call Stack (most recent call first):
2024-03-03T19:54:48.3233750Z   D:/bld/cppinterop_1709495262007/_h_env/Library/lib/cmake/llvm/LLVMConfig.cmake:278 (find_package)
2024-03-03T19:54:48.3234068Z   CMakeLists.txt:121 (find_package)

Our diagnosis is that find_package(LLVM REQUIRED CONFIG) triggers LLVMConfig.cmake to call find_package(zstd). In the MSVC branch we use string(REGEX REPLACE "${CMAKE_INSTALL_LIBDIR}$" "${CMAKE_INSTALL_BINDIR}" zstd_DIRNAME "${zstd_DIRNAME}"), however, CMAKE_INSTALL_LIBDIR is not defined yet and we error out:

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}")
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
INTERFACE_INCLUDE_DIRECTORIES "${zstd_INCLUDE_DIR}"
IMPORTED_LOCATION "${zstd_DIRNAME}/${zstd_BASENAME}"
IMPORTED_IMPLIB "${zstd_LIBRARY}")
unset(zstd_DIRNAME)
unset(zstd_BASENAME)

Adding include(GNUInstallDirs) which defines CMAKE_INSTALL_LIBDIR in the calling cmake fixes the problem but it's difficult to debug and and far from optimal.

Full log is here: https://dev.azure.com/conda-forge/84710dde-1620-425b-80d0-4cf5baca359d/_apis/build/builds/888296/logs/24

vgvassilev added a commit to vgvassilev/llvm-project that referenced this issue Mar 4, 2024
This fixes an odd problem with the regex when `CMAKE_INSTALL_LIBDIR` is not
defined:

`string sub-command REGEX, mode REPLACE: regex "$" matched an empty string.`

Fixes llvm#83802
vgvassilev added a commit to vgvassilev/CppInterOp that referenced this issue Mar 4, 2024
In short we use variables which require including `GNUInstallDirs` but we are
expecting somebody else to include it for us.

See llvm/llvm-project#83802
vgvassilev added a commit to vgvassilev/clad that referenced this issue Mar 4, 2024
In short we use variables which require including `GNUInstallDirs` but we are
expecting somebody else to include it for us.

See llvm/llvm-project#83802
@EugeneZelenko EugeneZelenko added cmake Build system in general and CMake in particular and removed new issue labels Mar 4, 2024
vgvassilev added a commit to compiler-research/CppInterOp that referenced this issue Mar 4, 2024
In short we use variables which require including `GNUInstallDirs` but we are
expecting somebody else to include it for us.

See llvm/llvm-project#83802
vgvassilev added a commit to vgvassilev/clad that referenced this issue Mar 4, 2024
In short we use variables which require including `GNUInstallDirs` but we are
expecting somebody else to include it for us.

See llvm/llvm-project#83802
vgvassilev added a commit to vgvassilev/llvm-project that referenced this issue Mar 5, 2024
weliveindetail pushed a commit to weliveindetail/llvm-project that referenced this issue Mar 5, 2024
weliveindetail added a commit to weliveindetail/llvm-project that referenced this issue Mar 5, 2024
gmarkall added a commit to yashssh/llvmlite that referenced this issue Mar 14, 2024
gmarkall added a commit to yashssh/llvmlite that referenced this issue Mar 14, 2024
galexite added a commit to galexite/include-what-you-use-feedstock that referenced this issue Mar 16, 2024
vgvassilev added a commit to vgvassilev/llvm-project that referenced this issue Jun 6, 2024
This fixes an odd problem with the regex when `CMAKE_INSTALL_LIBDIR` is not
defined:

`string sub-command REGEX, mode REPLACE: regex "$" matched an empty string.`

Fixes llvm#83802
Lunderberg added a commit to Lunderberg/tvm that referenced this issue Aug 19, 2024
This is a workaround for an upstream LLVM issue [0], which looks to be
caused by the `CMAKE_INSTALL_LIBDIR` variable is used before
definition.  While there is an LLVM PR to resolve this fix [1], as of
2024-08-19 it has not yet been merged to LLVM.

This change is intended to resolve the following error, which occurs
during the CI build of TVM on Windows.

```
The system cannot find the file specified.
CMake Error at C:/Miniconda/envs/tvm-build/conda-bld/tvm-package_1723747883202/_h_env/Library/lib/cmake/llvm/Findzstd.cmake:39 (string):
  string sub-command REGEX, mode REPLACE: regex "$" matched an empty string.
Call Stack (most recent call first):
  C:/Miniconda/envs/tvm-build/conda-bld/tvm-package_1723747883202/_h_env/Library/lib/cmake/llvm/LLVMConfig.cmake:277 (find_package)
  cmake/utils/FindLLVM.cmake:47 (find_package)
  cmake/modules/LLVM.cmake:31 (find_llvm)
  CMakeLists.txt:565 (include)
```

[0] llvm/llvm-project#83802
[1] llvm/llvm-project#83807
cjdb pushed a commit to cjdb/llvm-project that referenced this issue Aug 23, 2024
…lvm#83807)

This fixes an odd problem with the regex when `CMAKE_INSTALL_LIBDIR` is
not defined:

`string sub-command REGEX, mode REPLACE: regex "$" matched an empty
string.`

Fixes llvm#83802
dmpolukhin pushed a commit to dmpolukhin/llvm-project that referenced this issue Sep 2, 2024
…lvm#83807)

This fixes an odd problem with the regex when `CMAKE_INSTALL_LIBDIR` is
not defined:

`string sub-command REGEX, mode REPLACE: regex "$" matched an empty
string.`

Fixes llvm#83802
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cmake Build system in general and CMake in particular
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants