Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

zlib support in windows with MSVC #19402

Open Quuxplusone opened 10 years ago

Quuxplusone commented 10 years ago
Bugzilla Link PR19403
Status NEW
Importance P normal
Reported by Sumanth Gundapaneni (sgundapa@codeaurora.org)
Reported on 2014-04-11 13:54:53 -0700
Last modified on 2020-03-02 02:11:49 -0800
Version trunk
Hardware PC Windows NT
CC akhuang@google.com, dblaikie@gmail.com, ditaliano@apple.com, hans@chromium.org, llvm-bugs@lists.llvm.org, michael.holman@microsoft.com, rnk@google.com, zufuliu@163.com
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
Why is zlib support disabled for windows/MSVC in CMake?

I got the zlib headers and libraries from GetGnuWin32. I have a code in llvm
that uses zlib algorithm. With the current CMake configuration in LLVM, I
couldn't configure to link zlib.

To detect zlib.h header
-DCMAKE_C_FLAGS="/IC:/GetGnuWin32/gnuwin32/include" -
DCMAKE_CXX_FLAGS="/IC:/GetGnuWin32/gnuwin32/include"

To detect zlib.lib library (dirty hack)
-DHAVE_LIBZ=1 -DCMAKE_EXE_LINKER_FLAGS="C:/GetGnuWin32/gnuwin32/lib/zlib.lib" -
DCMAKE_SHARED_LINKER_FLAGS="C:/GetGnuWin32/gnuwin32/lib/zlib.lib"
The checks to detect zlib library and add it to the linker line are written for
non-windows/MSVC sytems.

I think, blocking the zlib support in windows is a limitation and a bug.

--Sumanth G
Quuxplusone commented 10 years ago

Try moving the 'check_library_exists(z compress2 "" HAVE_LIBZ)' call out of the NOT PURE_WINDOWS check. It might just work.

Quuxplusone commented 4 years ago
In chromium we're setting up zlib support for clang on windows here:
https://bugs.chromium.org/p/chromium/issues/detail?id=1004965
Quuxplusone commented 4 years ago
(In reply to Reid Kleckner from comment #2)
> In chromium we're setting up zlib support for clang on windows here:
> https://bugs.chromium.org/p/chromium/issues/detail?id=1004965

I see. My change was going to be to search for zlib with cmake's FindZlib
module. Then the user just has to set ZLIB_ROOT or
ZLIB_INCLUDE_DIRS/ZLIB_LIBRARIES instead of modifying compiler and linker flags
(which is what it looks like you are doing).

It seems like my change is still a simplification, but let me know if you think
it's unnecessary.
Quuxplusone commented 4 years ago

By all means, go for it. Using CMake's FindZLib will probably simplify our efforts to make it work in Chromium.

Quuxplusone commented 4 years ago
After https://reviews.llvm.org/D74176
the project no longer build with cmake 3.16.4:
CMake Error at lib/Support/CMakeLists.txt:202 (STRING):
  STRING sub-command REGEX, mode REPLACE: regex "^" matched an empty string.

line 202-203:
    STRING(REGEX REPLACE "^${CMAKE_STATIC_LIBRARY_PREFIX}" "" zlib_library ${zlib_library})
    STRING(REGEX REPLACE "${CMAKE_STATIC_LIBRARY_SUFFIX}$" "" zlib_library ${zlib_library})
Quuxplusone commented 4 years ago
(In reply to Zufu Liu from comment #5)
> After https://reviews.llvm.org/D74176
> the project no longer build with cmake 3.16.4:
> CMake Error at lib/Support/CMakeLists.txt:202 (STRING):
>   STRING sub-command REGEX, mode REPLACE: regex "^" matched an empty string.
>
> line 202-203:
>     STRING(REGEX REPLACE "^${CMAKE_STATIC_LIBRARY_PREFIX}" "" zlib_library
> ${zlib_library})
>     STRING(REGEX REPLACE "${CMAKE_STATIC_LIBRARY_SUFFIX}$" "" zlib_library
> ${zlib_library})

I believe rnk fixed this in 1079c68aa0fdb14d270a31c0df49a2afc5ed2485