Skip to content

cmake: fix CXX flag dependency in AddZstdCompilationFlags when C++ is not enabled - #4810

Open
Tyagiquamar wants to merge 1 commit into
facebook:devfrom
Tyagiquamar:fix-cmake-cxx-flag-dep-4800
Open

Tyagiquamar wants to merge 1 commit into
facebook:devfrom
Tyagiquamar:fix-cmake-cxx-flag-dep-4800

Conversation

@Tyagiquamar

Copy link
Copy Markdown

Summary of changes

Fixes #4800.

Since #4357, the CMake build enables C++ only when tests are enabled (ZSTD_BUILD_TESTS=ON), but AddZstdCompilationFlags.cmake still invoked CHECK_CXX_COMPILER_FLAG whenever CMAKE_CXX_COMPILER was defined in the environment or toolchain (such as standard MinGW/cross-compilation toolchains).

When C++ is not enabled as a CMake project language:

  1. CHECK_CXX_COMPILER_FLAG fails with check_compiler_flag: CXX: needs to be enabled before use.
  2. The compiler flags guard checked CMAKE_CXX_COMPILER_ID (which is empty when C++ is not loaded), causing default C-only builds to lose standard warnings (-Wall, -Wextra, etc.) and assembly support.
  3. ZSTD_HAS_NOEXECSTACK unconditionally required CXX_FLAG_WA_NOEXECSTACK to be set.

This change:

  • Updates EnableCompilerFlag to check C++ compiler flags only when CMAKE_CXX_COMPILER_LOADED is true.
  • Updates the GNU/Clang compiler ID check in ADD_ZSTD_COMPILATION_FLAGS to evaluate CMAKE_C_COMPILER_ID and CMAKE_CXX_COMPILER_ID.
  • Passes the actual variables ${_C}, ${_CXX}, ${_LD} to EnableCompilerFlag.
  • Allows ZSTD_HAS_NOEXECSTACK to succeed in C-only mode without requiring C++ CXX_FLAG_WA_NOEXECSTACK.

Validation

  • Clean build in Docker container (cmake -S build/cmake -B /tmp/zstd-build -G Ninja -DCMAKE_BUILD_TYPE=Release && cmake --build /tmp/zstd-build).
  • Verified all C warning flags (-Wall, -Wextra, -Wshadow, etc.), libzstd.a, libzstd.so, and executable binaries build and link with exit code 0.

… not enabled

Signed-off-by: Tyagiquamar <mohdquamartyagi@gmail.com>
@meta-cla meta-cla Bot added the CLA Signed label Oct 1, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cmake: AddZstdCompilationFlags still depends on C++ after #4357

1 participant