1
0
mirror of https://github.com/facebook/zstd.git synced 2025-07-28 00:01:53 +03:00
Commit Graph

216 Commits

Author SHA1 Message Date
9a6fe9a428 remove global variable
overkill and leaky to transport a test result just in one place.
2025-06-09 21:55:06 +00:00
472acf5d83 fix #4405 2025-06-09 07:24:03 +00:00
7e0324e124 fixed cmake + windows + visual + clang-cl
by removing processing of resource files in this case
2025-06-09 07:09:51 +00:00
49fe2ec793 refactor: modularize CMakeLists.txt for better maintainability
- Split monolithic 235-line CMakeLists.txt into focused modules
- Main file reduced to 78 lines with clear section organization
- Created 5 specialized modules:
  * ZstdVersion.cmake - CMake policies and version management
  * ZstdOptions.cmake - Build options and platform configuration
  * ZstdDependencies.cmake - External dependency management
  * ZstdBuild.cmake - Build targets and validation
  * ZstdPackage.cmake - Package configuration generation

Benefits:
- Improved readability and maintainability
- Better separation of concerns
- Easier debugging and modification
- Preserved 100% backward compatibility
- All existing build options and targets unchanged

The refactored build system passes all tests and maintains
identical functionality while being much easier to understand
and maintain.
2025-06-09 03:47:33 +00:00
769723aee2 [cmake] only require a CXX compiler when tests are build
Signed-off-by: Thomas Devoogdt <thomas@devoogdt.com>
2025-05-06 12:20:26 -07:00
0c3345d6ec [cmake] use target_compile_definitions
which is considered best practice.
2025-02-20 16:00:54 -08:00
de7c8b9842 cmake: Remove duplicated line 2025-01-28 00:22:35 +01:00
be1bf2469e fix: quote include directory for resource compiler 2025-01-27 15:18:55 -03:00
45c0e72c0a Instructions for Apple Framework builds 2025-01-22 22:54:03 +03:30
becef672bb Build: Revert min version to 3.10 2025-01-22 22:53:41 +03:30
897cec3876 Build: Add support for Apple frameworks
Signed-off-by: Treata11 <treata11@yahoo.com>
2025-01-21 20:58:27 +03:30
757e29e170 Oops 2025-01-02 14:17:24 -08:00
54c3d998a0 Support for libc variants without fseeko/ftello
Some older Android libc implementations don't support `fseeko` or `ftello`.
This commit adds a new compile-time macro `LIBC_NO_FSEEKO` as well as a usage in CMake for old Android APIs.
2025-01-02 14:02:10 -08:00
f0937b83d9 [cmake] Fix -z noexecstack portability
Summary:
Issue reported by @ryandesign and @MarcusCalhoun-Lopez.

CMake doesn't support spaces in flags. This caused older versions of gcc to
ignore the unknown flag "-z noexecstack" on MacOS since it was interpreted as a
single flag, not two separate flags. Then, during compilation it was treated as
"-z" "noexecstack", which was correctly forwarded to the linker. But the MacOS
linker does not support `-z noexecstack` so compilation failed.

The fix is to use `-Wl,-z,noexecstack`. This is never misinterpreted by a
compiler. However, not all compilers support this syntax to forward flags to the
linker. To fix this issue, we check if all the relevant `noexecstack` flags have
been successfully set, and if they haven't we disable assembly.

See also PR#4056 and PR#4061. I decided to go a different route because this is
simpler. It might not successfully set these flags on some compilers, but in that
case it also disables assembly, so they aren't required.

Test Plan:
```
mkdir build-cmake
cmake ../build/cmake/CMakeLists.txt
make -j
```

See that the linker flag is successfully detected & that assembly is enabled.

Run the same commands on MacOS which doesn't support `-Wl,-z,noexecstack` and see
that everything compiles and that `LD_FLAG_WL_Z_NOEXECSTACK` and
`ZSTD_HAS_NOEXECSTACK` are both false.
2024-12-20 15:06:23 -08:00
1198a582d3 Update VERSION_LESS usage to VERSION_GREATER_THAN 2024-12-12 11:39:40 -08:00
e190e7944e Update cmake minimum requirement to 3.10
CMake warns on the current minimum requirement (3.5). Update to 3.10.
This means support is still available for the default on Ubuntu 18.04, which
exited LTS standard in April of 2023.
[draft]
2024-12-09 10:53:38 -08:00
44e83e9180 Fix typos not found by codespell 2024-06-20 20:16:25 +02:00
fd5f8106a5 fix missing include folder for resource compiler 2024-04-06 00:05:58 +02:00
42b02f5185 [cmake] Emit warnings for contradictory build settings
Document that the `ZSTD_BUILD_{SHARED,STATIC}` take precedence over `BUILD_SHARED_LIBS` when exactly one is ON.

Thanks to @teo-tsirpanis for pointing out the potentially confusing behavior.
2024-03-18 09:31:22 -07:00
a595e5812a [cmake] Fix up PR #3716
* Make a variable `PublicHeaders` for Zstd's public headers
* Add `PublicHeaders` to `Headers`, which was missing
* Only export `${LIBRARY_DIR}` publicly, not `common/`
* Switch the `target_include_directories()` to `INTERFACE` because zstd uses relative includes internally, so doesn't need any include directories to build
* Switch installation to use the `PublicHeaders` variable, and test that the right headers are installed
2024-03-18 09:18:51 -04:00
79cd0ff712 Makes it possible to use the lib through FetchContent or ExternalProject_Add 2024-03-18 09:18:51 -04:00
a0a9bc6c95 [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.
2024-03-14 15:04:46 -04:00
c1e995321e [CI] Run tests with CMake on Windows
Build and run tests on Windows with CMake
2024-03-13 09:45:40 -04:00
f6039f3d5f cmake refactor: move HP-UX specific logic into its own function
reduce visual clutter of corner case configuration.
2024-03-11 16:22:13 -07:00
a4db145900 Merge pull request #3862 from likema/fix-hpux-parisc
Fix building on HP-UX 11.11 PA-RISC
2024-03-11 15:55:58 -07:00
b27d1634a5 Merge branch 'dev' into unified-target 2024-02-28 01:25:15 +02:00
dcd713ce06 Define the unified target inside the CMake project, and export it.
This is less error-prone.
2024-02-27 23:39:59 +02:00
b34517a440 fix cmake build 2024-02-20 20:20:40 -08:00
befcec1788 fix cmake recipe 2024-01-29 15:45:16 -08:00
2fc7248412 fix cmakebuild test
write it in a way which is more compatible with older versions of cmake (<3.13)

Also:
fix pzstd compilation (notably on macos)
2024-01-27 17:30:06 -08:00
dcf784a04b Merge pull request #3760 from jcelerier/patch-1
[x-compile] Fix cross-compiling for AArch64 with lld
2024-01-13 11:41:30 -08:00
e49d1ab6aa Fix building on HP-UX 11.11 PA-RISC
By CMake 3.8.2 and GCC 4.7.1
2024-01-14 00:32:19 +08:00
475da4fb2e Make zstd::libzstd an imported interface target.
It cannot be an alias, because it would lock the package to use either static or shared libraries at its build time. We want to decide this at the time `find_package` is called.
2023-12-19 17:04:09 +02:00
c53d650d9a Export a zstd::libzstd target if only static or dynamic linkage is specified. 2023-11-07 15:54:19 +02:00
f013b1b504 [cmake] Remove code for compatibility with CMake < 3.0
The required version of CMake is now 3.5.
2023-11-01 20:46:47 +01:00
4502ca5f42 [cmake] Require CMake version 3.5 or newer
More recent versions of CMake emit the following warning:
CMake Deprecation Warning at cmake/CMakeLists.txt:10 (cmake_minimum_required):
  Compatibility with CMake < 3.5 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.
2023-10-31 23:30:43 +01:00
3c3845b9d8 Add target_include_directories because windows and macos need it for me 2023-10-23 17:38:09 +02:00
e590c8a0e3 Add doc on how to use it with cmake FetchContent 2023-10-18 13:22:15 +02:00
4f77b81c8a Merge pull request #3777 from facebook/fix_x32
fix x32 tests on Github CI
2023-10-06 08:05:29 -04:00
fe34776c20 Fix new typos found by codespell 2023-09-23 18:56:01 +02:00
253873220f Fixed zstd cmake shared build on windows 2023-08-27 16:51:24 +02:00
a02d81f944 fix: ZSTD_BUILD_DECOMPRESSION message 2023-08-19 15:44:53 +03:00
7e09f07b32 Fix Intel Xcode builds with assembly
When forcing the source file language to `C`, Xcode enforces
the file to be compiled as `C` by appending `-x c` to the
compiler command line.

For now try to limit the damage and only enforce the language
if the ASM and C compilers differ.

Reproducer (CMake `3.26.4`, Xcode `14.3`):
```
cmake -S build/cmake -B _b -GXcode -DCMAKE_OSX_ARCHITECTURES=x86_64
cmake --build _b
```

Fix: #3622
2023-06-02 12:43:59 +02:00
5059618295 Add options in Makefile to cmake
Signed-off-by: Tao He <sighingnow@gmail.com>
2023-05-26 13:45:21 -07:00
979b047114 Disable linker flag detection on MSVC/ClangCL.
This fixes compilation with clang-cl on Windows. There
is a bug in cmake so that check_linker_flag() doesn't give
the correct result when using link.exe/lld-link.exe.

Details in CMake's gitlab: https://gitlab.kitware.com/cmake/cmake/-/issues/22023

Fixes #3522
2023-03-22 22:13:57 +01:00
8420502ef9 Don't require CMake 3.18 or later
fix #3500

CMake 3.18 or later was required by #3392. Because it uses
`CheckLinkerFlag`. But requiring CMake 3.18 or later is a bit
aggressive. Because Ubuntu 20.04 LTS still uses CMake 3.16.3:
https://packages.ubuntu.com/search?keywords=cmake

This change disables `-z noexecstack` check with old CMake. This will
not break any existing users. Because users who need `-z noexecstack`
must already use CMake 3.18 or later.
2023-02-16 10:08:45 -08:00
2a402626dd External matchfinder API (#3333)
* First building commit with sample matchfinder

* Set up ZSTD_externalMatchCtx struct

* move seqBuffer to ZSTD_Sequence*

* support non-contiguous dictionary

* clean up parens

* add clearExternalMatchfinder, handle allocation errors

* Add useExternalMatchfinder cParam

* validate useExternalMatchfinder cParam

* Disable LDM + external matchfinder

* Check for static CCtx

* Validate mState and mStateDestructor

* Improve LDM check to cover both branches

* Error API with optional fallback

* handle RLE properly for external matchfinder

* nit

* Move to a CDict-like model for resource ownership

* Add hidden useExternalMatchfinder bool to CCtx_params_s

* Eliminate malloc, move to cwksp allocation

* Handle CCtx reset properly

* Ensure seqStore has enough space for external sequences

* fix capitalization

* Add DEBUGLOG statements

* Add compressionLevel param to matchfinder API

* fix c99 issues and add a param combination error code

* nits

* Test external matchfinder API

* C90 compat for simpleExternalMatchFinder

* Fix some @nocommits and an ASAN bug

* nit

* nit

* nits

* forward declare copySequencesToSeqStore functions in zstd_compress_internal.h

* nit

* nit

* nits

* Update copyright headers

* Fix CMake zstreamtest build

* Fix copyright headers (again)

* typo

* Add externalMatchfinder demo program to make contrib

* Reduce memory consumption for small blockSize

* ZSTD_postProcessExternalMatchFinderResult nits

* test sum(matchlen) + sum(litlen) == srcSize in debug builds

* refExternalMatchFinder -> registerExternalMatchFinder

* C90 nit

* zstreamtest nits

* contrib nits

* contrib nits

* allow block splitter + external matchfinder, refactor

* add windowSize param

* add contrib/externalMatchfinder/README.md

* docs

* go back to old RLE heuristic because of the first block issue

* fix initializer element is not a constant expression

* ref contrib from zstd.h

* extremely pedantic compiler warning fix, meson fix, typo fix

* Additional docs on API limitations

* minor nits

* Refactor maxNbSeq calculation into a helper function

* Fix copyright
2022-12-28 16:45:14 -05:00
6640377783 cmake build: fix nit
reported by @jaimeMF in https://github.com/facebook/zstd/pull/3392#discussion_r1056643794
2022-12-23 14:18:11 -08:00
31a703ec13 [cmake] Add noexecstack to compiler/linker flags 2022-12-21 17:30:14 -08:00
651a381060 [build][cmake] Fix cmake with custom assembler
Tell CMake to explicitly compile our assembly as C code, because we
require it is compiled by a C compiler, and it is only enabled for
clang/gcc.

Fixes #3193.
2022-12-20 13:02:21 -08:00