madler / zlib

A massively spiffy yet delicately unobtrusive compression library.
http://zlib.net/
Other
5.55k stars 2.42k forks source link

cmake: Target "zlibstatic" INTERFACE_INCLUDE_DIRECTORIES property contains path issue #915

Closed hsdk123 closed 6 months ago

hsdk123 commented 7 months ago

Hi, I use fetchcontent to build zlib and have recently started getting cmake configuration errors like:

CMake Error in out/build/windows-release/_deps/minizip-src/third-party/zlib/CMakeLists.txt:
  Target "zlibstatic" INTERFACE_INCLUDE_DIRECTORIES property contains path:

    "C:/Users/daego/Desktop/Projects/Light.vn-core/core/out/build/windows-release/_deps/zlib-build"

  which is prefixed in the build directory.

CMake Error in out/build/windows-release/_deps/minizip-src/third-party/zlib/CMakeLists.txt:
  Target "zlibstatic" INTERFACE_INCLUDE_DIRECTORIES property contains path:

    "C:/Users/daego/Desktop/Projects/Light.vn-core/core/out/build/windows-release/_deps/zlib-build"

  which is prefixed in the build directory.Target "zlibstatic"
  INTERFACE_INCLUDE_DIRECTORIES property contains path:

    "C:/Users/daego/Desktop/Projects/Light.vn-core/core/out/build/windows-release/_deps/zlib-build"

  which is prefixed in the source directory.

CMake Error in out/build/windows-release/_deps/minizip-src/third-party/zlib/CMakeLists.txt:
  Target "zlibstatic" INTERFACE_INCLUDE_DIRECTORIES property contains path:

    "C:/Users/daego/Desktop/Projects/Light.vn-core/core/out/build/windows-release/_deps/minizip-src/third-party/zlib"

  which is prefixed in the build directory.

CMake Error in out/build/windows-release/_deps/minizip-src/third-party/zlib/CMakeLists.txt:
  Target "zlibstatic" INTERFACE_INCLUDE_DIRECTORIES property contains path:

    "C:/Users/daego/Desktop/Projects/Light.vn-core/core/out/build/windows-release/_deps/minizip-src/third-party/zlib"

  which is prefixed in the build directory.Target "zlibstatic"
  INTERFACE_INCLUDE_DIRECTORIES property contains path:

    "C:/Users/daego/Desktop/Projects/Light.vn-core/core/out/build/windows-release/_deps/minizip-src/third-party/zlib"

  which is prefixed in the source directory.

This seems to be due to https://github.com/madler/zlib/commit/2e3d86c4e12c4c23db4229eea7d0c1cd4571273e

ASpoonPlaysGames commented 7 months ago

We had the same issue in https://github.com/R2Northstar/NorthstarLauncher/ which submodules https://github.com/zlib-ng/minizip-ng which in turn uses FetchContent to get zlib.

Reverting the above commit in a fork of zlib and getting minizip to fetch that fork solved the issue.

hsdk123 commented 7 months ago

@madler could you take a look?

madler commented 7 months ago

@tr1cks

nmoinvaz commented 7 months ago

This might work with this instead?

add_library(zlib SHARED ${ZLIB_SRCS} ${ZLIB_DLL_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})
target_include_directories(zlib PUBLIC 
    $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}> 
    $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
add_library(zlibstatic STATIC ${ZLIB_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})
target_include_directories(zlibstatic PUBLIC
    $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}> 
    $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)

Perhaps somebody could test it.

ASpoonPlaysGames commented 7 months ago

Perhaps somebody could test it.

Seems to work for us, thanks!

madler commented 6 months ago

@hsdk123 Can you try @nmoinvaz 's suggestion?

hsdk123 commented 6 months ago

@hsdk123 Can you try @nmoinvaz 's suggestion?

Confirming working for us!

madler commented 6 months ago

Thanks all. https://github.com/madler/zlib/commit/f1f503da85d52e56aae11557b4d79a42bcaa2b86