]> git.ipfire.org Git - thirdparty/zstd.git/commit
[cmake] Always create libzstd target
authorNick Terrell <terrelln@fb.com>
Thu, 14 Mar 2024 15:47:04 +0000 (08:47 -0700)
committerNick Terrell <nickrterrell@gmail.com>
Thu, 14 Mar 2024 19:04:46 +0000 (15:04 -0400)
commita0a9bc6c95436c85002ffca972ae545f862e1638
tree0bb4e65353150ab174fcaffc88bfe8257d8e0e07
parent515c07a1315789e7330fb0b08191b9b42541e682
[cmake] Always create libzstd target

If both `ZSTD_BUILD_SHARED` and `ZSTD_BUILD_STATIC` are set, then cmake exports the libraries `libzstd_shared` and `libzstd_static` only.
It does not export `libzstd`, which is only exported when exactly one of `ZSTD_BUILD_SHARED` and `ZSTD_BUILD_STATIC` is set.
This PR exports `libzstd` in that case, based on the value of the standard CMake variable [`BUILD_SHARED_LIBS`](https://cmake.org/cmake/help/latest/variable/BUILD_SHARED_LIBS.html).
This ensures that `libzstd` can always be used to refer to the exported zstd library, since the build errors if neither `ZSTD_BUILD_SHARED` nor `ZSTD_BUILD_STATIC` are set.

I tested all the possible combinations of `ZSTD_BUILD_SHARED`, `ZSTD_BUILD_STATIC`, and `BUILD_SHARED_LIBS` and they always worked as expected:
* If only exactly one of `ZSTD_BUILD_SHARED` and `ZSTD_BUILD_STATIC` is set, that is used as `libzstd`.
* Otherwise, libzstd is set based on `BUILD_SHARED_LIBS`.

Fixes #3859.
build/cmake/lib/CMakeLists.txt