Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

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

Abierto Apto para principiantes
#4,800 0 comentarios 0 reacciones 0 asignados Ver en GitHub

@Tyagiquamar ya está trabajando en esto.

Desde el 1/10/2026.

  • #4810 de @Tyagiquamar — abierto

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
78/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
c, cmake, cpp
Área
build-system

Línea de trabajo

Comienza con AddZstdCompilationFlags.cmake, centrándote en EnableCompilerFlag() y ADD_ZSTD_COMPILATION_FLAGS; después, ejecuta el comando de configuración de MinGW del issue. Se considera terminado cuando la configuración se completa correctamente con CMAKE_CXX_COMPILER establecido y las compilaciones nativas conservan sus flags del compilador y de ensamblado sin requerir pruebas.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Since #4357 the cmake build enables C++ only for the tests, but AddZstdCompilationFlags.cmake still depends on it. For MinGW targets configure fails as soon as CMAKE_CXX_COMPILER is set, which is what cross toolchain files usually do.

Tested on 01b7154f1172432f8abe9b3bb9909e14a1176b7d. Works fine on the latest release (v1.5.7).

Steps to reproduce
cmake -S build/cmake -B out \
    -DCMAKE_SYSTEM_NAME=Windows \
    -DCMAKE_C_COMPILER=x86_64-w64-mingw32-gcc \
    -DCMAKE_CXX_COMPILER=x86_64-w64-mingw32-g++
CMake Error at /usr/share/cmake-4.2/Modules/Internal/CheckFlagCommonConfig.cmake:72 (message):
  check_compiler_flag: CXX: needs to be enabled before use.

The same command works without -DCMAKE_CXX_COMPILER or with -DZSTD_BUILD_TESTS=ON. The first commit that fails is 769723aee2.

Cause

EnableCompilerFlag() checks C++ flags when CMAKE_CXX_COMPILER is set, which does not tell whether the language is enabled:

if (_CXX AND CMAKE_CXX_COMPILER)
    CHECK_CXX_COMPILER_FLAG(${_flag} CXX_FLAG_${varname})

_CXX is always true here. ADD_ZSTD_COMPILATION_FLAGS passes _C _CXX on without ${}, so the function gets the string _CXX and not the value of ZSTD_ENABLE_CXX.

Also affects native compilation

Default build silently loses all flags and the assembly. The block is guarded by CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang", which is empty without C++, and ZSTD_HAS_NOEXECSTACK needs CXX_FLAG_WA_NOEXECSTACK. On x86-64 Linux with gcc 15.2.0:

$ cmake -S build/cmake -B out
$ grep C_FLAGS out/lib/CMakeFiles/libzstd_static.dir/flags.make
C_FLAGS = -O3 -DNDEBUG -fPIC -DZSTD_DISABLE_ASM

$ cmake -S build/cmake -B out2 -DZSTD_BUILD_TESTS=ON
$ grep C_FLAGS out2/lib/CMakeFiles/libzstd_static.dir/flags.make
C_FLAGS =  -Wall -Wextra -Wundef -Wshadow -Wcast-align -Wcast-qual -Wstrict-prototypes -Wa,--noexecstack -O3 -DNDEBUG -fPIC
Possible fix

Use CMAKE_C_COMPILER_ID for the guard, check C++ flags only if CMAKE_CXX_COMPILER_LOADED is set, and do not require CXX_FLAG_WA_NOEXECSTACK when C++ is not enabled.

Lenguaje dominante
C
Estrellas
28.1k
Forks
2.7k
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de facebook/zstd

Todos los issues de facebook/zstd

Issues similares

Más issues de C

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.